@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Prepare DestructionEngine to be modularized

Summary:
Ref T9979. The general shape of "engine" code feels pretty good, and I plan to move indexing to be more in line with other modern engines, with the ultimate goal of supporting subprojects (T10010) and several intermediate goals.

Before moving indexing, clean up Destruction, since some of the new indexes will need destruction hooks and destruction currently has a lot of `instanceof` stuff that should be easy to fix by applying more modern approaches.

Test Plan:
- Used `bin/remove destroy` to destory an Almanac device.
- Verified that properties for the device were destroyed.
- Viewed module panel in UI.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9979

Differential Revision: https://secure.phabricator.com/D14831

+138 -22
+6
src/__phutil_library_map__.php
··· 71 71 'AlmanacNetworkTransaction' => 'applications/almanac/storage/AlmanacNetworkTransaction.php', 72 72 'AlmanacNetworkTransactionQuery' => 'applications/almanac/query/AlmanacNetworkTransactionQuery.php', 73 73 'AlmanacNetworkViewController' => 'applications/almanac/controller/AlmanacNetworkViewController.php', 74 + 'AlmanacPropertiesDestructionEngineExtension' => 'applications/almanac/engineextension/AlmanacPropertiesDestructionEngineExtension.php', 74 75 'AlmanacProperty' => 'applications/almanac/storage/AlmanacProperty.php', 75 76 'AlmanacPropertyController' => 'applications/almanac/controller/AlmanacPropertyController.php', 76 77 'AlmanacPropertyDeleteController' => 'applications/almanac/controller/AlmanacPropertyDeleteController.php', ··· 2126 2127 'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php', 2127 2128 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 2128 2129 'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php', 2130 + 'PhabricatorDestructionEngineExtension' => 'applications/system/engine/PhabricatorDestructionEngineExtension.php', 2131 + 'PhabricatorDestructionEngineExtensionModule' => 'applications/system/engine/PhabricatorDestructionEngineExtensionModule.php', 2129 2132 'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php', 2130 2133 'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php', 2131 2134 'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php', ··· 3924 3927 'AlmanacNetworkTransaction' => 'PhabricatorApplicationTransaction', 3925 3928 'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3926 3929 'AlmanacNetworkViewController' => 'AlmanacNetworkController', 3930 + 'AlmanacPropertiesDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension', 3927 3931 'AlmanacProperty' => array( 3928 3932 'PhabricatorCustomFieldStorage', 3929 3933 'PhabricatorPolicyInterface', ··· 6295 6299 'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', 6296 6300 'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel', 6297 6301 'PhabricatorDestructionEngine' => 'Phobject', 6302 + 'PhabricatorDestructionEngineExtension' => 'Phobject', 6303 + 'PhabricatorDestructionEngineExtensionModule' => 'PhabricatorConfigModule', 6298 6304 'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions', 6299 6305 'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 6300 6306 'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
+32
src/applications/almanac/engineextension/AlmanacPropertiesDestructionEngineExtension.php
··· 1 + <?php 2 + 3 + final class AlmanacPropertiesDestructionEngineExtension 4 + extends PhabricatorDestructionEngineExtension { 5 + 6 + const EXTENSIONKEY = 'almanac.properties'; 7 + 8 + public function getExtensionName() { 9 + return pht('Almanac Properties'); 10 + } 11 + 12 + public function canDestroyObject( 13 + PhabricatorDestructionEngine $engine, 14 + $object) { 15 + return ($object instanceof AlmanacPropertyInterface); 16 + } 17 + 18 + public function destroyObject( 19 + PhabricatorDestructionEngine $engine, 20 + $object) { 21 + 22 + $table = new AlmanacProperty(); 23 + $conn_w = $table->establishConnection('w'); 24 + 25 + queryfx( 26 + $conn_w, 27 + 'DELETE FROM %T WHERE objectPHID = %s', 28 + $table->getTableName(), 29 + $object->getPHID()); 30 + } 31 + 32 + }
+1 -1
src/applications/search/engineextension/PhabricatorSearchEngineExtensionModule.php
··· 8 8 } 9 9 10 10 public function getModuleName() { 11 - return pht('SearchEngine Extensions'); 11 + return pht('Engine: Search'); 12 12 } 13 13 14 14 public function renderModuleStatus(AphrontRequest $request) {
+30 -20
src/applications/system/engine/PhabricatorDestructionEngine.php
··· 17 17 $log->setRootLogID($this->rootLogID); 18 18 } 19 19 20 - $object_phid = null; 21 - if (method_exists($object, 'getPHID')) { 22 - try { 23 - $object_phid = $object->getPHID(); 24 - $log->setObjectPHID($object_phid); 25 - } catch (Exception $ex) { 26 - // Ignore. 27 - } 20 + $object_phid = $this->getObjectPHID($object); 21 + if ($object_phid) { 22 + $log->setObjectPHID($object_phid); 28 23 } 29 24 30 25 if (method_exists($object, 'getMonogram')) { ··· 42 37 } 43 38 44 39 $object->destroyObjectPermanently($this); 40 + 41 + $extensions = PhabricatorDestructionEngineExtension::getAllExtensions(); 42 + foreach ($extensions as $key => $extension) { 43 + if (!$extension->canDestroyObject($this, $object)) { 44 + unset($extensions[$key]); 45 + continue; 46 + } 47 + } 48 + 49 + foreach ($extensions as $key => $extension) { 50 + $extension->destroyObject($this, $object); 51 + } 45 52 46 53 if ($object_phid) { 47 54 $this->destroyEdges($object_phid); ··· 92 99 $token->delete(); 93 100 } 94 101 } 95 - 96 - if ($object instanceof AlmanacPropertyInterface) { 97 - $this->destroyAlmanacProperties($object_phid); 98 - } 99 102 } 100 103 101 104 private function destroyEdges($src_phid) { ··· 152 155 $object_phid); 153 156 } 154 157 155 - private function destroyAlmanacProperties($object_phid) { 156 - $table = new AlmanacProperty(); 157 - $conn_w = $table->establishConnection('w'); 158 + private function destroyAlmanacProperties($object_phid) {} 159 + 160 + public function getObjectPHID($object) { 161 + if (!is_object($object)) { 162 + return null; 163 + } 164 + 165 + if (!method_exists($object, 'getPHID')) { 166 + return null; 167 + } 158 168 159 - queryfx( 160 - $conn_w, 161 - 'DELETE FROM %T WHERE objectPHID = %s', 162 - $table->getTableName(), 163 - $object_phid); 169 + try { 170 + return $object->getPHID(); 171 + } catch (Exception $ex) { 172 + return null; 173 + } 164 174 } 165 175 166 176 }
+24
src/applications/system/engine/PhabricatorDestructionEngineExtension.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorDestructionEngineExtension extends Phobject { 4 + 5 + final public function getExtensionKey() { 6 + return $this->getPhobjectClassConstant('EXTENSIONKEY'); 7 + } 8 + 9 + abstract public function getExtensionName(); 10 + abstract public function canDestroyObject( 11 + PhabricatorDestructionEngine $engine, 12 + $object); 13 + abstract public function destroyObject( 14 + PhabricatorDestructionEngine $engine, 15 + $object); 16 + 17 + final public static function getAllExtensions() { 18 + return id(new PhutilClassMapQuery()) 19 + ->setAncestorClass(__CLASS__) 20 + ->setUniqueMethod('getExtensionKey') 21 + ->execute(); 22 + } 23 + 24 + }
+44
src/applications/system/engine/PhabricatorDestructionEngineExtensionModule.php
··· 1 + <?php 2 + 3 + final class PhabricatorDestructionEngineExtensionModule 4 + extends PhabricatorConfigModule { 5 + 6 + public function getModuleKey() { 7 + return 'destructionengine'; 8 + } 9 + 10 + public function getModuleName() { 11 + return pht('Engine: Destruction'); 12 + } 13 + 14 + public function renderModuleStatus(AphrontRequest $request) { 15 + $viewer = $request->getViewer(); 16 + 17 + $extensions = PhabricatorDestructionEngineExtension::getAllExtensions(); 18 + 19 + $rows = array(); 20 + foreach ($extensions as $extension) { 21 + $rows[] = array( 22 + get_class($extension), 23 + $extension->getExtensionName(), 24 + ); 25 + } 26 + 27 + $table = id(new AphrontTableView($rows)) 28 + ->setHeaders( 29 + array( 30 + pht('Class'), 31 + pht('Name'), 32 + )) 33 + ->setColumnClasses( 34 + array( 35 + null, 36 + 'wide pri', 37 + )); 38 + 39 + return id(new PHUIObjectBoxView()) 40 + ->setHeaderText(pht('DestructionEngine Extensions')) 41 + ->setTable($table); 42 + } 43 + 44 + }
+1 -1
src/applications/transactions/editengineextension/PhabricatorEditEngineExtensionModule.php
··· 8 8 } 9 9 10 10 public function getModuleName() { 11 - return pht('EditEngine Extensions'); 11 + return pht('Engine: Edit'); 12 12 } 13 13 14 14 public function renderModuleStatus(AphrontRequest $request) {