aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-12-08 12:46:53 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-12-08 12:46:53 +0000
commit1b2a453410488addb98d8c7f769bfd29720093df (patch)
tree4085c5278bd3396b59fc9f58e486323e2d2f92b7 /engine
parentad8408a69a1910ae8759dd92d7735ab2ea99cda4 (diff)
downloadelgg-1b2a453410488addb98d8c7f769bfd29720093df.tar.gz
elgg-1b2a453410488addb98d8c7f769bfd29720093df.tar.bz2
fixes #1305 - user and entity cache now cleared on delete
git-svn-id: http://code.elgg.org/elgg/trunk@3743 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/entities.php7
-rw-r--r--engine/lib/users.php10
-rw-r--r--engine/tests/objects/users.php14
3 files changed, 30 insertions, 1 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index ef99f764a..f86299c6e 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -2399,13 +2399,18 @@ function enable_entity($guid) {
* Note: this bypasses ownership of sub items.
*/
function delete_entity($guid, $recursive = true) {
- global $CONFIG;
+ global $CONFIG, $ENTITY_CACHE;
$guid = (int)$guid;
if ($entity = get_entity($guid)) {
if (trigger_elgg_event('delete', $entity->type, $entity)) {
if ($entity->canEdit()) {
+ // delete cache
+ if (isset($ENTITY_CACHE[$guid])) {
+ invalidate_cache_for_entity($guid);
+ }
+
// Delete contained owned and otherwise releated objects (depth first)
if ($recursive) {
// Temporary token overriding access controls TODO: Do this better.
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 5892035a6..0857c520a 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -153,6 +153,16 @@ class ElggUser extends ElggEntity
* @return bool
*/
public function delete() {
+ global $USERNAME_TO_GUID_MAP_CACHE, $CODE_TO_GUID_MAP_CACHE;
+
+ // clear cache
+ if (isset($USERNAME_TO_GUID_MAP_CACHE[$this->username])) {
+ unset($USERNAME_TO_GUID_MAP_CACHE[$this->username]);
+ }
+ if (isset($CODE_TO_GUID_MAP_CACHE[$this->code])) {
+ unset($CODE_TO_GUID_MAP_CACHE[$this->code]);
+ }
+
// Delete owned data
clear_annotations_by_owner($this->guid);
clear_metadata_by_owner($this->guid);
diff --git a/engine/tests/objects/users.php b/engine/tests/objects/users.php
index ace683a82..c1403af1a 100644
--- a/engine/tests/objects/users.php
+++ b/engine/tests/objects/users.php
@@ -162,6 +162,20 @@ class ElggCoreUserTest extends ElggCoreUnitTest {
$this->assertFalse($this->fetchUser($guid));
}
+ public function testElggUserNameCache() {
+ // Trac #1305
+
+ // very unlikely a user would have this username
+ $name = (string)time();
+ $this->user->username = $name;
+
+ $guid = $this->user->save();
+
+ $user = get_user_by_username($name);
+ $user->delete();
+ $user = get_user_by_username($name);
+ $this->assertFalse($user);
+ }
protected function fetchUser($guid) {
global $CONFIG;