From e3deb40f69d413c36d06b45d6b10c1ea3faf935a Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 28 Dec 2015 08:53:23 +0100 Subject: [PATCH] Improve error when trying to install a plugin/theme from the command line and GPM is unreachable Previously it listed four times `PHP Warning: Invalid argument supplied for foreach()...`, now it fails with an error message --- system/src/Grav/Common/GPM/GPM.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/GPM/GPM.php b/system/src/Grav/Common/GPM/GPM.php index fa1c8081e..c6088e42e 100644 --- a/system/src/Grav/Common/GPM/GPM.php +++ b/system/src/Grav/Common/GPM/GPM.php @@ -323,13 +323,20 @@ class GPM extends Iterator return $found; } - foreach ($this->getRepositoryThemes() as $slug => $theme) { + $themes = $this->getRepositoryThemes(); + $plugins = $this->getRepositoryPlugins(); + + if (!$themes && !$plugins) { + throw new \RuntimeException("GPM not reachable. Please check your internet connection or check the Grav site is reachable"); + } + + if ($themes) foreach ($themes as $slug => $theme) { if ($search == $slug || $search == $theme->name) { return $theme; } } - foreach ($this->getRepositoryPlugins() as $slug => $plugin) { + if ($plugins) foreach ($plugins as $slug => $plugin) { if ($search == $slug || $search == $plugin->name) { return $plugin; }