Skip to content

Commit

Permalink
Fixed GPM errors from blueprints not being logged [#2505]
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 16, 2019
1 parent 65ba214 commit 01b85f1
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Optimizations for Plugin/Theme loading
1. [](#bugfix)
* 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
## 05/09/2019
Expand Down
14 changes: 12 additions & 2 deletions system/src/Grav/Common/Data/Blueprints.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function __construct($search = 'blueprints://')
public function get($type)
{
if (!isset($this->instances[$type])) {
$this->instances[$type] = $this->loadFile($type);
$blueprint = $this->loadFile($type);
$this->instances[$type] = $blueprint;
}

return $this->instances[$type];
Expand Down Expand Up @@ -99,6 +100,15 @@ protected function loadFile($name)
$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;
}
}
13 changes: 8 additions & 5 deletions system/src/Grav/Common/GPM/Common/CachedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@

use Grav\Common\Iterator;

class CachedCollection extends Iterator {

class CachedCollection extends Iterator
{
protected static $cache;

public function __construct($items)
{
parent::__construct();

$method = static::class . __METHOD__;

// local cache to speed things up
if (!isset(self::$cache[get_called_class() . __METHOD__])) {
self::$cache[get_called_class() . __METHOD__] = $items;
if (!isset(self::$cache[$method])) {
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]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions system/src/Grav/Common/GPM/Common/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use Grav\Common\Data\Data;

class Package {

class Package
{
/**
* @var Data
*/
Expand Down
25 changes: 13 additions & 12 deletions system/src/Grav/Common/GPM/GPM.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public function getVersionOfDependencyRequiredByPackage($package_slug, $dependen
* @param array $ignore_packages_list
*
* @return bool
* @throws \Exception
* @throws \RuntimeException
*/
public function checkNoOtherPackageNeedsThisDependencyInALowerVersion(
$slug,
Expand All @@ -793,8 +793,8 @@ public function checkNoOtherPackageNeedsThisDependencyInALowerVersion(
$compatible = $this->checkNextSignificantReleasesAreCompatible($version,
$other_dependency_version);
if (!$compatible) {
if (!in_array($dependent_package, $ignore_packages_list)) {
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>.",
if (!in_array($dependent_package, $ignore_packages_list, true)) {
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);
}
}
Expand Down Expand Up @@ -850,10 +850,10 @@ public function getDependencies($packages)
) {
//Needs a Grav update first
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.
Expand All @@ -863,10 +863,10 @@ public function getDependencies($packages)
) {
//Needs a Grav update first
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)) {
Expand Down Expand Up @@ -1092,6 +1092,7 @@ public function calculateVersionNumberFromDependencyVersion($version)
if ($this->versionFormatIsEqualOrHigher($version)) {
return trim(substr($version, 2));
}

return $version;
}

Expand All @@ -1104,7 +1105,7 @@ public function calculateVersionNumberFromDependencyVersion($version)
*
* @return bool
*/
public function versionFormatIsNextSignificantRelease($version)
public function versionFormatIsNextSignificantRelease($version): bool
{
return strpos($version, '~') === 0;
}
Expand All @@ -1118,7 +1119,7 @@ public function versionFormatIsNextSignificantRelease($version)
*
* @return bool
*/
public function versionFormatIsEqualOrHigher($version)
public function versionFormatIsEqualOrHigher($version): bool
{
return strpos($version, '>=') === 0;
}
Expand All @@ -1136,7 +1137,7 @@ public function versionFormatIsEqualOrHigher($version)
*
* @return bool
*/
public function checkNextSignificantReleasesAreCompatible($version1, $version2)
public function checkNextSignificantReleasesAreCompatible($version1, $version2): bool
{
$version1array = explode('.', $version1);
$version2array = explode('.', $version2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ abstract class AbstractPackageCollection extends BaseCollection
public function __construct($items)
{
parent::__construct();

foreach ($items as $name => $data) {
$data->set('slug', $name);
$this->items[$name] = new Package($data, $this->type);
Expand Down
1 change: 1 addition & 0 deletions system/src/Grav/Common/GPM/Local/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct()
{
/** @var \Grav\Common\Plugins $plugins */
$plugins = Grav::instance()['plugins'];

parent::__construct($plugins->all());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct($repository = null, $refresh = false, $callback = nu
{
parent::__construct();
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');
Expand Down
6 changes: 3 additions & 3 deletions system/src/Grav/Common/GPM/Remote/GravCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function __construct($refresh = false, $callback = null)
$this->fetch($refresh, $callback);

$this->data = json_decode($this->raw, true);
$this->version = isset($this->data['version']) ? $this->data['version'] : '-';
$this->date = isset($this->data['date']) ? $this->data['date'] : '-';
$this->min_php = isset($this->data['min_php']) ? $this->data['min_php'] : null;
$this->version = $this->data['version'] ?? '-';
$this->date = $this->data['date'] ?? '-';
$this->min_php = $this->data['min_php'] ?? null;

if (isset($this->data['assets'])) {
foreach ((array)$this->data['assets'] as $slug => $data) {
Expand Down
17 changes: 15 additions & 2 deletions system/src/Grav/Common/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,25 @@ public function add($plugin)
*/
public static function all()
{
$plugins = Grav::instance()['plugins'];
$grav = Grav::instance();
$plugins = $grav['plugins'];
$list = [];

foreach ($plugins as $instance) {
$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) {
$list[$name] = $result;
Expand Down
14 changes: 13 additions & 1 deletion system/src/Grav/Common/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,19 @@ public function all()
}

$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) {
$list[$theme] = $result;
Expand Down

0 comments on commit 01b85f1

Please sign in to comment.