]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #6177 - refuse to deactive plugins used as dependencies
authorbeck24 <beck24@gmail.com>
Sun, 13 Oct 2013 07:03:11 +0000 (00:03 -0700)
committerbeck24 <beck24@gmail.com>
Sun, 13 Oct 2013 07:03:11 +0000 (00:03 -0700)
engine/lib/plugins.php
languages/en.php

index 74bce45fdfb375b181d047c992a2ec94467b9fd8..f0d89e92dd5797905ca2f813185fc54e9ab1a743 100644 (file)
@@ -1104,6 +1104,39 @@ function plugins_test($hook, $type, $value, $params) {
        return $value;
 }
 
+function plugins_deactivate_dependency_check($event, $type, $params) {
+    $plugin_id = $params['plugin_entity']->getManifest()->getPluginID();
+    $plugin_name = $params['plugin_entity']->getManifest()->getName();
+  
+    $active_plugins = elgg_get_plugins();
+
+       $dependents = array();
+    foreach ($active_plugins as $plugin) {
+               $manifest = $plugin->getManifest();
+               $requires = $manifest->getRequires();
+    
+               foreach ($requires as $required) {
+                       if ($required['type'] == 'plugin' && $required['name'] == $plugin_id) {
+                               // there are active dependents
+                               $dependents[$manifest->getPluginID()] = $plugin;
+                       }
+               }
+    }
+    
+    if ($dependents) {
+               $list = '<ul>';
+               // construct error message and prevent disabling
+               foreach ($dependents as $dependent) {
+                       $list .= '<li>' . $dependent->getManifest()->getName() . '</li>';
+               }
+               $list .= '</ul>';
+               
+               register_error(elgg_echo('ElggPlugin:Dependencies:ActiveDependent', array($plugin_name, $list)));
+               
+               return false;
+    }
+}
+
 /**
  * Initialize the plugin system
  * Listens to system init and registers actions
@@ -1115,6 +1148,8 @@ function plugin_init() {
        run_function_once("plugin_run_once");
 
        elgg_register_plugin_hook_handler('unit_test', 'system', 'plugins_test');
+       
+       elgg_register_event_handler('deactivate', 'plugin', 'plugins_deactivate_dependency_check');
 
        elgg_register_action("plugins/settings/save", '', 'admin');
        elgg_register_action("plugins/usersettings/save");
index 1721865f7b525b0d26efbaa2d9dd946eb886cdbe..ad4831db7fec8d7885e779e45335f01c099cd42c 100644 (file)
@@ -105,6 +105,8 @@ $english = array(
        'ElggPlugin:Dependencies:Priority:Before' => 'Before %s',
        'ElggPlugin:Dependencies:Priority:Uninstalled' => '%s is not installed',
        'ElggPlugin:Dependencies:Suggests:Unsatisfied' => 'Missing',
+       
+       'ElggPlugin:Dependencies:ActiveDependent' => 'There are other plugins that list %s as a dependency.  You must disable the following plugins before disabling this one: %s',
 
        'ElggPlugin:InvalidAndDeactivated' => '%s is an invalid plugin and has been deactivated.',