Pārlūkot izejas kodu

Allow plugins to specify that other plugins are incompatible with it in the info() function - in the required_plugins array therein, the incompatible plugin name as array key and value of SQ_INCOMPATIBLE. See upcoming release of the add_address plugin for an example.

pdontthink 17 gadi atpakaļ
vecāks
revīzija
f5f1f8d4c0
2 mainītis faili ar 37 papildinājumiem un 14 dzēšanām
  1. 29 12
      functions/plugin.php
  2. 8 2
      src/configtest.php

+ 29 - 12
functions/plugin.php

@@ -759,13 +759,15 @@ function get_plugin_requirement($plugin_name, $requirement,
   *               which might vary per the value of $do_parse
   *               which might vary per the value of $do_parse
   *               as well as if the plugin requires a SquirrelMail
   *               as well as if the plugin requires a SquirrelMail
   *               core plugin, in which case it is "CORE" or
   *               core plugin, in which case it is "CORE" or
-  *               "CORE:1.5.2" or similar), 'activate' - value is
-  *               boolean: TRUE indicates that the plugin must
-  *               also be activated, FALSE means that it only
-  *               needs to be present, but does not need to be
-  *               activated.  Note that the return value might
-  *               be an empty array, indicating that the plugin
-  *               has no dependencies.
+  *               "CORE:1.5.2" or similar, or, if the plugin is
+  *               actually incompatible (not required) with this
+  *               one, the constant SQ_INCOMPATIBLE will be found
+  *               here), 'activate' - value is boolean: TRUE
+  *               indicates that the plugin must also be activated,
+  *               FALSE means that it only needs to be present,
+  *               but does not need to be activated.  Note that
+  *               the return value might be an empty array,
+  *               indicating that the plugin has no dependencies.
   *
   *
   */
   */
 function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE, 
 function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE, 
@@ -817,7 +819,7 @@ function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE,
 
 
          // parse version into something we understand?
          // parse version into something we understand?
          //
          //
-         if ($do_parse)
+         if ($do_parse && $plugin_requirements['version'] != SQ_INCOMPATIBLE)
          {
          {
 
 
             // massage version number into something we understand
             // massage version number into something we understand
@@ -911,10 +913,12 @@ function get_plugin_dependencies($plugin_name, $force_inclusion = FALSE,
   *               corresponding values) will be available: 
   *               corresponding values) will be available: 
   *               'version' - value is the minimum version 
   *               'version' - value is the minimum version 
   *               required for that plugin (in printable, non-
   *               required for that plugin (in printable, non-
-  *               parsed format), 'activate' - value is boolean: 
-  *               TRUE indicates that the plugin must also be 
-  *               activated, FALSE means that it only needs to 
-  *               be present, but does not need to be activated.  
+  *               parsed format) or the constant SQ_INCOMPATIBLE,
+  *               which indicates that the plugin is actually
+  *               incompatible (not required), 'activate' - value
+  *               is boolean: TRUE indicates that the plugin must
+  *               also be activated, FALSE means that it only needs
+  *               to be present, but does not need to be activated.  
   *
   *
   */
   */
 function check_plugin_dependencies($plugin_name, $force_inclusion = FALSE)
 function check_plugin_dependencies($plugin_name, $force_inclusion = FALSE)
@@ -965,6 +969,19 @@ function check_plugin_dependencies($plugin_name, $force_inclusion = FALSE)
 
 
       }
       }
 
 
+      // if the plugin is actually incompatible; check that it
+      // is not activated
+      //
+      if ($depend_requirements['version'] == SQ_INCOMPATIBLE)
+      {
+
+         if (is_plugin_enabled($depend_name))
+            $missing_or_bad[$depend_name] = $depend_requirements;
+
+         continue;
+
+      }
+
       // check for normal plugins
       // check for normal plugins
       //
       //
       $version = explode('.', $depend_requirements['version'], 3);
       $version = explode('.', $depend_requirements['version'], 3);

+ 8 - 2
src/configtest.php

@@ -490,10 +490,16 @@ if (isset($plugins[0])) {
         }
         }
         else if (is_array($failed_dependencies)) {
         else if (is_array($failed_dependencies)) {
             $missing_plugins = '';
             $missing_plugins = '';
+            $incompatible_plugins = '';
             foreach ($failed_dependencies as $depend_name => $depend_requirements) {
             foreach ($failed_dependencies as $depend_name => $depend_requirements) {
-                $missing_plugins .= ', ' . $depend_name . ' (version ' . $depend_requirements['version'] . ', ' . ($depend_requirements['activate'] ? 'must be activated' : 'need not be activated') . ')';
+                if ($depend_requirements['version'] == SQ_INCOMPATIBLE)
+                    $incompatible_plugins .= ', ' . $depend_name;
+                else
+                    $missing_plugins .= ', ' . $depend_name . ' (version ' . $depend_requirements['version'] . ', ' . ($depend_requirements['activate'] ? 'must be activated' : 'need not be activated') . ')';
             }
             }
-            do_err($name . ' is missing some dependencies: ' . trim($missing_plugins, ', '), FALSE);
+            $error_string = (!empty($incompatible_plugins) ? $name . ' cannot be activated at the same time as the following plugins: ' . trim($incompatible_plugins, ', ') : '')
+                          . (!empty($missing_plugins) ? (!empty($incompatible_plugins) ? '.  ' . $name . ' is also ' : $name . ' is ') . 'missing some dependencies: ' . trim($missing_plugins, ', ') : '');
+            do_err($error_string, FALSE);
         }
         }
 
 
     }
     }