Fixed GPM errors from blueprints not being logged [#2505]

This commit is contained in:
Matias Griese
2019-05-16 11:51:30 +03:00
parent 65ba214494
commit 01b85f19bc
11 changed files with 70 additions and 28 deletions

View File

@@ -7,6 +7,7 @@
* Optimizations for Plugin/Theme loading * Optimizations for Plugin/Theme loading
1. [](#bugfix) 1. [](#bugfix)
* Force question to install demo content in theme update [#2493](https://github.com/getgrav/grav/issues/2493) * Force question to install demo content in theme update [#2493](https://github.com/getgrav/grav/issues/2493)
* Fixed GPM errors from blueprints not being logged [#2505](https://github.com/getgrav/grav/issues/2505)
# v1.6.9 # v1.6.9
## 05/09/2019 ## 05/09/2019

View File

@@ -39,7 +39,8 @@ class Blueprints
public function get($type) public function get($type)
{ {
if (!isset($this->instances[$type])) { if (!isset($this->instances[$type])) {
$this->instances[$type] = $this->loadFile($type); $blueprint = $this->loadFile($type);
$this->instances[$type] = $blueprint;
} }
return $this->instances[$type]; return $this->instances[$type];
@@ -99,6 +100,15 @@ class Blueprints
$blueprint->setContext($this->search); $blueprint->setContext($this->search);
} }
return $blueprint->load()->init(); try {
$blueprint->load()->init();
} catch (\RuntimeException $e) {
$log = Grav::instance()['log'];
$log->error(sprintf('Blueprint %s cannot be loaded: %s', $name, $e->getMessage()));
throw $e;
}
return $blueprint;
} }
} }

View File

