From 06b068d43b62731fdd74e03c7ed0fec32402b831 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 18 Nov 2013 20:04:00 +0100 Subject: [PATCH] Don't allow double plugin loading --- lib/cache.php | 8 +++----- lib/statusnet.php | 24 ++++++++++++++++++------ scripts/showplugins.php | 3 +-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/cache.php b/lib/cache.php index 01bc29fa48..e79d75c294 100644 --- a/lib/cache.php +++ b/lib/cache.php @@ -125,14 +125,12 @@ class Cache if (empty($prefix)) { - $plugins = StatusNet::getActivePlugins(); - $names = array(); + $names = array(); - foreach ($plugins as $plugin) { - $names[] = $plugin[0]; + foreach (StatusNet::getActivePlugins() as $plugin=>$attrs) { + $names[] = $plugin; } - $names = array_unique($names); asort($names); // Unique enough. diff --git a/lib/statusnet.php b/lib/statusnet.php index 432c5b8a20..cf2069c1a6 100644 --- a/lib/statusnet.php +++ b/lib/statusnet.php @@ -47,6 +47,14 @@ class StatusNet public static function addPlugin($name, $attrs = null) { $name = ucfirst($name); + + if (isset(self::$plugins[$name])) { + // We have already loaded this plugin. Don't try to + // do it again with (possibly) different values. + // Försten till kvarn får mala. + return true; + } + $pluginclass = "{$name}Plugin"; if (!class_exists($pluginclass)) { @@ -78,7 +86,7 @@ class StatusNet } // Record activated plugins for later display/config dump - self::$plugins[] = array($name, $attrs); + self::$plugins[$name] = $attrs; return true; } @@ -181,9 +189,13 @@ class StatusNet */ protected static function initPlugins() { + // User config may have already added some of these plugins, with + // maybe configured parameters. The self::addPlugin function will + // ignore the new call if it has already been instantiated. + // Load core plugins foreach (common_config('plugins', 'core') as $name => $params) { - call_user_func('addPlugin', $name, $params); + call_user_func('self::addPlugin', $name, $params); } // Load default plugins @@ -194,17 +206,17 @@ class StatusNet } if (is_null($params)) { - addPlugin($name); + self::addPlugin($name); } else if (is_array($params)) { if (count($params) == 0) { - addPlugin($name); + self::addPlugin($name); } else { $keys = array_keys($params); if (is_string($keys[0])) { - addPlugin($name, $params); + self::addPlugin($name, $params); } else { foreach ($params as $paramset) { - addPlugin($name, $paramset); + self::addPlugin($name, $paramset); } } } diff --git a/scripts/showplugins.php b/scripts/showplugins.php index 058393b0ee..3c03646227 100755 --- a/scripts/showplugins.php +++ b/scripts/showplugins.php @@ -22,8 +22,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); require_once INSTALLDIR.'/scripts/commandline.inc'; -foreach (StatusNet::getActivePlugins() as $data) { - list($plugin, $args) = $data; +foreach (StatusNet::getActivePlugins() as $plugin=>$args) { echo "$plugin: "; if ($args === null) { echo "(no args)\n";