From e83db6a59a42902e4d6e112dda4ced4a749b6d39 Mon Sep 17 00:00:00 2001 From: Paweł Sroka Date: Mon, 26 Nov 2012 11:46:44 +0100 Subject: Fixes #4933 - Adds plugin_id to GUID lookup map --- engine/lib/plugins.php | 62 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 17 deletions(-) (limited to 'engine/lib') diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index d5cd4fe76..127d4bf8e 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -107,6 +107,7 @@ 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(); @@ -151,6 +152,7 @@ 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)); } } @@ -175,6 +177,25 @@ function elgg_generate_plugin_entities() { return true; } +/** + * Registers given plugins in plugin_id to entity mapping data structure + * + * @param array $plugins ElggPlugin instances to be registered + * + * @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; + } + } +} + /** * Returns an ElggPlugin object with the path $path. * @@ -183,24 +204,30 @@ function elgg_generate_plugin_entities() { * @since 1.8.0 */ function elgg_get_plugin_from_id($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]; + 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; } - - return false; } /** @@ -390,6 +417,7 @@ 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; -- cgit v1.2.3