From e434049a59a70668cc5662785cd152514d795a32 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 9 Feb 2009 15:47:37 +0000 Subject: Added a new filter to delete relationship functions git-svn-id: https://code.elgg.org/elgg/trunk@2691 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/relationships.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'engine') diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 4bc2ad2dd..46b0e7c46 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -426,10 +426,11 @@ * * @param int $guid_one The GUID of the entity * @param string $relationship The name of the relationship (optionally) - * @param true|false $inverse Whether we're deleting inverse relationships (default false) + * @param true|false $inverse Whether we're deleting inverse relationships (default false) + * @param string $type The type of entity to limit this relationship delete to (defaults to all) * @return true|false Depending on success */ - function remove_entity_relationships($guid_one, $relationship = "", $inverse = false) { + function remove_entity_relationships($guid_one, $relationship = "", $inverse = false, $type = '') { global $CONFIG; @@ -437,15 +438,30 @@ if (!empty($relationship)) { $relationship = sanitise_string($relationship); - $where = "and relationship='$relationship'"; + $where = "and er.relationship='$relationship'"; } else { $where = ""; + } + + if (!empty($type)) { + $type = sanitise_string($type); + if (!$inverse) { + $join = " join {$CONFIG->dbprefix}entities e on e.guid = er.guid_two "; + } else { + $join = " join {$CONFIG->dbprefix}entities e on e.guid = er.guid_one "; + $where .= " and "; + } + $where .= " and e.type = '{$type}' "; + } else { + $join = ""; } - if (!$inverse) { - 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 {$where}"); + if (!$inverse) { + $sql = "DELETE er from {$CONFIG->dbprefix}entity_relationships as er {$join} where guid_one={$guid_one} {$where}"; + return delete_data($sql); + } else { + $sql = "DELETE er from {$CONFIG->dbprefix}entity_relationships as er {$join} where guid_two={$guid_one} {$where}"; + return delete_data($sql); } } -- cgit v1.2.3