better label handling for snapshots

Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
Andy Miller
2025-10-18 19:06:27 -06:00
parent 6a4ab16529
commit da0fbf9dd6

View File

@@ -124,7 +124,7 @@ function createUpgradeService(array $options): SafeUpgradeService
} }
/** /**
* @return list<array{id:string,source_version:?string,target_version:?string,created_at:int}> * @return list<array{id:string,label:?string,source_version:?string,target_version:?string,created_at:int}>
*/ */
function loadSnapshots(): array function loadSnapshots(): array
{ {
@@ -145,6 +145,7 @@ function loadSnapshots(): array
$snapshots[] = [ $snapshots[] = [
'id' => $decoded['id'], 'id' => $decoded['id'],
'label' => $decoded['label'] ?? null,
'source_version' => $decoded['source_version'] ?? null, 'source_version' => $decoded['source_version'] ?? null,
'target_version' => $decoded['target_version'] ?? null, 'target_version' => $decoded['target_version'] ?? null,
'created_at' => (int)($decoded['created_at'] ?? 0), 'created_at' => (int)($decoded['created_at'] ?? 0),
@@ -155,15 +156,17 @@ function loadSnapshots(): array
} }
/** /**
* @param list<array{id:string,source_version:?string,target_version:?string,created_at:int}> $snapshots * @param list<array{id:string,label:?string,source_version:?string,target_version:?string,created_at:int}> $snapshots
* @return string * @return string
*/ */
function formatSnapshotListLine(array $snapshot): string function formatSnapshotListLine(array $snapshot): string
{ {
$restoreVersion = $snapshot['source_version'] ?? $snapshot['target_version'] ?? 'unknown'; $restoreVersion = $snapshot['source_version'] ?? $snapshot['target_version'] ?? 'unknown';
$timeLabel = formatSnapshotTimestamp($snapshot['created_at']); $timeLabel = formatSnapshotTimestamp($snapshot['created_at']);
$label = $snapshot['label'] ?? null;
$display = $label ? sprintf('%s [%s]', $label, $snapshot['id']) : $snapshot['id'];
return sprintf('%s (restore to Grav %s, %s)', $snapshot['id'], $restoreVersion, $timeLabel); return sprintf('%s (restore to Grav %s, %s)', $display, $restoreVersion, $timeLabel);
} }
function formatSnapshotTimestamp(int $timestamp): string function formatSnapshotTimestamp(int $timestamp): string