0, 'step' => 'idle', 'text' => '', 'ts' => 0]; } $data = json_decode((string)@file_get_contents($file), true); if (!is_array($data)) { return ['pct' => 0, 'step' => 'idle', 'text' => '', 'ts' => 0]; } return [ 'pct' => (int)($data['pct'] ?? 0), 'step' => (string)($data['step'] ?? 'idle'), 'text' => (string)($data['text'] ?? ''), 'ts' => (int)($data['ts'] ?? 0), ]; } public static function set(int $pct, string $step, string $text): void { $dir = Version::storageDir(); if (!is_dir($dir)) { @mkdir($dir, 0775, true); } @file_put_contents(self::file(), json_encode([ 'pct' => $pct, 'step' => $step, 'text' => $text, 'ts' => time(), ], JSON_UNESCAPED_UNICODE)); } /** * Fehlerzustand. pct = -1 statt 0, damit sich "fehlgeschlagen" nicht als * "0 % erledigt" liest - die Oberflaeche kann beides sonst nicht trennen. */ public static function error(string $text): void { self::set(-1, 'error', $text); } /** * Laeuft gerade ein Update? Ein abgestuerzter Lauf wuerde den naechsten * sonst dauerhaft blockieren, deshalb zaehlt nur ein frisches * Lebenszeichen. */ public static function isRunning(): bool { $state = self::get(); if (in_array($state['step'], ['idle', 'done', 'error'], true)) { return false; } return (time() - $state['ts']) < self::STALE_AFTER; } public static function clear(): void { $file = self::file(); if (is_file($file)) { @unlink($file); } } }