1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 02:32:42 +01:00

Make AuthProvider, ExternalAccount, and ExternalAccountIdentifier all Destructible

Summary: Depends on D21014. Ref T13493. Make these objects all use destructible interfaces and destroy sub-objects appropriately.

Test Plan:
  - Used `bin/remove destroy --trace ...` to destroy a provider, a user, and an external account.
  - Observed destruction of sub-objects, including external account identifiers.

Maniphest Tasks: T13493

Differential Revision: https://secure.phabricator.com/D21015
This commit is contained in:
epriestley 2020-02-21 08:17:35 -08:00
parent 05eb16d6de
commit 0872051bfa
6 changed files with 82 additions and 9 deletions

View file

@ -8758,6 +8758,7 @@ phutil_register_library_map(array(
'PhabricatorAuthDAO', 'PhabricatorAuthDAO',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
), ),
'PhabricatorAuthProviderConfigController' => 'PhabricatorAuthProviderController', 'PhabricatorAuthProviderConfigController' => 'PhabricatorAuthProviderController',
'PhabricatorAuthProviderConfigEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorAuthProviderConfigEditor' => 'PhabricatorApplicationTransactionEditor',
@ -9765,10 +9766,12 @@ phutil_register_library_map(array(
'PhabricatorExternalAccount' => array( 'PhabricatorExternalAccount' => array(
'PhabricatorUserDAO', 'PhabricatorUserDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
), ),
'PhabricatorExternalAccountIdentifier' => array( 'PhabricatorExternalAccountIdentifier' => array(
'PhabricatorUserDAO', 'PhabricatorUserDAO',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
), ),
'PhabricatorExternalAccountIdentifierQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorExternalAccountIdentifierQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorExternalAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorExternalAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -4,7 +4,8 @@ final class PhabricatorAuthProviderConfig
extends PhabricatorAuthDAO extends PhabricatorAuthDAO
implements implements
PhabricatorApplicationTransactionInterface, PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface { PhabricatorPolicyInterface,
PhabricatorDestructibleInterface {
protected $providerClass; protected $providerClass;
protected $providerType; protected $providerType;
@ -140,4 +141,33 @@ final class PhabricatorAuthProviderConfig
return false; 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();
}
} }

View file

@ -1,7 +1,10 @@
<?php <?php
final class PhabricatorExternalAccount extends PhabricatorUserDAO final class PhabricatorExternalAccount
implements PhabricatorPolicyInterface { extends PhabricatorUserDAO
implements
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface {
protected $userPHID; protected $userPHID;
protected $accountType; protected $accountType;
@ -162,4 +165,24 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO
} }
} }
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$viewer = $engine->getViewer();
$identifiers = id(new PhabricatorExternalAccountIdentifierQuery())
->setViewer($viewer)
->withExternalAccountPHIDs(array($this->getPHID()))
->newIterator();
foreach ($identifiers as $identifier) {
$engine->destroyObject($identifier);
}
$this->delete();
}
} }

View file

@ -2,7 +2,9 @@
final class PhabricatorExternalAccountIdentifier final class PhabricatorExternalAccountIdentifier
extends PhabricatorUserDAO extends PhabricatorUserDAO
implements PhabricatorPolicyInterface { implements
PhabricatorPolicyInterface,
PhabricatorDestructibleInterface {
protected $externalAccountPHID; protected $externalAccountPHID;
protected $providerConfigPHID; protected $providerConfigPHID;
@ -64,4 +66,13 @@ final class PhabricatorExternalAccountIdentifier
return false; return false;
} }
/* -( PhabricatorDestructibleInterface )----------------------------------- */
public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) {
$this->delete();
}
} }

View file

@ -1110,19 +1110,21 @@ final class PhabricatorUser
public function destroyObjectPermanently( public function destroyObjectPermanently(
PhabricatorDestructionEngine $engine) { PhabricatorDestructionEngine $engine) {
$viewer = $engine->getViewer();
$this->openTransaction(); $this->openTransaction();
$this->delete(); $this->delete();
$externals = id(new PhabricatorExternalAccountQuery()) $externals = id(new PhabricatorExternalAccountQuery())
->setViewer($engine->getViewer()) ->setViewer($viewer)
->withUserPHIDs(array($this->getPHID())) ->withUserPHIDs(array($this->getPHID()))
->execute(); ->newIterator();
foreach ($externals as $external) { foreach ($externals as $external) {
$external->delete(); $engine->destroyObject($external);
} }
$prefs = id(new PhabricatorUserPreferencesQuery()) $prefs = id(new PhabricatorUserPreferencesQuery())
->setViewer($engine->getViewer()) ->setViewer($viewer)
->withUsers(array($this)) ->withUsers(array($this))
->execute(); ->execute();
foreach ($prefs as $pref) { foreach ($prefs as $pref) {
@ -1137,7 +1139,7 @@ final class PhabricatorUser
} }
$keys = id(new PhabricatorAuthSSHKeyQuery()) $keys = id(new PhabricatorAuthSSHKeyQuery())
->setViewer($engine->getViewer()) ->setViewer($viewer)
->withObjectPHIDs(array($this->getPHID())) ->withObjectPHIDs(array($this->getPHID()))
->execute(); ->execute();
foreach ($keys as $key) { foreach ($keys as $key) {

View file

@ -359,6 +359,10 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
return $results; return $results;
} }
final public function newIterator() {
return new PhabricatorQueryIterator($this);
}
final public function executeWithCursorPager(AphrontCursorPagerView $pager) { final public function executeWithCursorPager(AphrontCursorPagerView $pager) {
$limit = $pager->getPageSize(); $limit = $pager->getPageSize();