mirror of
https://github.com/getgrav/grav.git
synced 2025-10-26 07:56:07 +01:00
fix for recovery window/manifest via bin/gpm
Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
@@ -64,6 +64,8 @@ class SafeUpgradeService
|
||||
private $manifestStore;
|
||||
/** @var \Grav\Common\Config\ConfigInterface|null */
|
||||
private $config;
|
||||
/** @var array|null */
|
||||
private $lastManifest = null;
|
||||
|
||||
/** @var array */
|
||||
private $ignoredDirs = [
|
||||
@@ -207,6 +209,7 @@ class SafeUpgradeService
|
||||
|
||||
$this->reportProgress('finalizing', 'Finalizing upgrade...', null);
|
||||
$this->persistManifest($manifest);
|
||||
$this->lastManifest = $manifest;
|
||||
$this->pruneOldSnapshots();
|
||||
Folder::delete($stagePath);
|
||||
|
||||
@@ -246,6 +249,7 @@ class SafeUpgradeService
|
||||
$manifest['mode'] = 'manual';
|
||||
|
||||
$this->persistManifest($manifest);
|
||||
$this->lastManifest = $manifest;
|
||||
$this->pruneOldSnapshots();
|
||||
|
||||
$this->reportProgress('complete', sprintf('Snapshot %s created.', $stageId), 100, [
|
||||
@@ -409,6 +413,7 @@ class SafeUpgradeService
|
||||
$this->reportProgress('rollback', 'Restoring snapshot...', null);
|
||||
$this->copyEntries($entries, $backupPath, $this->rootPath, 'rollback', 'Restoring');
|
||||
$this->markRollback($manifest['id']);
|
||||
$this->lastManifest = $manifest;
|
||||
|
||||
return $manifest;
|
||||
}
|
||||
@@ -424,6 +429,14 @@ class SafeUpgradeService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getLastManifest(): ?array
|
||||
{
|
||||
return $this->lastManifest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array>
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ZipArchive;
|
||||
use function date;
|
||||
use function count;
|
||||
use function is_callable;
|
||||
use function strlen;
|
||||
@@ -251,6 +252,44 @@ class SelfupgradeCommand extends GpmCommand
|
||||
$error = 1;
|
||||
} else {
|
||||
$io->writeln(" '- <green>Success!</green> ");
|
||||
|
||||
$manifest = Install::instance()->getLastManifest();
|
||||
if (is_array($manifest) && ($manifest['id'] ?? null)) {
|
||||
$snapshotId = (string) $manifest['id'];
|
||||
$snapshotTimestamp = isset($manifest['created_at']) ? (int) $manifest['created_at'] : null;
|
||||
$manifestPath = null;
|
||||
if (isset($manifest['id'])) {
|
||||
$manifestPath = 'user/data/upgrades/' . $manifest['id'] . '.json';
|
||||
}
|
||||
$metadata = [
|
||||
'scope' => 'core',
|
||||
'target_version' => $remote,
|
||||
'snapshot' => $snapshotId,
|
||||
];
|
||||
if (null !== $snapshotTimestamp) {
|
||||
$metadata['snapshot_created_at'] = $snapshotTimestamp;
|
||||
}
|
||||
if ($manifestPath) {
|
||||
$metadata['snapshot_manifest'] = $manifestPath;
|
||||
}
|
||||
|
||||
$recovery->markUpgradeWindow('core-upgrade', $metadata);
|
||||
|
||||
$io->writeln(sprintf(" |- Recovery snapshot: <cyan>%s</cyan>", $snapshotId));
|
||||
if (null !== $snapshotTimestamp) {
|
||||
$io->writeln(sprintf(" |- Snapshot captured: <white>%s</white>", date('c', $snapshotTimestamp)));
|
||||
}
|
||||
if ($manifestPath) {
|
||||
$io->writeln(sprintf(" |- Manifest stored at: <white>%s</white>", $manifestPath));
|
||||
}
|
||||
} else {
|
||||
// Ensure recovery window remains active even if manifest could not be resolved.
|
||||
$recovery->markUpgradeWindow('core-upgrade', [
|
||||
'scope' => 'core',
|
||||
'target_version' => $remote,
|
||||
]);
|
||||
}
|
||||
|
||||
$io->newLine();
|
||||
$safeUpgrade->clearRecoveryFlag();
|
||||
}
|
||||
|
||||
@@ -120,6 +120,9 @@ final class Install
|
||||
/** @var VersionUpdater|null */
|
||||
private $updater;
|
||||
|
||||
/** @var array|null */
|
||||
private $lastManifest = null;
|
||||
|
||||
/** @var static */
|
||||
private static $instance;
|
||||
/** @var callable|null */
|
||||
@@ -268,6 +271,8 @@ ERR;
|
||||
throw new RuntimeException('Oops, installer was run without prepare()!', 500);
|
||||
}
|
||||
|
||||
$this->lastManifest = null;
|
||||
|
||||
try {
|
||||
if (null === $this->updater) {
|
||||
$versions = Versions::instance(USER_DIR . 'config/versions.yaml');
|
||||
@@ -294,7 +299,8 @@ ERR;
|
||||
$this->relayProgress($stage, $message, $percent);
|
||||
});
|
||||
}
|
||||
$service->promote($this->location, $this->getVersion(), $this->ignores);
|
||||
$manifest = $service->promote($this->location, $this->getVersion(), $this->ignores);
|
||||
$this->lastManifest = $service->getLastManifest() ?? $manifest;
|
||||
Installer::setError(Installer::OK);
|
||||
} else {
|
||||
Installer::install(
|
||||
@@ -484,4 +490,12 @@ ERR;
|
||||
@chmod($path, $current | 0111);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
*/
|
||||
public function getLastManifest(): ?array
|
||||
{
|
||||
return $this->lastManifest;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user