aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-09 15:47:37 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-02-09 15:47:37 +0000
commite434049a59a70668cc5662785cd152514d795a32 (patch)
tree6737c62f6160aed96f2444e32497b01a83a4b800 /engine/lib
parent002bf98873d8752c120037ff94c72ab8210eedea (diff)
downloadelgg-e434049a59a70668cc5662785cd152514d795a32.tar.gz
elgg-e434049a59a70668cc5662785cd152514d795a32.tar.bz2
Added a new filter to delete relationship functions
git-svn-id: https://code.elgg.org/elgg/trunk@2691 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/relationships.php30
1 files changed, 23 insertions, 7 deletions
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);
}
}