From 1026deb7ef24677a2a0b48b4297911a4c2eceb6d Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 4 Feb 2011 21:04:34 +0000 Subject: Added new priority 'requires' for plugin dep system. You can now say that a plugin is required to be after / before another plugin in the system. git-svn-id: http://code.elgg.org/elgg/trunk@8016 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggMenuItem.php | 18 +++++----- engine/classes/ElggPlugin.php | 2 +- engine/classes/ElggPluginManifest.php | 67 +++++++++++++++++++++-------------- engine/classes/ElggPluginPackage.php | 57 ++++++++++++++++++++++++++++- 4 files changed, 107 insertions(+), 37 deletions(-) (limited to 'engine/classes') diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php index 40df8f182..a190a89ef 100644 --- a/engine/classes/ElggMenuItem.php +++ b/engine/classes/ElggMenuItem.php @@ -46,17 +46,17 @@ class ElggMenuItem { /** * @var string Identifier of this item's parent */ - protected $parent_name = ''; + protected $parent_name = ''; - /** - * @var ElggMenuItem The parent object or null - */ - protected $parent = null; + /** + * @var ElggMenuItem The parent object or null + */ + protected $parent = null; - /** - * @var array Array of children objects or empty array - */ - protected $children = array(); + /** + * @var array Array of children objects or empty array + */ + protected $children = array(); /** * ElggMenuItem constructor diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 5782ac4dd..11b57e8d0 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -791,7 +791,7 @@ class ElggPlugin extends ElggObject { } $this->attributes[$name] = $value; - + return true; } else { return set_private_setting($this->guid, $name, $value); diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 9ddf60396..95f008f98 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -32,6 +32,15 @@ class ElggPluginManifest { 'comparison' => 'ge' ); + /** + * The expected structure of a requires element + */ + private $depsRequiresStructPriority = array( + 'type' => '', + 'name' => '', + 'priority' => '', + ); + /* * The expected structure of elgg and elgg_release requires element */ @@ -405,6 +414,10 @@ class ElggPluginManifest { $struct = $this->depsRequiresStructPlugin; break; + case 'priority': + $struct = $this->depsRequiresStructPriority; + break; + case 'php_extension': $struct = $this->depsRequiresStructPhpExtension; break; @@ -438,32 +451,34 @@ class ElggPluginManifest { $normalized_req = $this->buildStruct($struct, $req); // normalize comparison operators - switch ($normalized_req['comparison']) { - case '<': - $normalized_req['comparison'] = 'lt'; - break; - - case '<=': - $normalized_req['comparison'] = 'le'; - break; - - case '>': - $normalized_req['comparison'] = 'gt'; - break; - - case '>=': - $normalized_req['comparison'] = 'ge'; - break; - - case '==': - case 'eq': - $normalized_req['comparison'] = '='; - break; - - case '<>': - case 'ne': - $normalized_req['comparison'] = '!='; - break; + if (isset($normalized_req['comparison'])) { + switch ($normalized_req['comparison']) { + case '<': + $normalized_req['comparison'] = 'lt'; + break; + + case '<=': + $normalized_req['comparison'] = 'le'; + break; + + case '>': + $normalized_req['comparison'] = 'gt'; + break; + + case '>=': + $normalized_req['comparison'] = 'ge'; + break; + + case '==': + case 'eq': + $normalized_req['comparison'] = '='; + break; + + case '<>': + case 'ne': + $normalized_req['comparison'] = '!='; + break; + } } $normalized[] = $normalized_req; diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 01437a4e4..db62620a8 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -42,7 +42,7 @@ class ElggPluginPackage { * @var array */ private $depsSupportedTypes = array( - 'elgg_version', 'elgg_release', 'php_extension', 'php_ini', 'plugin' + 'elgg_version', 'elgg_release', 'php_extension', 'php_ini', 'plugin', 'priority', ); /** @@ -332,6 +332,10 @@ class ElggPluginPackage { $result = $this->checkDepPlugin($dep, $enabled_plugins, $inverse); break; + case 'priority': + $result = $this->checkDepPriority($dep, $enabled_plugins, $inverse); + break; + case 'php_extension': $result = $this->checkDepPhpExtension($dep); break; @@ -393,6 +397,57 @@ class ElggPluginPackage { return $r; } + /** + * Checks if $plugins meets the requirement by $dep. + * + * @param array $dep An Elgg manifest.xml deps array + * @param array $plugins A list of plugins as returned by get_installed_plugins(); + * @param bool $inverse Inverse the results to use as a conflicts. + * @return bool + */ + private function checkDepPriority(array $dep, array $plugins, $inverse = false) { + // see if we exist as an ElggPlugin + $this_plugin = elgg_get_plugin_from_id($this->getID()); + $this_priority = $this_plugin->getPriority(); + + foreach ($plugins as $test_plugin) { + if ($test_plugin->getID() == $dep['name']) { + break; + } + } + + $test_plugin_priority = $test_plugin->getPriority(); + + switch ($dep['priority']) { + case 'before': + $status = $this_priority < $test_plugin_priority; + break; + + case 'after': + $status = $this_priority > $test_plugin_priority; + break; + + default; + $status = false; + } + + // get the current value + if ($this_priority < $test_plugin_priority) { + $value = 'before'; + } else { + $value = 'after'; + } + + if ($inverse) { + $status = !$status; + } + + return array( + 'status' => $status, + 'value' => $value + ); + } + /** * Checks if $elgg_version meets the requirement by $dep. * -- cgit v1.2.3