/** * Remove a relationship between two users and clear caches afterwards. * * @param $user1 Integer: user ID of the first user * @param $user2 Integer: user ID of the second user */ public function removeRelationshipByUserID($user1, $user2) { global $wgUser, $wgMemc; if ($user1 != $wgUser->getID() && $user2 != $wgUser->getID()) { return false; // only logged in user should be able to delete } // must delete record for each user involved in relationship $dbw = wfGetDB(DB_MASTER); $dbw->delete('user_relationship', array('r_user_id' => $user1, 'r_user_id_relation' => $user2), __METHOD__); $dbw->delete('user_relationship', array('r_user_id' => $user2, 'r_user_id_relation' => $user1), __METHOD__); $wgMemc->delete(wfForeignMemcKey('huiji', '', 'relationship', 'profile', "{$user1}-1")); $wgMemc->delete(wfForeignMemcKey('huiji', '', 'relationship', 'profile', "{$user2}-1")); $wgMemc->delete(wfForeignMemcKey('huiji', '', 'relationship', 'profile', "{$user1}-2")); $wgMemc->delete(wfForeignMemcKey('huiji', '', 'relationship', 'profile', "{$user2}-2")); // RelationshipRemovedByUserID hook wfRunHooks('RelationshipRemovedByUserID', array($user1, $user2)); // Update social statistics for both users $stats = new UserStatsTrack($user1, ''); $stats->updateRelationshipCount(1); $stats->updateRelationshipCount(2); $stats->clearCache(); $stats = new UserStatsTrack($user2, ''); $stats->updateRelationshipCount(1); $stats->updateRelationshipCount(2); $stats->clearCache(); }