From 0b87e462cd706d887e33bd2ce3cc3194f7a79f3b Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Thu, 4 Jun 2015 07:18:33 +1000 Subject: [PATCH] Remove flags and tokens upon object destruction Summary: When destroying an object, also remove all associated flags and tokens. Test Plan: Awarded a Maniphest task with a token and flagged it as well. Destroyed it with `./bin/remove destroy` and saw flag and token removed from the database. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D13112 --- .../engine/PhabricatorDestructionEngine.php | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/applications/system/engine/PhabricatorDestructionEngine.php b/src/applications/system/engine/PhabricatorDestructionEngine.php index eddc2f73fb..fd7ba7c30a 100644 --- a/src/applications/system/engine/PhabricatorDestructionEngine.php +++ b/src/applications/system/engine/PhabricatorDestructionEngine.php @@ -68,8 +68,30 @@ final class PhabricatorDestructionEngine extends Phobject { } // TODO: Remove stuff from search indexes? - // TODO: PhabricatorFlaggableInterface - // TODO: PhabricatorTokenReceiverInterface + + if ($object instanceof PhabricatorFlaggableInterface) { + $flags = id(new PhabricatorFlag())->loadAllWhere( + 'objectPHID = %s', $object_phid); + + foreach ($flags as $flag) { + $flag->delete(); + } + } + + $flags = id(new PhabricatorFlag())->loadAllWhere( + 'ownerPHID = %s', $object_phid); + foreach ($flags as $flag) { + $flag->delete(); + } + + if ($object instanceof PhabricatorTokenReceiverInterface) { + $tokens = id(new PhabricatorTokenGiven())->loadAllWhere( + 'objectPHID = %s', $object_phid); + + foreach ($tokens as $token) { + $token->delete(); + } + } } private function destroyEdges($src_phid) { @@ -116,7 +138,7 @@ final class PhabricatorDestructionEngine extends Phobject { } private function destroyNotifications($object_phid) { - $table = id(new PhabricatorFeedStoryNotification()); + $table = new PhabricatorFeedStoryNotification(); $conn_w = $table->establishConnection('w'); queryfx(