aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-29 22:19:22 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-01-29 22:19:22 +0000
commit7b9ec5afdab5d3e873da3e2b18cc5060a1f46585 (patch)
tree35b5bb45e2d5be25fa673fe6713811811ea47094
parent0f98f79a128f2641c6928e49fa0564a3045bf363 (diff)
downloadelgg-7b9ec5afdab5d3e873da3e2b18cc5060a1f46585.tar.gz
elgg-7b9ec5afdab5d3e873da3e2b18cc5060a1f46585.tar.bz2
Fixes #1468: Cleaned up logic for enabling and disabling plugins. Checking for arrays when metadata returns only a single enabled plugin.
git-svn-id: http://code.elgg.org/elgg/trunk@3859 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/plugins.php50
1 files changed, 30 insertions, 20 deletions
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index d7c154b5f..0df6ff03e 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -622,20 +622,20 @@ function enable_plugin($plugin, $site_guid = 0) {
throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite"));
}
- $enabled = $site->getMetaData('enabled_plugins');
- $new_enabled = array();
- if ($enabled) {
+ // getMetadata() doesn't return an array if only one plugin is enabled
+ if ($enabled = $site->enabled_plugins) {
if (!is_array($enabled)) {
- $new_enabled[] = $enabled;
- } else {
- $new_enabled = $enabled;
+ $enabled = array($enabled);
}
+ } else {
+ $enabled = array();
}
- $new_enabled[] = $plugin;
- $new_enabled = array_unique($new_enabled);
- $return = $site->setMetaData('enabled_plugins', $new_enabled);
- $ENABLED_PLUGINS_CACHE = $new_enabled;
+ $enabled[] = $plugin;
+ $enabled = array_unique($enabled);
+
+ $return = $site->setMetaData('enabled_plugins', $enabled);
+ $ENABLED_PLUGINS_CACHE = $enabled;
return $return;
}
@@ -666,17 +666,24 @@ function disable_plugin($plugin, $site_guid = 0) {
throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite"));
}
- $enabled = $site->getMetaData('enabled_plugins');
- $new_enabled = array();
-
- foreach ($enabled as $plug) {
- if ($plugin != $plug) {
- $new_enabled[] = $plug;
+ // getMetadata() doesn't return an array if only one plugin is enabled
+ if ($enabled = $site->enabled_plugins) {
+ if (!is_array($enabled)) {
+ $enabled = array($enabled);
}
+ } else {
+ $enabled = array();
+ }
+
+ // remove the disabled plugin from the array
+ if (FALSE !== $i = array_search($plugin, $enabled)) {
+ unset($enabled[$i]);
}
- $return = $site->setMetaData('enabled_plugins', $new_enabled);
- $ENABLED_PLUGINS_CACHE = $new_enabled;
+ // if we're unsetting all the plugins, this will return an empty array.
+ // it will fail with FALSE, though.
+ $return = (FALSE === $site->enabled_plugins = $enabled) ? FALSE : TRUE;
+ $ENABLED_PLUGINS_CACHE = $enabled;
return $return;
}
@@ -700,14 +707,17 @@ function is_plugin_enabled($plugin, $site_guid = 0) {
$site_guid = $CONFIG->site_guid;
}
-
if (!$ENABLED_PLUGINS_CACHE) {
$site = get_entity($site_guid);
if (!($site instanceof ElggSite)) {
throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $site_guid, "ElggSite"));
}
- $ENABLED_PLUGINS_CACHE = $site->enabled_plugins;
+ $enabled_plugins = $site->enabled_plugins;
+ if ($enabled_plugins && !is_array($enabled_plugins)) {
+ $enabled_plugins = array($enabled_plugins);
+ }
+ $ENABLED_PLUGINS_CACHE = $enabled_plugins;
}
foreach ($ENABLED_PLUGINS_CACHE as $e) {