diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -8758,6 +8758,7 @@ 'PhabricatorAuthDAO', 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'PhabricatorAuthProviderConfigController' => 'PhabricatorAuthProviderController', 'PhabricatorAuthProviderConfigEditor' => 'PhabricatorApplicationTransactionEditor', @@ -9765,10 +9766,12 @@ 'PhabricatorExternalAccount' => array( 'PhabricatorUserDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'PhabricatorExternalAccountIdentifier' => array( 'PhabricatorUserDAO', 'PhabricatorPolicyInterface', + 'PhabricatorDestructibleInterface', ), 'PhabricatorExternalAccountIdentifierQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorExternalAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', diff --git a/src/applications/auth/storage/PhabricatorAuthProviderConfig.php b/src/applications/auth/storage/PhabricatorAuthProviderConfig.php --- a/src/applications/auth/storage/PhabricatorAuthProviderConfig.php +++ b/src/applications/auth/storage/PhabricatorAuthProviderConfig.php @@ -4,7 +4,8 @@ extends PhabricatorAuthDAO implements PhabricatorApplicationTransactionInterface, - PhabricatorPolicyInterface { + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $providerClass; protected $providerType; @@ -140,4 +141,33 @@ return false; } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + + $viewer = $engine->getViewer(); + $config_phid = $this->getPHID(); + + $accounts = id(new PhabricatorExternalAccountQuery()) + ->setViewer($viewer) + ->withProviderConfigPHIDs(array($config_phid)) + ->newIterator(); + foreach ($accounts as $account) { + $engine->destroyObject($account); + } + + $identifiers = id(new PhabricatorExternalAccountIdentifierQuery()) + ->setViewer($viewer) + ->withProviderConfigPHIDs(array($config_phid)) + ->newIterator(); + foreach ($identifiers as $identifier) { + $engine->destroyObject($identifier); + } + + $this->delete(); + } + } diff --git a/src/applications/people/storage/PhabricatorExternalAccount.php b/src/applications/people/storage/PhabricatorExternalAccount.php --- a/src/applications/people/storage/PhabricatorExternalAccount.php +++ b/src/applications/people/storage/PhabricatorExternalAccount.php @@ -1,7 +1,10 @@ getViewer(); + + $identifiers = id(new PhabricatorExternalAccountIdentifierQuery()) + ->setViewer($viewer) + ->withExternalAccountPHIDs(array($this->getPHID())) + ->newIterator(); + foreach ($identifiers as $identifier) { + $engine->destroyObject($identifier); + } + + $this->delete(); + } + } diff --git a/src/applications/people/storage/PhabricatorExternalAccountIdentifier.php b/src/applications/people/storage/PhabricatorExternalAccountIdentifier.php --- a/src/applications/people/storage/PhabricatorExternalAccountIdentifier.php +++ b/src/applications/people/storage/PhabricatorExternalAccountIdentifier.php @@ -2,7 +2,9 @@ final class PhabricatorExternalAccountIdentifier extends PhabricatorUserDAO - implements PhabricatorPolicyInterface { + implements + PhabricatorPolicyInterface, + PhabricatorDestructibleInterface { protected $externalAccountPHID; protected $providerConfigPHID; @@ -64,4 +66,13 @@ return false; } + +/* -( PhabricatorDestructibleInterface )----------------------------------- */ + + + public function destroyObjectPermanently( + PhabricatorDestructionEngine $engine) { + $this->delete(); + } + } diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -1110,19 +1110,21 @@ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { + $viewer = $engine->getViewer(); + $this->openTransaction(); $this->delete(); $externals = id(new PhabricatorExternalAccountQuery()) - ->setViewer($engine->getViewer()) + ->setViewer($viewer) ->withUserPHIDs(array($this->getPHID())) - ->execute(); + ->newIterator(); foreach ($externals as $external) { - $external->delete(); + $engine->destroyObject($external); } $prefs = id(new PhabricatorUserPreferencesQuery()) - ->setViewer($engine->getViewer()) + ->setViewer($viewer) ->withUsers(array($this)) ->execute(); foreach ($prefs as $pref) { @@ -1137,7 +1139,7 @@ } $keys = id(new PhabricatorAuthSSHKeyQuery()) - ->setViewer($engine->getViewer()) + ->setViewer($viewer) ->withObjectPHIDs(array($this->getPHID())) ->execute(); foreach ($keys as $key) { diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php --- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php @@ -359,6 +359,10 @@ return $results; } + final public function newIterator() { + return new PhabricatorQueryIterator($this); + } + final public function executeWithCursorPager(AphrontCursorPagerView $pager) { $limit = $pager->getPageSize();