From 4655b7e4da8eb09ccd2f708cbc66f47e1679fdec Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Tue, 13 Jan 2015 16:17:38 -0800 Subject: [PATCH] OAuthServer - implement destructible interface on oauth server client objects Summary: Fixes T6955. Test Plan: made an oauth app. made a test authorization. ran bin/remove destroy and there were no errors. verified oauth app and test authorization were both gone. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T6955 Differential Revision: https://secure.phabricator.com/D11378 --- .../storage/PhabricatorOAuthServerClient.php | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/applications/oauthserver/storage/PhabricatorOAuthServerClient.php b/src/applications/oauthserver/storage/PhabricatorOAuthServerClient.php index 0d4598385c..ea3637d788 100644 --- a/src/applications/oauthserver/storage/PhabricatorOAuthServerClient.php +++ b/src/applications/oauthserver/storage/PhabricatorOAuthServerClient.php @@ -2,7 +2,9 @@ final class PhabricatorOAuthServerClient extends PhabricatorOAuthServerDAO - implements PhabricatorPolicyInterface { + implements + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $secret; protected $name; @@ -89,4 +91,33 @@ final class PhabricatorOAuthServerClient return null; } +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $this->openTransaction(); + $this->delete(); + + $authorizations = id(new PhabricatorOAuthClientAuthorization()) + ->loadAllWhere('clientPHID = %s', $this->getPHID()); + foreach ($authorizations as $authorization) { + $authorization->delete(); + } + + $tokens = id(new PhabricatorOAuthServerAccessToken()) + ->loadAllWhere('clientPHID = %s', $this->getPHID()); + foreach ($tokens as $token) { + $token->delete(); + } + + $codes = id(new PhabricatorOAuthServerAuthorizationCode()) + ->loadAllWhere('clientPHID = %s', $this->getPHID()); + foreach ($codes as $code) { + $code->delete(); + } + + $this->saveTransaction(); + + } }