From a40357cec951beecfadb0b730ab95324dc1eac7f Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 21 Mar 2017 17:42:56 +1100 Subject: [PATCH] Added a check for missing dependencies in two places - System dashboard now lists missing dependencies - Installing a plugin with missing dependencies will also attempt to install those dependencies at the same time Fixes #36 --- modules/backend/lang/en/lang.php | 3 ++- modules/system/classes/PluginManager.php | 9 +++++-- modules/system/controllers/Updates.php | 34 ++++++++++++++++-------- modules/system/reportwidgets/Status.php | 9 +++++++ 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 9d5fb2e11..66c8d7e8a 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -313,7 +313,8 @@ return [ 'tips' => 'System configuration tips', 'tips_description' => 'There are issues you need to pay attention to in order to configure the system properly.', 'permissions' => 'Directory :name or its subdirectories is not writable for PHP. Please set corresponding permissions for the webserver on this directory.', - 'extension' => 'The PHP extension :name is not installed. Please install this library and activate the extension.' + 'extension' => 'The PHP extension :name is not installed. Please install this library and activate the extension.', + 'plugin_missing' => 'The plugin :name is a dependency but is not installed. Please install this plugin.', ], 'editor' => [ 'menu_label' => 'Editor settings', diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 09943eb6c..a6ce922f6 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -565,8 +565,12 @@ class PluginManager // /** - * Scans the system plugins to locate any dependencies - * that are not currently installed. + * Scans the system plugins to locate any dependencies that are not currently + * installed. Returns an array of plugin codes that are needed. + * + * PluginManager::instance()->findMissingDependencies(); + * + * @return array */ public function findMissingDependencies() { @@ -592,6 +596,7 @@ class PluginManager /** * Cross checks all plugins and their dependancies, if not met plugins * are disabled and vice versa. + * @return void */ protected function loadDependencies() { diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index fbd40fa61..d520eb212 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -661,6 +661,7 @@ class Updates extends Controller $name = $result['code']; $hash = $result['hash']; $plugins = [$name => $hash]; + $plugins = $this->appendRequiredPlugins($plugins, $result); /* * Update steps @@ -817,17 +818,7 @@ class Updates extends Controller $name = $result['code']; $hash = $result['hash']; $themes = [$name => $hash]; - $plugins = []; - - foreach ((array) array_get($result, 'require') as $plugin) { - if ( - ($name = array_get($plugin, 'code')) && - ($hash = array_get($plugin, 'hash')) && - !PluginManager::instance()->hasPlugin($name) - ) { - $plugins[$name] = $hash; - } - } + $plugins = $this->appendRequiredPlugins([], $result); /* * Update steps @@ -962,4 +953,25 @@ class Updates extends Controller { return str_replace(':', '.', $code); } + + /** + * Adds require plugin codes to the collection based on a result. + * @param array $plugins + * @param array $result + * @return array + */ + protected function appendRequiredPlugins(array $plugins, array $result) + { + foreach ((array) array_get($result, 'require') as $plugin) { + if ( + ($name = array_get($plugin, 'code')) && + ($hash = array_get($plugin, 'hash')) && + !PluginManager::instance()->hasPlugin($name) + ) { + $plugins[$name] = $hash; + } + } + + return $plugins; + } } diff --git a/modules/system/reportwidgets/Status.php b/modules/system/reportwidgets/Status.php index 1a80b3cc1..488825291 100644 --- a/modules/system/reportwidgets/Status.php +++ b/modules/system/reportwidgets/Status.php @@ -4,6 +4,7 @@ use Lang; use BackendAuth; use System\Models\Parameter; use System\Classes\UpdateManager; +use System\Classes\PluginManager; use Backend\Classes\ReportWidgetBase; use System\Models\EventLog; use System\Models\RequestLog; @@ -73,6 +74,8 @@ class Status extends ReportWidgetBase { $warnings = []; + $missingPlugins = PluginManager::instance()->findMissingDependencies(); + $writablePaths = [ temp_path(), themes_path(), @@ -85,6 +88,7 @@ class Status extends ReportWidgetBase storage_path('cms/twig'), storage_path('cms/combiner'), ]; + $requiredExtensions = [ 'GD' => extension_loaded('gd'), 'fileinfo' => extension_loaded('fileinfo'), @@ -98,12 +102,17 @@ class Status extends ReportWidgetBase $warnings[] = Lang::get('backend::lang.warnings.permissions', ['name' => ''.$path.'']); } } + foreach ($requiredExtensions as $extension => $installed) { if (!$installed) { $warnings[] = Lang::get('backend::lang.warnings.extension', ['name' => ''.$extension.'']); } } + foreach ($missingPlugins as $pluginCode) { + $warnings[] = Lang::get('backend::lang.warnings.plugin_missing', ['name' => ''.$pluginCode.'']); + } + return $warnings; } }