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
This commit is contained in:
Flavio Copes
2015-12-28 08:53:23 +01:00
parent 492b290845
commit e3deb40f69

View File

@@ -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;
}