mirror of
https://github.com/getgrav/grav.git
synced 2026-07-15 20:53:28 +02:00
Add version information when upgrading Grav
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user