diff options
author | Steve Clay <steve@mrclay.org> | 2012-11-26 17:31:53 -0500 |
---|---|---|
committer | Steve Clay <steve@mrclay.org> | 2012-11-26 17:31:53 -0500 |
commit | 937119200300ebc2b09df4354fb7cd547535ecfb (patch) | |
tree | 8d8ff330083b3321389ebf13688ff347cac3f290 | |
parent | e83db6a59a42902e4d6e112dda4ced4a749b6d39 (diff) | |
download | elgg-937119200300ebc2b09df4354fb7cd547535ecfb.tar.gz elgg-937119200300ebc2b09df4354fb7cd547535ecfb.tar.bz2 |
Refs #4933: cache in plugin constructor, remove $CONFIG
-rw-r--r-- | engine/classes/ElggPlugin.php | 7 | ||||
-rw-r--r-- | engine/lib/plugins.php | 69 |
2 files changed, 36 insertions, 40 deletions
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 3e43c8e81..c6ce2905f 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -36,8 +36,9 @@ class ElggPlugin extends ElggObject { * @warning Unlike other ElggEntity objects, you cannot null instantiate * ElggPlugin. You must point it to an actual plugin GUID or location. * - * @param mixed $plugin The GUID of the ElggPlugin object or the path of - * the plugin to load. + * @param mixed $plugin The GUID of the ElggPlugin object or the path of the plugin to load. + * + * @throws PluginException */ public function __construct($plugin) { if (!$plugin) { @@ -76,6 +77,8 @@ class ElggPlugin extends ElggObject { // load the rest of the plugin parent::__construct($existing_guid); } + + _elgg_cache_plugin_by_id($this); } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 127d4bf8e..ca4a957f4 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -107,7 +107,6 @@ function elgg_generate_plugin_entities() { $old_access = access_get_show_hidden_status(); access_show_hidden_entities(true); $known_plugins = elgg_get_entities_from_relationship($options); - _elgg_add_plugin_ids_mapping($known_plugins); if (!$known_plugins) { $known_plugins = array(); @@ -152,7 +151,6 @@ function elgg_generate_plugin_entities() { // priority is force to last in save() if not set. $plugin = new ElggPlugin($plugin_id); $plugin->save(); - _elgg_add_plugin_ids_mapping(array($plugin)); } } @@ -178,22 +176,16 @@ function elgg_generate_plugin_entities() { } /** - * Registers given plugins in plugin_id to entity mapping data structure + * Cache a reference to this plugin by its ID * - * @param array $plugins ElggPlugin instances to be registered + * @param ElggPlugin $plugin * * @access private */ -function _elgg_add_plugin_ids_mapping($plugins) { - global $CONFIG; - if (!is_array($CONFIG->plugin_ids_mapping)) { - $CONFIG->plugin_ids_mapping = array(); - } - foreach ($plugins as $plugin) { - if ($plugin instanceof ElggPlugin) { - $CONFIG->plugin_ids_mapping[$plugin->getID()] = $plugin; - } - } +function _elgg_cache_plugin_by_id(ElggPlugin $plugin) { + $map = (array) elgg_get_config('plugins_by_id_map'); + $map[$plugin->getID()] = $plugin; + elgg_set_config('plugins_by_id_map', $map); } /** @@ -204,30 +196,29 @@ function _elgg_add_plugin_ids_mapping($plugins) { * @since 1.8.0 */ function elgg_get_plugin_from_id($plugin_id) { - global $CONFIG; - if (isset($CONFIG->plugin_ids_mapping[$plugin_id])) { - return $CONFIG->plugin_ids_mapping[$plugin_id]; - } else { - $plugin_id = sanitize_string($plugin_id); - $db_prefix = get_config('dbprefix'); - - $options = array( - 'type' => 'object', - 'subtype' => 'plugin', - 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), - 'wheres' => array("oe.title = '$plugin_id'"), - 'limit' => 1 - ); - - $plugins = elgg_get_entities($options); - - if ($plugins) { - _elgg_add_plugin_ids_mapping($plugins); - return $plugins[0]; - } - - return false; + $map = (array) elgg_get_config('plugins_by_id_map'); + if (isset($map[$plugin_id])) { + return $map[$plugin_id]; + } + + $plugin_id = sanitize_string($plugin_id); + $db_prefix = get_config('dbprefix'); + + $options = array( + 'type' => 'object', + 'subtype' => 'plugin', + 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), + 'wheres' => array("oe.title = '$plugin_id'"), + 'limit' => 1 + ); + + $plugins = elgg_get_entities($options); + + if ($plugins) { + return $plugins[0]; } + + return false; } /** @@ -417,7 +408,6 @@ function elgg_get_plugins($status = 'active', $site_guid = null) { $old_ia = elgg_set_ignore_access(true); $plugins = elgg_get_entities_from_relationship($options); - _elgg_add_plugin_ids_mapping($plugins); elgg_set_ignore_access($old_ia); return $plugins; @@ -540,6 +530,8 @@ function elgg_namespace_plugin_private_setting($type, $name, $id = null) { * @return string|false Plugin name, or false if no plugin name was called * @since 1.8.0 * @access private + * + * @todo get rid of this */ function elgg_get_calling_plugin_id($mainfilename = false) { if (!$mainfilename) { @@ -948,6 +940,7 @@ function elgg_set_plugin_setting($name, $value, $plugin_id = null) { * * @return mixed * @since 1.8.0 + * @todo make $plugin_id required in future version */ function elgg_get_plugin_setting($name, $plugin_id = null) { if ($plugin_id) { |