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 +++++++++++++++++- engine/lib/plugins.php | 20 +++++-- languages/en.php | 6 +- .../admin/components/plugin_dependencies.php | 11 ++-- views/default/css/admin.php | 3 + 8 files changed, 137 insertions(+), 47 deletions(-) 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. * diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 2174814bd..e61874ebc 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -669,6 +669,7 @@ function elgg_get_plugin_dependency_strings($dep) { 'requires' 'php setting bob' >3 3 'change it' 'conflicts' 'php setting' >3 4 'change it' 'provides' 'plugin oauth_lib' 1.3 -- -- + 'priority' 'before blog' -- after 'move it' */ $strings = array(); $strings['type'] = elgg_echo('ElggPlugin:Dependencies:' . ucwords($dep_system)); @@ -678,7 +679,7 @@ function elgg_get_plugin_dependency_strings($dep) { case 'elgg_release': // 'Elgg Version' $strings['name'] = elgg_echo('ElggPlugin:Dependencies:Elgg'); - $strings['value'] = "$comparison {$info['version']}"; + $strings['expected_value'] = "$comparison {$info['version']}"; $strings['local_value'] = $dep['value']; $strings['comment'] = ''; break; @@ -687,10 +688,10 @@ function elgg_get_plugin_dependency_strings($dep) { // PHP Extension %s [version] $strings['name'] = elgg_echo('ElggPlugin:Dependencies:PhpExtension', array($info['name'])); if ($info['version']) { - $strings['value'] = "$comparison {$info['version']}"; + $strings['expected_value'] = "$comparison {$info['version']}"; $strings['local_value'] = $dep['value']; } else { - $strings['value'] = ''; + $strings['expected_value'] = ''; $strings['local_value'] = ''; } $strings['comment'] = ''; @@ -698,17 +699,26 @@ function elgg_get_plugin_dependency_strings($dep) { case 'php_ini': $strings['name'] = elgg_echo('ElggPlugin:Dependencies:PhpIni', array($info['name'])); - $strings['value'] = "$comparison {$info['value']}"; + $strings['expected_value'] = "$comparison {$info['value']}"; $strings['local_value'] = $dep['value']; $strings['comment'] = ''; break; case 'plugin': $strings['name'] = elgg_echo('ElggPlugin:Dependencies:Plugin', array($info['name'])); - $strings['value'] = "$comparison {$info['version']}"; + $strings['expected_value'] = "$comparison {$info['version']}"; $strings['local_value'] = $dep['version']; $strings['comment'] = ''; break; + + case 'priority': + $expected_priority = ucwords($info['priority']); + $real_priority = ucwords($dep['value']); + $strings['name'] = elgg_echo('ElggPlugin:Dependencies:Priority'); + $strings['expected_value'] = elgg_echo("ElggPlugin:Dependencies:Priority:$expected_priority", array($info['name'])); + $strings['local_value'] = elgg_echo("ElggPlugin:Dependencies:Priority:$real_priority", array($info['name'])); + $strings['comment'] = ''; + break; } if ($dep['status']) { diff --git a/languages/en.php b/languages/en.php index 648c84b70..3d4484e2e 100644 --- a/languages/en.php +++ b/languages/en.php @@ -87,11 +87,15 @@ $english = array( 'ElggPlugin:Dependencies:Requires' => 'Requires', 'ElggPlugin:Dependencies:Conflicts' => 'Conflicts', 'ElggPlugin:Dependencies:Provides' => 'Provides', + 'ElggPlugin:Dependencies:Priority' => 'Priority', 'ElggPlugin:Dependencies:Elgg' => 'Elgg version', 'ElggPlugin:Dependencies:PhpExtension' => 'PHP extension: %s', 'ElggPlugin:Dependencies:PhpIni' => 'PHP ini setting: %s', 'ElggPlugin:Dependencies:Plugin' => 'Plugin: %s', + 'ElggPlugin:Dependencies:Priority:After' => 'After %s', + 'ElggPlugin:Dependencies:Priority:Before' => 'Before %s', + 'InvalidParameterException:NonElggUser' => "Passing a non-ElggUser to an ElggUser constructor!", @@ -598,7 +602,7 @@ $english = array( 'admin:plugins:dependencies:type' => 'Type', 'admin:plugins:dependencies:name' => 'Name', - 'admin:plugins:dependencies:value' => 'Value', + 'admin:plugins:dependencies:expected_value' => 'Expected Value', 'admin:plugins:dependencies:local_value' => 'Actual value', 'admin:plugins:dependencies:comment' => 'Comment', diff --git a/views/default/admin/components/plugin_dependencies.php b/views/default/admin/components/plugin_dependencies.php index 9e0e284f1..cd38e98b0 100644 --- a/views/default/admin/components/plugin_dependencies.php +++ b/views/default/admin/components/plugin_dependencies.php @@ -11,7 +11,7 @@ $plugin = elgg_get_array_value('plugin', $vars, false); $deps = $plugin->package->checkDependencies(true); -$columns = array('type', 'name', 'value', 'local_value', 'comment'); +$columns = array('type', 'name', 'expected_value', 'local_value', 'comment'); echo ' @@ -19,11 +19,12 @@ echo '
foreach ($columns as $column) { $column = elgg_echo("admin:plugins:dependencies:$column"); - echo ""; + echo ""; } echo ''; +$row = 'odd'; foreach ($deps as $dep) { $fields = elgg_get_plugin_dependency_strings($dep); @@ -33,13 +34,15 @@ foreach ($deps as $dep) { $class = 'elgg-unsatisfied-dependency'; } - echo ""; + echo ""; foreach ($columns as $column) { - echo ""; + echo ""; } echo ''; + + $row = ($row == 'odd') ? 'even' : 'odd'; } echo '
$column$column
{$fields[$column]}{$fields[$column]}
'; \ No newline at end of file diff --git a/views/default/css/admin.php b/views/default/css/admin.php index f8806ff35..4376ca41a 100644 --- a/views/default/css/admin.php +++ b/views/default/css/admin.php @@ -957,6 +957,9 @@ ul.admin_plugins { .plugin_settings { font-weight: normal; } +.elgg-unsatisfied-dependency { + font-weight: bold; +} .active { border:1px solid #999999; background:white; -- cgit v1.2.3