diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-21 16:25:16 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-21 16:25:16 +0000 |
commit | 1bdab3286dba42516ea49ba047943c028bbc250a (patch) | |
tree | 91206e59bc845b3b3f824db919aff7fa59a90f43 /engine | |
parent | 2725ae29f0ac3716a552717fe0965daff312dbd0 (diff) | |
download | elgg-1bdab3286dba42516ea49ba047943c028bbc250a.tar.gz elgg-1bdab3286dba42516ea49ba047943c028bbc250a.tar.bz2 |
Entities now clear all associated relationships on delete
git-svn-id: https://code.elgg.org/elgg/trunk@672 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/entities.php | 14 | ||||
-rw-r--r-- | engine/lib/relationships.php | 16 |
2 files changed, 24 insertions, 6 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 850da0008..34b73b580 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -174,6 +174,17 @@ { return clear_metadata($this->getGUID()); } +
+ /**
+ * Remove all entities associated with this entity
+ *
+ * @return true
+ */
+ public function clearRelationships() {
+ remove_entity_relationships($this->getGUID());
+ remove_entity_relationships($this->getGUID(),"",true);
+ return true;
+ }
/** * Adds an annotation to an entity. By default, the type is detected automatically; however, @@ -917,7 +928,8 @@ if (trigger_event('delete',$entity->type,$entity)) {
if ($entity->canEdit()) {
$entity->clearMetadata();
- $entity->clearAnnotations(); + $entity->clearAnnotations();
+ $entity->clearRelationships(); $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
return $res;
}
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 28c7ba604..519f28566 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -346,21 +346,27 @@ * Removes all arbitrary relationships originating from a particular entity
*
* @param int $guid_one The GUID of the entity
- * @param string $relationship The name of the relationship
+ * @param string $relationship The name of the relationship (optionally)
* @param true|false $inverse Whether we're deleting inverse relationships (default false)
* @return true|false Depending on success
*/
- function remove_entity_relationships($guid_one, $relationship, $inverse = false) {
+ function remove_entity_relationships($guid_one, $relationship = "", $inverse = false) {
global $CONFIG;
$guid_one = (int) $guid_one;
- $relationship = sanitise_string($relationship);
+
+ if (!empty($relationship)) {
+ $relationship = sanitise_string($relationship);
+ $where = "and relationship='$relationship'";
+ } else {
+ $where = "";
+ }
if (!$inverse) {
- return delete_data("DELETE from {$CONFIG->dbprefix}entity_relationships where guid_one=$guid_one and relationship='$relationship'");
+ return delete_data("DELETE from {$CONFIG->dbprefix}entity_relationships where guid_one=$guid_one {$where}");
} else {
- return delete_data("DELETE from {$CONFIG->dbprefix}entity_relationships where guid_two=$guid_one and relationship='$relationship'");
+ return delete_data("DELETE from {$CONFIG->dbprefix}entity_relationships where guid_two=$guid_one {$where}");
}
} |