From 70e0ecfef530d42e5893584bd847cb4c4dae6e20 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 23 Nov 2020 20:46:41 +0200 Subject: [PATCH] Add version information when upgrading Grav --- system/src/Grav/Installer/Install.php | 28 +++++++++++++++++++- system/src/Grav/Installer/VersionUpdater.php | 18 ++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Installer/Install.php b/system/src/Grav/Installer/Install.php index ba8b22434..e764224ca 100644 --- a/system/src/Grav/Installer/Install.php +++ b/system/src/Grav/Installer/Install.php @@ -15,6 +15,7 @@ use Grav\Common\GPM\Installer; use Grav\Common\Grav; use Grav\Common\Plugins; use function dirname; +use function is_string; /** * Grav installer. @@ -224,7 +225,7 @@ ERR; $this->location = dirname($location, 4); $versions = Versions::instance(GRAV_ROOT . '/user/config/versions.yaml'); - $this->updater = new VersionUpdater('core/grav', __DIR__ . '/updates', $versions); + $this->updater = new VersionUpdater('core/grav', __DIR__ . '/updates', $this->getVersion(), $versions); $this->updater->preflight(); } @@ -257,6 +258,8 @@ ERR; if (!$success) { throw new \RuntimeException(Installer::lastErrorMsg()); } + + $this->updater->install(); } /** @@ -274,6 +277,13 @@ ERR; } } + /** + * @param array $results + * @param string $type + * @param string $name + * @param array $check + * @param string|null $version + */ protected function checkVersion(array &$results, $type, $name, array $check, $version): void { if (null === $version && !empty($check['optional'])) { @@ -314,6 +324,10 @@ ERR; ]; } + /** + * @param array $results + * @param array $plugins + */ protected function checkPlugins(array &$results, array $plugins): void { if (!\class_exists('Plugins')) { @@ -334,6 +348,18 @@ ERR; } } + /** + * @return string + */ + protected function getVersion(): string + { + $definesFile = "{$this->location}/system/defines.php"; + $content = file_get_contents($definesFile); + preg_match("/define\('GRAV_VERSION', '([^']+)'\);/mu", $content, $matches); + + return $matches[1] ?? ''; + } + protected function legacySupport(): void { // Support install for Grav 1.6.0 - 1.6.20 by loading the original class from the older version of Grav. diff --git a/system/src/Grav/Installer/VersionUpdater.php b/system/src/Grav/Installer/VersionUpdater.php index e90ba4f42..6b71f5eb7 100644 --- a/system/src/Grav/Installer/VersionUpdater.php +++ b/system/src/Grav/Installer/VersionUpdater.php @@ -23,19 +23,21 @@ final class VersionUpdater * VersionUpdater constructor. * @param string $name * @param string $path + * @param string $version * @param Versions $versions */ - public function __construct(string $name, string $path, Versions $versions) + public function __construct(string $name, string $path, string $version, Versions $versions) { $this->name = $name; $this->path = $path; + $this->version = $version; $this->versions = $versions; $this->loadUpdates(); } /** - * Pre-installation methods. + * Pre-installation method. */ public function preflight(): void { @@ -45,7 +47,17 @@ final class VersionUpdater } /** - * Post-installation methods. + * Install method. + */ + public function install(): void + { + $versions = $this->getVersions(); + $versions->updateVersion($this->name, $this->version); + $versions->save(); + } + + /** + * Post-installation method. */ public function postflight(): void {