From 3048db0f3f1ade31d6f3a2cdd3268e978a3e3cf3 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 17 Sep 2012 17:41:15 -0400 Subject: Fixes #4861: allow lazy-loading for static method callbacks, allow more callables --- engine/lib/entities.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a50567d9f..5a5906b1f 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -2011,7 +2011,7 @@ function get_entity_url($entity_guid) { function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) { global $CONFIG; - if (!is_callable($function_name)) { + if (!is_callable($function_name, true)) { return false; } -- cgit v1.2.3 From 4f9fb7df0dabfa470e1f7045428c5e47a6ce3919 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Wed, 14 Nov 2012 21:54:13 -0500 Subject: Style cleanup --- engine/lib/access.php | 11 +++-------- engine/lib/elgglib.php | 18 +++++++++--------- engine/lib/entities.php | 2 +- engine/lib/extender.php | 3 ++- engine/lib/pagehandler.php | 1 + engine/lib/views.php | 1 + engine/lib/web_services.php | 35 +++++++++++++++++++++++------------ 7 files changed, 40 insertions(+), 31 deletions(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/access.php b/engine/lib/access.php index e8b3b0d52..3b2b7aeaa 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -88,11 +88,7 @@ function get_access_array($user_id = 0, $site_id = 0, $flush = false) { // @todo everything from the db is cached. // this cache might be redundant. But db cache is flushed on every db write. - static $access_array; - - if (!isset($access_array)) { - $access_array = array(); - } + static $access_array = array(); if ($user_id == 0) { $user_id = elgg_get_logged_in_user_guid(); @@ -476,7 +472,7 @@ function can_edit_access_collection($collection_id, $user_guid = null) { return false; } - $write_access = get_write_access_array($user->getGUID(), null, true); + $write_access = get_write_access_array($user->getGUID(), 0, true); // don't ignore access when checking users. if ($user_guid) { @@ -560,8 +556,6 @@ function create_access_collection($name, $owner_guid = 0, $site_guid = 0) { * @see remove_user_from_access_collection() */ function update_access_collection($collection_id, $members) { - global $CONFIG; - $acl = get_access_collection($collection_id); if (!$acl) { @@ -1018,6 +1012,7 @@ function elgg_override_permissions($hook, $type, $value, $params) { */ function access_test($hook, $type, $value, $params) { global $CONFIG; + $value[] = $CONFIG->path . 'engine/tests/api/access_collections.php'; return $value; } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 85610f0c2..974f38aad 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -671,7 +671,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority global $CONFIG; if (empty($event) || empty($object_type)) { - return FALSE; + return false; } if (!isset($CONFIG->events)) { @@ -685,7 +685,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority } if (!is_callable($callback, true)) { - return FALSE; + return false; } $priority = max((int) $priority, 0); @@ -695,7 +695,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority } $CONFIG->events[$event][$object_type][$priority] = $callback; ksort($CONFIG->events[$event][$object_type]); - return TRUE; + return true; } /** @@ -770,14 +770,14 @@ function elgg_trigger_event($event, $object_type, $object = null) { foreach ($events as $callback_list) { if (is_array($callback_list)) { foreach ($callback_list as $callback) { - if (is_callable($callback) && (call_user_func_array($callback, $args) === FALSE)) { - return FALSE; + if (is_callable($callback) && (call_user_func_array($callback, $args) === false)) { + return false; } } } } - return TRUE; + return true; } /** @@ -850,7 +850,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = global $CONFIG; if (empty($hook) || empty($type)) { - return FALSE; + return false; } if (!isset($CONFIG->hooks)) { @@ -864,7 +864,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = } if (!is_callable($callback, true)) { - return FALSE; + return false; } $priority = max((int) $priority, 0); @@ -874,7 +874,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = } $CONFIG->hooks[$hook][$type][$priority] = $callback; ksort($CONFIG->hooks[$hook][$type]); - return TRUE; + return true; } /** diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 5a5906b1f..a14160e14 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -1838,7 +1838,7 @@ function oddentity_to_elggentity(ODDEntity $element) { function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params) { $element = $params['element']; - $tmp = NULL; + $tmp = null; if ($element instanceof ODDEntity) { $tmp = oddentity_to_elggentity($element); diff --git a/engine/lib/extender.php b/engine/lib/extender.php index 636b711ea..538f601e1 100644 --- a/engine/lib/extender.php +++ b/engine/lib/extender.php @@ -141,9 +141,10 @@ function can_edit_extender($extender_id, $type, $user_guid = 0) { return false; } - if (!is_a($extender, "ElggExtender")) { + if (!($extender instanceof ElggExtender)) { return false; } + /* @var ElggExtender $extender */ // If the owner is the specified user, great! They can edit. if ($extender->getOwnerGUID() == $user->getGUID()) { diff --git a/engine/lib/pagehandler.php b/engine/lib/pagehandler.php index a53506812..0cf99b6fe 100644 --- a/engine/lib/pagehandler.php +++ b/engine/lib/pagehandler.php @@ -83,6 +83,7 @@ function page_handler($handler, $page) { */ function elgg_register_page_handler($handler, $function) { global $CONFIG; + if (!isset($CONFIG->pagehandler)) { $CONFIG->pagehandler = array(); } diff --git a/engine/lib/views.php b/engine/lib/views.php index e43c29cb2..8a0642c2b 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1403,6 +1403,7 @@ function elgg_view_access_collections($owner_guid) { */ function set_template_handler($function_name) { global $CONFIG; + if (is_callable($function_name)) { $CONFIG->template_handler = $function_name; return true; diff --git a/engine/lib/web_services.php b/engine/lib/web_services.php index 39fb0dc44..c8e4a13cc 100644 --- a/engine/lib/web_services.php +++ b/engine/lib/web_services.php @@ -1195,6 +1195,8 @@ $ERRORS = array(); * * @return void * @access private + * + * @throws Exception */ function _php_api_error_handler($errno, $errmsg, $filename, $linenum, $vars) { global $ERRORS; @@ -1300,6 +1302,7 @@ function service_handler($handler, $request) { */ function register_service_handler($handler, $function) { global $CONFIG; + if (!isset($CONFIG->servicehandler)) { $CONFIG->servicehandler = array(); } @@ -1318,11 +1321,13 @@ function register_service_handler($handler, $function) { * * @param string $handler web services type * - * @return 1.7.0 + * @return void + * @since 1.7.0 */ function unregister_service_handler($handler) { global $CONFIG; - if (isset($CONFIG->servicehandler) && isset($CONFIG->servicehandler[$handler])) { + + if (isset($CONFIG->servicehandler, $CONFIG->servicehandler[$handler])) { unset($CONFIG->servicehandler[$handler]); } } @@ -1332,6 +1337,8 @@ function unregister_service_handler($handler) { * * @return void * @access private + * + * @throws SecurityException|APIException */ function rest_handler() { global $CONFIG; @@ -1386,7 +1393,7 @@ function rest_handler() { /** * Unit tests for API * - * @param sting $hook unit_test + * @param string $hook unit_test * @param string $type system * @param mixed $value Array of tests * @param mixed $params Params @@ -1396,6 +1403,7 @@ function rest_handler() { */ function api_unit_test($hook, $type, $value, $params) { global $CONFIG; + $value[] = $CONFIG->path . 'engine/tests/services/api.php'; return $value; } @@ -1417,15 +1425,18 @@ function api_init() { elgg_echo("system.api.list"), "GET", false, false); // The authentication token api - expose_function("auth.gettoken", - "auth_gettoken", array( - 'username' => array ('type' => 'string'), - 'password' => array ('type' => 'string'), - ), - elgg_echo('auth.gettoken'), - 'POST', - false, - false); + expose_function( + "auth.gettoken", + "auth_gettoken", + array( + 'username' => array ('type' => 'string'), + 'password' => array ('type' => 'string'), + ), + elgg_echo('auth.gettoken'), + 'POST', + false, + false + ); } -- cgit v1.2.3 From 7ca70cd97dc3b7f728eb79dcacc7c2c972f129e0 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 26 Nov 2012 01:20:30 -0500 Subject: Fixes #4932: Allow plugins to be saved in entity cache --- engine/lib/entities.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a14160e14..0b28750d5 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -59,9 +59,9 @@ function invalidate_cache_for_entity($guid) { function cache_entity(ElggEntity $entity) { global $ENTITY_CACHE; - // Don't cache entities while access control is off, otherwise they could be + // Don't cache non-plugin entities while access control is off, otherwise they could be // exposed to users who shouldn't see them when control is re-enabled. - if (elgg_get_ignore_access()) { + if (!($entity instanceof ElggPlugin) && elgg_get_ignore_access()) { return; } -- cgit v1.2.3 From f09e927d13ba0beb41121691fe531cbf76a0f37b Mon Sep 17 00:00:00 2001 From: Paweł Sroka Date: Sun, 4 Nov 2012 11:25:42 +0100 Subject: Added caching of all subtypes with single query --- engine/lib/entities.php | 112 ++++++++++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 42 deletions(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a14160e14..3642856bf 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -17,7 +17,7 @@ global $ENTITY_CACHE; $ENTITY_CACHE = array(); /** - * Cache subtypes and related class names once loaded. + * Cache subtypes and related class names. * * @global array $SUBTYPE_CACHE * @access private @@ -156,18 +156,15 @@ function get_subtype_id($type, $subtype) { if ($subtype == "") { return FALSE; } + + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } - // @todo use the cache before hitting database - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes - where type='$type' and subtype='$subtype'"); - - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } - - $SUBTYPE_CACHE[$result->id] = $result; - return $result->id; + // use the cache before hitting database + $result = retrieve_cached_subtype($type, $subtype); + if ($result!==null) { + return $result->id; } return FALSE; @@ -192,21 +189,47 @@ function get_subtype_from_id($subtype_id) { return false; } + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->subtype; } - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id"); - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } + return false; +} - $SUBTYPE_CACHE[$subtype_id] = $result; - return $result->subtype; +/** + * Retrieve subtype from the cache. + * + * @return stdClass|null + * @access private + */ +function retrieve_cached_subtype($type, $subtype) { + global $SUBTYPE_CACHE; + + foreach ($SUBTYPE_CACHE as $id => $obj) { + if ($obj->type==$type && $obj->subtype==$subtype) { + return $obj; + } } + return null; +} - return false; +/** + * Fetch all suptypes from DB to local cache. + * @access private + */ +function populate_subtype_cache() { + global $CONFIG, $SUBTYPE_CACHE; + + $results = get_data("SELECT * from {$CONFIG->dbprefix}entity_subtypes"); + + $SUBTYPE_CACHE = array(); + foreach ($results as $result) { + $SUBTYPE_CACHE[$result->id] = $result; + } } /** @@ -230,16 +253,13 @@ function get_subtype_class($type, $subtype) { $type = sanitise_string($type); $subtype = sanitise_string($subtype); - // @todo use the cache before going to the database - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes - where type='$type' and subtype='$subtype'"); - - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } - - $SUBTYPE_CACHE[$result->id] = $result; + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + + // use the cache before going to the database + $result = retrieve_cached_subtype($type, $subtype); + if ($result!==null) { return $result->class; } @@ -265,20 +285,14 @@ function get_subtype_class_from_id($subtype_id) { return false; } + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->class; } - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id"); - - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } - $SUBTYPE_CACHE[$subtype_id] = $result; - return $result->class; - } - return NULL; } @@ -305,7 +319,7 @@ function get_subtype_class_from_id($subtype_id) { * @see get_entity() */ function add_subtype($type, $subtype, $class = "") { - global $CONFIG; + global $CONFIG, $SUBTYPE_CACHE; $type = sanitise_string($type); $subtype = sanitise_string($subtype); $class = sanitise_string($class); @@ -318,8 +332,18 @@ function add_subtype($type, $subtype, $class = "") { $id = get_subtype_id($type, $subtype); if ($id == 0) { - return insert_data("insert into {$CONFIG->dbprefix}entity_subtypes" + $result = insert_data("insert into {$CONFIG->dbprefix}entity_subtypes" . " (type, subtype, class) values ('$type','$subtype','$class')"); + + // add entry to cache + $obj = new stdClass(); + $obj->id = $result; + $obj->type = $type; + $obj->subtype = $subtype; + $obj->class = $class; + $SUBTYPE_CACHE[$obj->id] = $obj; + + return $result; } return $id; @@ -367,6 +391,10 @@ function update_subtype($type, $subtype, $class = '') { $type = sanitise_string($type); $subtype = sanitise_string($subtype); + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + $result = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes SET type = '$type', subtype = '$subtype', class = '$class' WHERE id = $id -- cgit v1.2.3 From 867d094d56df02ed93806f0c2c72890ecf762e41 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Wed, 28 Nov 2012 00:27:53 -0500 Subject: Subtype functions cleanup --- engine/lib/entities.php | 178 ++++++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 88 deletions(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 3642856bf..a1c1c2997 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -19,11 +19,11 @@ $ENTITY_CACHE = array(); /** * Cache subtypes and related class names. * - * @global array $SUBTYPE_CACHE + * @global array|null $SUBTYPE_CACHE array once populated from DB, initially null * @access private */ global $SUBTYPE_CACHE; -$SUBTYPE_CACHE = NULL; +$SUBTYPE_CACHE = null; /** * Invalidate this class's entry in the cache. @@ -87,8 +87,6 @@ function cache_entity(ElggEntity $entity) { function retrieve_cached_entity($guid) { global $ENTITY_CACHE; - $guid = (int)$guid; - if (isset($ENTITY_CACHE[$guid])) { if ($ENTITY_CACHE[$guid]->isFullyLoaded()) { return $ENTITY_CACHE[$guid]; @@ -148,26 +146,23 @@ function retrieve_cached_entity_row($guid) { * @access private */ function get_subtype_id($type, $subtype) { - global $CONFIG, $SUBTYPE_CACHE; + global $SUBTYPE_CACHE; - $type = sanitise_string($type); - $subtype = sanitise_string($subtype); - - if ($subtype == "") { - return FALSE; + if (!$subtype) { + return false; } - - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); + + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); } - // use the cache before hitting database - $result = retrieve_cached_subtype($type, $subtype); - if ($result!==null) { - return $result->id; + // use the cache before hitting database + $result = _elgg_retrieve_cached_subtype($type, $subtype); + if ($result !== null) { + return $result->id; } - return FALSE; + return false; } /** @@ -175,24 +170,22 @@ function get_subtype_id($type, $subtype) { * * @param int $subtype_id Subtype ID * - * @return string Subtype name + * @return string|false Subtype name, false if subtype not found * @link http://docs.elgg.org/DataModel/Entities/Subtypes * @see get_subtype_from_id() * @access private */ function get_subtype_from_id($subtype_id) { - global $CONFIG, $SUBTYPE_CACHE; - - $subtype_id = (int)$subtype_id; + global $SUBTYPE_CACHE; if (!$subtype_id) { return false; } - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } - + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } + if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->subtype; } @@ -200,35 +193,43 @@ function get_subtype_from_id($subtype_id) { return false; } -/** - * Retrieve subtype from the cache. - * - * @return stdClass|null - * @access private - */ -function retrieve_cached_subtype($type, $subtype) { - global $SUBTYPE_CACHE; - - foreach ($SUBTYPE_CACHE as $id => $obj) { - if ($obj->type==$type && $obj->subtype==$subtype) { +/** + * Retrieve subtype from the cache. + * + * @param string $type + * @param string $subtype + * @return stdClass|null + * + * @access private + */ +function _elgg_retrieve_cached_subtype($type, $subtype) { + global $SUBTYPE_CACHE; + + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } + + foreach ($SUBTYPE_CACHE as $obj) { + if ($obj->type === $type && $obj->subtype === $subtype) { return $obj; } } - return null; + return null; } /** * Fetch all suptypes from DB to local cache. + * * @access private */ -function populate_subtype_cache() { +function _elgg_populate_subtype_cache() { global $CONFIG, $SUBTYPE_CACHE; - $results = get_data("SELECT * from {$CONFIG->dbprefix}entity_subtypes"); + $results = get_data("SELECT * FROM {$CONFIG->dbprefix}entity_subtypes"); $SUBTYPE_CACHE = array(); - foreach ($results as $result) { - $SUBTYPE_CACHE[$result->id] = $result; + foreach ($results as $row) { + $SUBTYPE_CACHE[$row->id] = $row; } } @@ -248,22 +249,19 @@ function populate_subtype_cache() { * @access private */ function get_subtype_class($type, $subtype) { - global $CONFIG, $SUBTYPE_CACHE; + global $SUBTYPE_CACHE; - $type = sanitise_string($type); - $subtype = sanitise_string($subtype); - - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } // use the cache before going to the database - $result = retrieve_cached_subtype($type, $subtype); - if ($result!==null) { - return $result->class; + $obj = _elgg_retrieve_cached_subtype($type, $subtype); + if ($obj) { + return $obj->class; } - return NULL; + return null; } /** @@ -277,23 +275,21 @@ function get_subtype_class($type, $subtype) { * @access private */ function get_subtype_class_from_id($subtype_id) { - global $CONFIG, $SUBTYPE_CACHE; - - $subtype_id = (int)$subtype_id; + global $SUBTYPE_CACHE; if (!$subtype_id) { - return false; + return null; } - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->class; } - return NULL; + return null; } /** @@ -320,30 +316,31 @@ function get_subtype_class_from_id($subtype_id) { */ function add_subtype($type, $subtype, $class = "") { global $CONFIG, $SUBTYPE_CACHE; - $type = sanitise_string($type); - $subtype = sanitise_string($subtype); - $class = sanitise_string($class); - // Short circuit if no subtype is given - if ($subtype == "") { + if (!$subtype) { return 0; } $id = get_subtype_id($type, $subtype); - if ($id == 0) { - $result = insert_data("insert into {$CONFIG->dbprefix}entity_subtypes" - . " (type, subtype, class) values ('$type','$subtype','$class')"); + if (!$id) { + // In cache we store non-SQL-escaped strings because that's what's returned by query + $cache_obj = (object) array( + 'type' => $type, + 'subtype' => $subtype, + 'class' => $class, + ); + + $type = sanitise_string($type); + $subtype = sanitise_string($subtype); + $class = sanitise_string($class); + + $id = insert_data("INSERT INTO {$CONFIG->dbprefix}entity_subtypes" + . " (type, subtype, class) VALUES ('$type', '$subtype', '$class')"); // add entry to cache - $obj = new stdClass(); - $obj->id = $result; - $obj->type = $type; - $obj->subtype = $subtype; - $obj->class = $class; - $SUBTYPE_CACHE[$obj->id] = $obj; - - return $result; + $cache_obj->id = $id; + $SUBTYPE_CACHE[$id] = $cache_obj; } return $id; @@ -385,26 +382,31 @@ function remove_subtype($type, $subtype) { function update_subtype($type, $subtype, $class = '') { global $CONFIG, $SUBTYPE_CACHE; - if (!$id = get_subtype_id($type, $subtype)) { - return FALSE; + $id = get_subtype_id($type, $subtype); + if (!$id) { + return false; } + + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } + + $unescaped_class = $class; + $type = sanitise_string($type); $subtype = sanitise_string($subtype); - - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } + $class = sanitise_string($class); - $result = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes + $success = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes SET type = '$type', subtype = '$subtype', class = '$class' WHERE id = $id "); - if ($result && isset($SUBTYPE_CACHE[$id])) { - $SUBTYPE_CACHE[$id]->class = $class; + if ($success && isset($SUBTYPE_CACHE[$id])) { + $SUBTYPE_CACHE[$id]->class = $unescaped_class; } - return $result; + return $success; } /** @@ -1800,7 +1802,7 @@ function oddentity_to_elggentity(ODDEntity $element) { if (!$tmp) { // Construct new class with owner from session $classname = get_subtype_class($class, $subclass); - if ($classname != "") { + if ($classname) { if (class_exists($classname)) { $tmp = new $classname(); -- cgit v1.2.3 From 87b2da7e3d8f06ba541fea29d44c4c2e9630584d Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Wed, 28 Nov 2012 16:05:35 -0500 Subject: Fixes #4937: Metadata cache is purged when entity cache item removed --- engine/lib/entities.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'engine/lib/entities.php') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a1c1c2997..e9c96a596 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -68,7 +68,15 @@ function cache_entity(ElggEntity $entity) { // Don't store too many or we'll have memory problems // TODO(evan): Pick a less arbitrary limit if (count($ENTITY_CACHE) > 256) { - unset($ENTITY_CACHE[array_rand($ENTITY_CACHE)]); + $random_guid = array_rand($ENTITY_CACHE); + + unset($ENTITY_CACHE[$random_guid]); + + // Purge separate metadata cache. Original idea was to do in entity destructor, but that would + // have caused a bunch of unnecessary purges at every shutdown. Doing it this way we have no way + // to know that the expunged entity will be GCed (might be another reference living), but that's + // OK; the metadata will reload if necessary. + elgg_get_metadata_cache()->clear($random_guid); } $ENTITY_CACHE[$entity->guid] = $entity; -- cgit v1.2.3