$size)); return; } $globResult = ABJ_404_Solution_FileSystemService::captureFilesystemWarnings( static function () use ($directory) { return glob($directory . self::FILE_PREFIX . '*'); } ); self::reportFilesystemWarning('self-test glob', $globResult['warning']); $globMatches = $globResult['result']; $globCount = is_array($globMatches) ? count($globMatches) : 0; if ($globCount < 1) { self::recordStep($requestId, false, 'glob', array('glob_count' => $globCount)); return; } $readResult = ABJ_404_Solution_FileSystemService::captureFilesystemWarnings( static function () use ($path) { return file_get_contents($path); } ); self::reportFilesystemWarning('self-test read', $readResult['warning']); $readBack = $readResult['result']; if ($readBack !== $payload) { self::recordStep($requestId, false, 'read'); return; } $delete = ABJ_404_Solution_FileSystemService::captureFilesystemWarnings( static function () use ($path) { return unlink($path); } ); self::reportFilesystemWarning('self-test delete', $delete['warning']); if (!$delete['result']) { self::recordStep($requestId, false, 'delete'); return; } self::recordStep($requestId, true, 'complete', array('glob_count' => $globCount)); } catch (Throwable $e) { // Reported to the debug log as well as journaled: an exception here // is a host condition the plugin cannot act on, and the journal is // read only when an admin sends a support request. abj404_logPhpFallback('ajax-checkpoint', 'AJAX checkpoint self-test failed: ' . $e->getMessage()); self::recordStep($requestId, false, 'exception', array('message' => substr($e->getMessage(), 0, 200))); } } /** * One step outcome, under the event name the evidence catalogue and both * acceptance gates already know this probe by. * * @param array $extra */ private static function recordStep(string $requestId, bool $ok, string $step, array $extra = array()): void { if (!$ok && in_array($step, array('resolve_directory', 'create', 'append_flush', 'exception'), true) && class_exists('ABJ_404_Solution_RequestFailureFrame', false)) { ABJ_404_Solution_RequestFailureFrame::storageFailed(); } ABJ_404_Solution_AjaxCheckpointLogger::record($requestId, 'selftest', array_merge(array('ok' => $ok, 'step' => $step), $extra)); } private static function reportFilesystemWarning(string $operation, ?string $warning): void { if ($warning !== null && $warning !== '' && function_exists('abj404_logPhpFallback')) { abj404_logPhpFallback('logger-internal', $operation . ': ' . $warning); } } }