sync with 1.8 changes

Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
Andy Miller
2025-10-20 13:23:50 -06:00
parent 71eb774a39
commit 06471eb8cf
3 changed files with 95 additions and 1 deletions

View File

@@ -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>
*/

View File

@@ -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;
@@ -253,6 +254,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();
}

View File

@@ -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(
@@ -354,6 +360,8 @@ ERR;
$this->updater->postflight();
$this->ensureExecutablePermissions();
Cache::clearCache('all');
clearstatcache();
@@ -456,4 +464,38 @@ ERR;
// Support install for Grav 1.6.0 - 1.6.20 by loading the original class from the older version of Grav.
class_exists(\Grav\Console\Cli\CacheCommand::class, true);
}
private function ensureExecutablePermissions(): void
{
$executables = [
'bin/grav',
'bin/plugin',
'bin/gpm',
'bin/restore',
'bin/composer.phar'
];
foreach ($executables as $relative) {
$path = GRAV_ROOT . '/' . $relative;
if (!is_file($path) || is_link($path)) {
continue;
}
$mode = @fileperms($path);
$current = $mode !== false ? ($mode & 0777) : 0644;
if (($current & 0111) === 0111) {
continue;
}
@chmod($path, $current | 0111);
}
}
/**
* @return array|null
*/
public function getLastManifest(): ?array
{
return $this->lastManifest;
}
}