@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+82 -9
+3
src/__phutil_library_map__.php
··· 8758 8758 'PhabricatorAuthDAO', 8759 8759 'PhabricatorApplicationTransactionInterface', 8760 8760 'PhabricatorPolicyInterface', 8761 + 'PhabricatorDestructibleInterface', 8761 8762 ), 8762 8763 'PhabricatorAuthProviderConfigController' => 'PhabricatorAuthProviderController', 8763 8764 'PhabricatorAuthProviderConfigEditor' => 'PhabricatorApplicationTransactionEditor', ··· 9765 9766 'PhabricatorExternalAccount' => array( 9766 9767 'PhabricatorUserDAO', 9767 9768 'PhabricatorPolicyInterface', 9769 + 'PhabricatorDestructibleInterface', 9768 9770 ), 9769 9771 'PhabricatorExternalAccountIdentifier' => array( 9770 9772 'PhabricatorUserDAO', 9771 9773 'PhabricatorPolicyInterface', 9774 + 'PhabricatorDestructibleInterface', 9772 9775 ), 9773 9776 'PhabricatorExternalAccountIdentifierQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 9774 9777 'PhabricatorExternalAccountQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+31 -1
src/applications/auth/storage/PhabricatorAuthProviderConfig.php
··· 4 4 extends PhabricatorAuthDAO 5 5 implements 6 6 PhabricatorApplicationTransactionInterface, 7 - PhabricatorPolicyInterface { 7 + PhabricatorPolicyInterface, 8 + PhabricatorDestructibleInterface { 8 9 9 10 protected $providerClass; 10 11 protected $providerType; ··· 138 139 139 140 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 140 141 return false; 142 + } 143 + 144 + 145 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 146 + 147 + 148 + public function destroyObjectPermanently( 149 + PhabricatorDestructionEngine $engine) { 150 + 151 + $viewer = $engine->getViewer(); 152 + $config_phid = $this->getPHID(); 153 + 154 + $accounts = id(new PhabricatorExternalAccountQuery()) 155 + ->setViewer($viewer) 156 + ->withProviderConfigPHIDs(array($config_phid)) 157 + ->newIterator(); 158 + foreach ($accounts as $account) { 159 + $engine->destroyObject($account); 160 + } 161 + 162 + $identifiers = id(new PhabricatorExternalAccountIdentifierQuery()) 163 + ->setViewer($viewer) 164 + ->withProviderConfigPHIDs(array($config_phid)) 165 + ->newIterator(); 166 + foreach ($identifiers as $identifier) { 167 + $engine->destroyObject($identifier); 168 + } 169 + 170 + $this->delete(); 141 171 } 142 172 143 173 }
+25 -2
src/applications/people/storage/PhabricatorExternalAccount.php
··· 1 1 <?php 2 2 3 - final class PhabricatorExternalAccount extends PhabricatorUserDAO 4 - implements PhabricatorPolicyInterface { 3 + final class PhabricatorExternalAccount 4 + extends PhabricatorUserDAO 5 + implements 6 + PhabricatorPolicyInterface, 7 + PhabricatorDestructibleInterface { 5 8 6 9 protected $userPHID; 7 10 protected $accountType; ··· 160 163 return pht( 161 164 'External accounts can only be edited by the account owner.'); 162 165 } 166 + } 167 + 168 + 169 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 170 + 171 + 172 + public function destroyObjectPermanently( 173 + PhabricatorDestructionEngine $engine) { 174 + 175 + $viewer = $engine->getViewer(); 176 + 177 + $identifiers = id(new PhabricatorExternalAccountIdentifierQuery()) 178 + ->setViewer($viewer) 179 + ->withExternalAccountPHIDs(array($this->getPHID())) 180 + ->newIterator(); 181 + foreach ($identifiers as $identifier) { 182 + $engine->destroyObject($identifier); 183 + } 184 + 185 + $this->delete(); 163 186 } 164 187 165 188 }
+12 -1
src/applications/people/storage/PhabricatorExternalAccountIdentifier.php
··· 2 2 3 3 final class PhabricatorExternalAccountIdentifier 4 4 extends PhabricatorUserDAO 5 - implements PhabricatorPolicyInterface { 5 + implements 6 + PhabricatorPolicyInterface, 7 + PhabricatorDestructibleInterface { 6 8 7 9 protected $externalAccountPHID; 8 10 protected $providerConfigPHID; ··· 62 64 63 65 public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { 64 66 return false; 67 + } 68 + 69 + 70 + /* -( PhabricatorDestructibleInterface )----------------------------------- */ 71 + 72 + 73 + public function destroyObjectPermanently( 74 + PhabricatorDestructionEngine $engine) { 75 + $this->delete(); 65 76 } 66 77 67 78 }
+7 -5
src/applications/people/storage/PhabricatorUser.php
··· 1110 1110 public function destroyObjectPermanently( 1111 1111 PhabricatorDestructionEngine $engine) { 1112 1112 1113 + $viewer = $engine->getViewer(); 1114 + 1113 1115 $this->openTransaction(); 1114 1116 $this->delete(); 1115 1117 1116 1118 $externals = id(new PhabricatorExternalAccountQuery()) 1117 - ->setViewer($engine->getViewer()) 1119 + ->setViewer($viewer) 1118 1120 ->withUserPHIDs(array($this->getPHID())) 1119 - ->execute(); 1121 + ->newIterator(); 1120 1122 foreach ($externals as $external) { 1121 - $external->delete(); 1123 + $engine->destroyObject($external); 1122 1124 } 1123 1125 1124 1126 $prefs = id(new PhabricatorUserPreferencesQuery()) 1125 - ->setViewer($engine->getViewer()) 1127 + ->setViewer($viewer) 1126 1128 ->withUsers(array($this)) 1127 1129 ->execute(); 1128 1130 foreach ($prefs as $pref) { ··· 1137 1139 } 1138 1140 1139 1141 $keys = id(new PhabricatorAuthSSHKeyQuery()) 1140 - ->setViewer($engine->getViewer()) 1142 + ->setViewer($viewer) 1141 1143 ->withObjectPHIDs(array($this->getPHID())) 1142 1144 ->execute(); 1143 1145 foreach ($keys as $key) {
+4
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 359 359 return $results; 360 360 } 361 361 362 + final public function newIterator() { 363 + return new PhabricatorQueryIterator($this); 364 + } 365 + 362 366 final public function executeWithCursorPager(AphrontCursorPagerView $pager) { 363 367 $limit = $pager->getPageSize(); 364 368