Fixed bin/gpm selfupgrade error on Call to undefined method [#3160]

This commit is contained in:
Matias Griese
2021-01-20 14:03:04 +02:00
parent eb98597220
commit f5b10564ca
5 changed files with 31 additions and 70 deletions

View File

@@ -6,6 +6,7 @@
* Sanitize valid Page extensions from `Page::template_format()`
* Fixed `bin/gpm index` erroring out [#3158](https://github.com/getgrav/grav/issues/3158)
* Fixed `bin/gpm selfupgrade` failing to report failed Grav update [#3116](https://github.com/getgrav/grav/issues/3116)
* Fixed `bin/gpm selfupgrade` error on `Call to undefined method` [#3160](https://github.com/getgrav/grav/issues/3160)
* Flex Pages: Fixed fatal error when trying to move a page to Root (/) [#3161](https://github.com/getgrav/grav/issues/3161)
# v1.7.0

View File

@@ -12,6 +12,7 @@ namespace Grav\Console\Cli;
use Grav\Common\Cache;
use Grav\Console\GravCommand;
use Symfony\Component\Console\Input\InputOption;
use function is_callable;
/**
* Class ClearCacheCommand
@@ -44,6 +45,14 @@ class ClearCacheCommand extends GravCommand
*/
protected function serve(): int
{
// Old versions of Grav called this command after grav upgrade.
// We need make this command to work with older GravCommand instance:
if (!is_callable($this, 'initializePlugins')) {
Cache::clearCache('all');
return 0;
}
$this->initializePlugins();
$this->cleanPaths();

View File

@@ -73,6 +73,7 @@ class DirectInstallCommand extends GpmCommand
{
$input = $this->getInput();
$io = $this->getIO();
if (!class_exists(ZipArchive::class)) {
$io->title('Direct Install');
$io->error('php-zip extension needs to be enabled!');
@@ -266,6 +267,9 @@ class DirectInstallCommand extends GpmCommand
],
$extracted
);
// clear cache after successful upgrade
$this->clearCache();
}
Folder::delete($tmp_source);
@@ -289,31 +293,16 @@ class DirectInstallCommand extends GpmCommand
Folder::delete($tmp_zip);
// clear cache after successful upgrade
$this->clearCache();
return 0;
}
/**
* @param string $zip
* @param string $folder
* @param bool $keepFolder
* @return void
*/
private function upgradeGrav(string $zip, string $folder, bool $keepFolder = false): void
private function upgradeGrav(string $zip, string $folder): void
{
static $ignores = [
'backup',
'cache',
'images',
'logs',
'tmp',
'user',
'.htaccess',
'robots.txt'
];
if (!is_dir($folder)) {
Installer::setError('Invalid source folder');
}
@@ -324,15 +313,7 @@ class DirectInstallCommand extends GpmCommand
if ((file_exists($script) && $install = include $script) && is_callable($install)) {
$install($zip);
} else {
Installer::install(
$zip,
GRAV_ROOT,
['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true, 'ignores' => $ignores],
$folder,
$keepFolder
);
Cache::clearCache();
throw new RuntimeException('Uploaded archive file is not a valid Grav update package');
}
} catch (Exception $e) {
Installer::setError($e->getMessage());

View File

@@ -10,13 +10,13 @@
namespace Grav\Console\Gpm;
use Exception;
use Grav\Common\Cache;
use Grav\Common\Filesystem\Folder;
use Grav\Common\GPM\Installer;
use Grav\Common\GPM\Response;
use Grav\Common\GPM\Upgrader;
use Grav\Common\Grav;
use Grav\Console\GpmCommand;
use RuntimeException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\ConfirmationQuestion;
@@ -36,7 +36,7 @@ class SelfupgradeCommand extends GpmCommand
protected $file;
/** @var array */
protected $types = ['plugins', 'themes'];
/** @var string */
/** @var string|null */
private $tmp;
/** @var Upgrader */
private $upgrader;
@@ -202,8 +202,9 @@ class SelfupgradeCommand extends GpmCommand
$io->newLine();
}
// clear cache after successful upgrade
$this->clearCache(['all']);
if ($this->tmp && is_dir($this->tmp)) {
Folder::delete($this->tmp);
}
return $error;
}
@@ -217,7 +218,7 @@ class SelfupgradeCommand extends GpmCommand
$io = $this->getIO();
$tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
$this->tmp = $tmp_dir . '/Grav-' . uniqid('', false);
$this->tmp = $tmp_dir . '/grav-update-' . uniqid('', false);
$options = [
'curl' => [
CURLOPT_TIMEOUT => $this->timeout,
@@ -247,17 +248,7 @@ class SelfupgradeCommand extends GpmCommand
{
$io = $this->getIO();
if ($this->file) {
$folder = Installer::unZip($this->file, $this->tmp . '/zip');
} else {
$folder = false;
}
$this->upgradeGrav($this->file, $folder);
if ($this->tmp) {
Folder::delete($this->tmp);
}
$this->upgradeGrav($this->file);
$errorCode = Installer::lastErrorCode();
if ($errorCode) {
@@ -308,42 +299,21 @@ class SelfupgradeCommand extends GpmCommand
/**
* @param string $zip
* @param string $folder
* @param bool $keepFolder
* @return void
*/
private function upgradeGrav(string $zip, string $folder, bool $keepFolder = false): void
private function upgradeGrav(string $zip): void
{
static $ignores = [
'backup',
'cache',
'images',
'logs',
'tmp',
'user',
'.htaccess',
'robots.txt'
];
if (!is_dir($folder)) {
Installer::setError('Invalid source folder');
}
try {
$folder = Installer::unZip($zip, $this->tmp . '/zip');
if ($folder === false) {
throw new RuntimeException(Installer::lastErrorMsg());
}
$script = $folder . '/system/install.php';
/** Install $installer */
if ((file_exists($script) && $install = include $script) && is_callable($install)) {
$install($zip);
} else {
Installer::install(
$zip,
GRAV_ROOT,
['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true, 'ignores' => $ignores],
$folder,
$keepFolder
);
Cache::clearCache();
throw new RuntimeException('Uploaded archive file is not a valid Grav update package');
}
} catch (Exception $e) {
Installer::setError($e->getMessage());

View File

@@ -285,7 +285,7 @@ ERR;
{
$this->updater->postflight();
Cache::clearCache();
Cache::clearCache('all');
clearstatcache();
if (function_exists('opcache_reset')) {