From 8b5fd806d6871aaeb179376328a8af215ed44f88 Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 22 Apr 2009 15:20:13 +0000 Subject: Closes #957: Annotations and metadata owned by a deleted user are now also deleted. git-svn-id: https://code.elgg.org/elgg/trunk@3227 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 21 +++++++++++++++++++++ engine/lib/entities.php | 3 ++- engine/lib/metadata.php | 21 +++++++++++++++++++++ engine/lib/users.php | 15 +++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) (limited to 'engine') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 8ad918180..dd647444a 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -820,6 +820,27 @@ } } + } + + /** + * Clear all annotations belonging to a given owner_guid + * + * @param int $owner_guid The owner + */ + function clear_annotations_by_owner($owner_guid) + { + $owner_guid = (int)$owner_guid; + + $annotations = get_data("SELECT id from {$CONFIG->dbprefix}annotations WHERE owner_guid=$owner_guid"); + $deleted = 0; + + foreach ($annotations as $id) + { + if (delete_annotation($id)) // Is this the best way? + $deleted++; + } + + return $deleted; } /** diff --git a/engine/lib/entities.php b/engine/lib/entities.php index ff4487570..fc572e29a 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -1843,7 +1843,7 @@ $entity->clearAnnotations(); $entity->clearRelationships(); remove_from_river_by_subject($guid); - remove_from_river_by_object($guid); + remove_from_river_by_object($guid); $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}"); if ($res) { @@ -2777,6 +2777,7 @@ // Allow a permission override for recursive entity deletion // TODO: Can this be done better? register_plugin_hook('permissions_check','all','recursive_delete_permissions_check'); + register_plugin_hook('permissions_check:metadata','all','recursive_delete_permissions_check'); register_plugin_hook('gc','system','entities_gc'); } diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 3decc1461..57987107c 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -730,6 +730,27 @@ return delete_data("DELETE from {$CONFIG->dbprefix}metadata where entity_guid={$entity_guid}"); } return false; + } + + /** + * Clear all annotations belonging to a given owner_guid + * + * @param int $owner_guid The owner + */ + function clear_metadata_by_owner($owner_guid) + { + $owner_guid = (int)$owner_guid; + + $metas = get_data("SELECT id from {$CONFIG->dbprefix}metadata WHERE owner_guid=$owner_guid"); + $deleted = 0; + + foreach ($metas as $id) + { + if (delete_metadata($id)) // Is this the best way? + $deleted++; + } + + return $deleted; } /** diff --git a/engine/lib/users.php b/engine/lib/users.php index e45223e54..5a9234dc6 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -143,6 +143,21 @@ // Now save specific stuff return create_user_entity($this->get('guid'), $this->get('name'), $this->get('username'), $this->get('password'), $this->get('salt'), $this->get('email'), $this->get('language'), $this->get('code')); + } + + /** + * User specific override of the entity delete method. + * + * @return bool + */ + public function delete() + { + // Delete owned data + clear_annotations_by_owner($this->owner_guid); + clear_metadata_by_owner($this->owner_guid); + + // Delete entity + return parent::delete(); } /** -- cgit v1.2.3