From d69a7360ea172d8213df842493de7a320a6afa17 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 14 Nov 2019 10:20:01 -0800 Subject: [PATCH] Use DestructionEngine to destroy UserEmail objects Summary: Ref T13444. Prepare to hook identity updates when user email addreses are destroyed. Test Plan: - Destroyed a user with `bin/remove destroy ... --trace`, saw email deleted. - Destroyed an email from the web UI, saw email deleted. Maniphest Tasks: T13444 Differential Revision: https://secure.phabricator.com/D20912 --- src/__phutil_library_map__.php | 5 ++++- .../people/editor/PhabricatorUserEditor.php | 3 ++- src/applications/people/storage/PhabricatorUser.php | 2 +- .../people/storage/PhabricatorUserEmail.php | 13 ++++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9d85964435..ffb824f177 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -11681,7 +11681,10 @@ phutil_register_library_map(array( 'PhabricatorUserEditEngine' => 'PhabricatorEditEngine', 'PhabricatorUserEditor' => 'PhabricatorEditor', 'PhabricatorUserEditorTestCase' => 'PhabricatorTestCase', - 'PhabricatorUserEmail' => 'PhabricatorUserDAO', + 'PhabricatorUserEmail' => array( + 'PhabricatorUserDAO', + 'PhabricatorDestructibleInterface', + ), 'PhabricatorUserEmailTestCase' => 'PhabricatorTestCase', 'PhabricatorUserEmpowerTransaction' => 'PhabricatorUserTransactionType', 'PhabricatorUserFerretEngine' => 'PhabricatorFerretEngine', diff --git a/src/applications/people/editor/PhabricatorUserEditor.php b/src/applications/people/editor/PhabricatorUserEditor.php index 81f427ada8..34bc1ae03f 100644 --- a/src/applications/people/editor/PhabricatorUserEditor.php +++ b/src/applications/people/editor/PhabricatorUserEditor.php @@ -241,7 +241,8 @@ final class PhabricatorUserEditor extends PhabricatorEditor { throw new Exception(pht('Email not owned by user!')); } - $email->delete(); + id(new PhabricatorDestructionEngine()) + ->destroyObject($email); $log = PhabricatorUserLog::initializeNewLog( $actor, diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php index cce4ffa58a..a62aab4fc3 100644 --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -1148,7 +1148,7 @@ final class PhabricatorUser 'userPHID = %s', $this->getPHID()); foreach ($emails as $email) { - $email->delete(); + $engine->destroyObject($email); } $sessions = id(new PhabricatorAuthSession())->loadAllWhere( diff --git a/src/applications/people/storage/PhabricatorUserEmail.php b/src/applications/people/storage/PhabricatorUserEmail.php index 572c7d6e8b..f626e8f133 100644 --- a/src/applications/people/storage/PhabricatorUserEmail.php +++ b/src/applications/people/storage/PhabricatorUserEmail.php @@ -4,7 +4,9 @@ * @task restrictions Domain Restrictions * @task email Email About Email */ -final class PhabricatorUserEmail extends PhabricatorUserDAO { +final class PhabricatorUserEmail + extends PhabricatorUserDAO + implements PhabricatorDestructibleInterface { protected $userPHID; protected $address; @@ -271,4 +273,13 @@ final class PhabricatorUserEmail extends PhabricatorUserDAO { return $this; } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + $this->delete(); + } + }