diff --git a/system/recovery.php b/system/recovery.php index 9c62903dd..6427a8091 100644 --- a/system/recovery.php +++ b/system/recovery.php @@ -63,21 +63,37 @@ if (is_file($quarantineFile)) { } $manifestDir = GRAV_ROOT . '/user/data/upgrades'; -$manifests = []; +$snapshots = []; if (is_dir($manifestDir)) { $files = glob($manifestDir . '/*.json'); if ($files) { - rsort($files); foreach ($files as $file) { $decoded = json_decode(file_get_contents($file), true); - if (is_array($decoded)) { - $decoded['file'] = basename($file); - $manifests[] = $decoded; + if (!is_array($decoded)) { + continue; } + + $id = $decoded['id'] ?? pathinfo($file, PATHINFO_FILENAME); + if (!is_string($id) || $id === '' || strncmp($id, 'snapshot-', 9) !== 0) { + continue; + } + + $decoded['id'] = $id; + $decoded['file'] = basename($file); + $decoded['created_at'] = (int)($decoded['created_at'] ?? filemtime($file) ?: 0); + $snapshots[] = $decoded; + } + + if ($snapshots) { + usort($snapshots, static function (array $a, array $b): int { + return ($b['created_at'] ?? 0) <=> ($a['created_at'] ?? 0); + }); } } } +$latestSnapshot = $snapshots[0] ?? null; + header('Content-Type: text/html; charset=utf-8'); ?> @@ -89,7 +105,8 @@ header('Content-Type: text/html; charset=utf-8');