@@ -11,19 +11,22 @@ namespace Grav\Common\GPM\Common;
use Grav\Common\Iterator; use Grav\Common\Iterator;
class CachedCollection extends Iterator { class CachedCollection extends Iterator
{
protected static $cache; protected static $cache;
public function __construct($items) public function __construct($items)
{ {
parent::__construct(); parent::__construct();
$method = static::class . __METHOD__;
// local cache to speed things up // local cache to speed things up
if (!isset(self::$cache[get_called_class() . __METHOD__])) { if (!isset(self::$cache[$method])) {
self::$cache[get_called_class() . __METHOD__] = $items; self::$cache[$method] = $items;
} }
foreach (self::$cache[get_called_class() . __METHOD__] as $name => $item) { foreach (self::$cache[$method] as $name => $item) {
$this->append([$name => $item]); $this->append([$name => $item]);
} }
} }

View File

@@ -11,8 +11,8 @@ namespace Grav\Common\GPM\Common;
use Grav\Common\Data\Data; use Grav\Common\Data\Data;
class Package { class Package
{
/** /**
* @var Data * @var Data
*/ */

View File

@@ -770,7 +770,7 @@ class GPM extends Iterator
* @param array $ignore_packages_list * @param array $ignore_packages_list
* *
* @return bool * @return bool
* @throws \Exception * @throws \RuntimeException
*/ */
public function checkNoOtherPackageNeedsThisDependencyInALowerVersion( public function checkNoOtherPackageNeedsThisDependencyInALowerVersion(
$slug, $slug,
@@ -793,8 +793,8 @@ class GPM extends Iterator
$compatible = $this->checkNextSignificantReleasesAreCompatible($version, $compatible = $this->checkNextSignificantReleasesAreCompatible($version,
$other_dependency_version); $other_dependency_version);
if (!$compatible) { if (!$compatible) {
if (!in_array($dependent_package, $ignore_packages_list)) { if (!in_array($dependent_package, $ignore_packages_list, true)) {
throw new \Exception("Package <cyan>$slug</cyan> is required in an older version by package <cyan>$dependent_package</cyan>. This package needs a newer version, and because of this it cannot be installed. The <cyan>$dependent_package</cyan> package must be updated to use a newer release of <cyan>$slug</cyan>.", throw new \RuntimeException("Package <cyan>$slug</cyan> is required in an older version by package <cyan>$dependent_package</cyan>. This package needs a newer version, and because of this it cannot be installed. The <cyan>$dependent_package</cyan> package must be updated to use a newer release of <cyan>$slug</cyan>.",
2); 2);
} }
} }
@@ -850,10 +850,10 @@ class GPM extends Iterator
) { ) {
//Needs a Grav update first //Needs a Grav update first
throw new \RuntimeException("<red>One of the packages require PHP {$dependencies['php']}. Please update PHP to resolve this"); throw new \RuntimeException("<red>One of the packages require PHP {$dependencies['php']}. Please update PHP to resolve this");
} else {
unset($dependencies[$dependency_slug]);
continue;
} }
unset($dependencies[$dependency_slug]);
continue;
} }
//First, check for Grav dependency. If a dependency requires Grav > the current version, abort and tell. //First, check for Grav dependency. If a dependency requires Grav > the current version, abort and tell.
@@ -863,10 +863,10 @@ class GPM extends Iterator
) { ) {
//Needs a Grav update first //Needs a Grav update first
throw new \RuntimeException("<red>One of the packages require Grav {$dependencies['grav']}. Please update Grav to the latest release."); throw new \RuntimeException("<red>One of the packages require Grav {$dependencies['grav']}. Please update Grav to the latest release.");
} else {
unset($dependencies[$dependency_slug]);
continue;
} }
unset($dependencies[$dependency_slug]);
continue;
} }
if ($this->isPluginInstalled($dependency_slug)) { if ($this->isPluginInstalled($dependency_slug)) {
@@ -1092,6 +1092,7 @@ class GPM extends Iterator
if ($this->versionFormatIsEqualOrHigher($version)) { if ($this->versionFormatIsEqualOrHigher($version)) {
return trim(substr($version, 2)); return trim(substr($version, 2));
} }
return $version; return $version;
} }
@@ -1104,7 +1105,7 @@ class GPM extends Iterator
* *
* @return bool * @return bool
*/ */
public function versionFormatIsNextSignificantRelease($version) public function versionFormatIsNextSignificantRelease($version): bool
{ {
return strpos($version, '~') === 0; return strpos($version, '~') === 0;
} }
@@ -1118,7 +1119,7 @@ class GPM extends Iterator
* *
* @return bool * @return bool
*/ */
public function versionFormatIsEqualOrHigher($version) public function versionFormatIsEqualOrHigher($version): bool
{ {
return strpos($version, '>=') === 0; return strpos($version, '>=') === 0;
} }
@@ -1136,7 +1137,7 @@ class GPM extends Iterator
* *
* @return bool * @return bool
*/ */
public function checkNextSignificantReleasesAreCompatible($version1, $version2) public function checkNextSignificantReleasesAreCompatible($version1, $version2): bool
{ {
$version1array = explode('.', $version1); $version1array = explode('.', $version1);
$version2array = explode('.', $version2); $version2array = explode('.', $version2);

View File

@@ -16,6 +16,7 @@ abstract class AbstractPackageCollection extends BaseCollection
public function __construct($items) public function __construct($items)
{ {
parent::__construct(); parent::__construct();
foreach ($items as $name => $data) { foreach ($items as $name => $data) {
$data->set('slug', $name); $data->set('slug', $name);
$this->items[$name] = new Package($data, $this->type); $this->items[$name] = new Package($data, $this->type);

View File

@@ -25,6 +25,7 @@ class Plugins extends AbstractPackageCollection
{ {
/** @var \Grav\Common\Plugins $plugins */ /** @var \Grav\Common\Plugins $plugins */
$plugins = Grav::instance()['plugins']; $plugins = Grav::instance()['plugins'];
parent::__construct($plugins->all()); parent::__construct($plugins->all());
} }
} }

View File

@@ -43,7 +43,7 @@ class AbstractPackageCollection extends BaseCollection
{ {
parent::__construct(); parent::__construct();
if ($repository === null) { if ($repository === null) {
throw new \RuntimeException("A repository is required to indicate the origin of the remote collection"); throw new \RuntimeException('A repository is required to indicate the origin of the remote collection');
} }
$channel = Grav::instance()['config']->get('system.gpm.releases', 'stable'); $channel = Grav::instance()['config']->get('system.gpm.releases', 'stable');

View File

@@ -37,9 +37,9 @@ class GravCore extends AbstractPackageCollection
$this->fetch($refresh, $callback); $this->fetch($refresh, $callback);
$this->data = json_decode($this->raw, true); $this->data = json_decode($this->raw, true);
$this->version = isset($this->data['version']) ? $this->data['version'] : '-'; $this->version = $this->data['version'] ?? '-';
$this->date = isset($this->data['date']) ? $this->data['date'] : '-'; $this->date = $this->data['date'] ?? '-';
$this->min_php = isset($this->data['min_php']) ? $this->data['min_php'] : null; $this->min_php = $this->data['min_php'] ?? null;
if (isset($this->data['assets'])) { if (isset($this->data['assets'])) {
foreach ((array)$this->data['assets'] as $slug => $data) { foreach ((array)$this->data['assets'] as $slug => $data) {

View File

@@ -133,12 +133,25 @@ class Plugins extends Iterator
*/ */
public static function all() public static function all()
{ {
$plugins = Grav::instance()['plugins']; $grav = Grav::instance();
$plugins = $grav['plugins'];
$list = []; $list = [];
foreach ($plugins as $instance) { foreach ($plugins as $instance) {
$name = $instance->name; $name = $instance->name;
$result = self::get($name);
try {
$result = self::get($name);
} catch (\Exception $e) {
$exception = new \RuntimeException(sprintf('Plugin %s: %s', $name, $e->getMessage()), $e->getCode(), $e);
/** @var Debugger $debugger */
$debugger = $grav['debugger'];
$debugger->addMessage("Plugin {$name} cannot be loaded, please check Exceptions tab", 'error');
$debugger->addException($exception);
continue;
}
if ($result) { if ($result) {
$list[$name] = $result; $list[$name] = $result;

View File

@@ -100,7 +100,19 @@ class Themes extends Iterator
} }
$theme = $directory->getFilename(); $theme = $directory->getFilename();
$result = $this->get($theme);
try {
$result = $this->get($theme);
} catch (\Exception $e) {
$exception = new \RuntimeException(sprintf('Theme %s: %s', $theme, $e->getMessage()), $e->getCode(), $e);
/** @var Debugger $debugger */
$debugger = $this->grav['debugger'];
$debugger->addMessage("Theme {$theme} cannot be loaded, please check Exceptions tab", 'error');
$debugger->addException($exception);
continue;
}
if ($result) { if ($result) {
$list[$theme] = $result; $list[$theme] = $result;