From 82f85ba30f16ec6cfb8abb86a94af08f84fdf825 Mon Sep 17 00:00:00 2001 From: brettp Date: Mon, 29 Jun 2009 21:18:52 +0000 Subject: Closes #502: Removing unfriended users from access lists upon unfriending. git-svn-id: https://code.elgg.org/elgg/trunk@3362 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/users.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'engine/lib/users.php') diff --git a/engine/lib/users.php b/engine/lib/users.php index b271d4b4f..5f562845c 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -557,9 +557,28 @@ * @return true|false Depending on success */ function user_remove_friend($user_guid, $friend_guid) { + global $CONFIG; + $user_guid = (int) $user_guid; $friend_guid = (int) $friend_guid; - return remove_entity_relationship($user_guid, "friend", $friend_guid); + if (!remove_entity_relationship($user_guid, "friend", $friend_guid)){ + return false; + } + + // perform cleanup for access lists. + $collections = get_user_access_collections($user_guid); + $in_arr = array(); + foreach ($collections as $collection) { + $in_arr[] = $collection->id; + } + $query = "DELETE FROM `{$CONFIG->dbprefix}access_collection_membership` + WHERE `user_guid` = '$friend_guid' + AND `access_collection_id` IN(" . implode($in_arr, ',') . ")"; + delete_data($query); + + // delete_data() might return nothing if no rows were affected. + // the users has been removed already, so we safely return true. + return true; } /** -- cgit v1.2.3