mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 12:00:55 +01:00
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
This commit is contained in:
parent
5fecd55d6e
commit
674388ce6a
7 changed files with 138 additions and 22 deletions
|
@ -71,6 +71,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacNetworkTransaction' => 'applications/almanac/storage/AlmanacNetworkTransaction.php',
|
||||
'AlmanacNetworkTransactionQuery' => 'applications/almanac/query/AlmanacNetworkTransactionQuery.php',
|
||||
'AlmanacNetworkViewController' => 'applications/almanac/controller/AlmanacNetworkViewController.php',
|
||||
'AlmanacPropertiesDestructionEngineExtension' => 'applications/almanac/engineextension/AlmanacPropertiesDestructionEngineExtension.php',
|
||||
'AlmanacProperty' => 'applications/almanac/storage/AlmanacProperty.php',
|
||||
'AlmanacPropertyController' => 'applications/almanac/controller/AlmanacPropertyController.php',
|
||||
'AlmanacPropertyDeleteController' => 'applications/almanac/controller/AlmanacPropertyDeleteController.php',
|
||||
|
@ -2126,6 +2127,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php',
|
||||
'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php',
|
||||
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.php',
|
||||
'PhabricatorDestructionEngineExtension' => 'applications/system/engine/PhabricatorDestructionEngineExtension.php',
|
||||
'PhabricatorDestructionEngineExtensionModule' => 'applications/system/engine/PhabricatorDestructionEngineExtensionModule.php',
|
||||
'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
|
||||
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
|
||||
'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php',
|
||||
|
@ -3924,6 +3927,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacNetworkTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'AlmanacNetworkViewController' => 'AlmanacNetworkController',
|
||||
'AlmanacPropertiesDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
|
||||
'AlmanacProperty' => array(
|
||||
'PhabricatorCustomFieldStorage',
|
||||
'PhabricatorPolicyInterface',
|
||||
|
@ -6295,6 +6299,8 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
|
||||
'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorDestructionEngine' => 'Phobject',
|
||||
'PhabricatorDestructionEngineExtension' => 'Phobject',
|
||||
'PhabricatorDestructionEngineExtensionModule' => 'PhabricatorConfigModule',
|
||||
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||
'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
final class AlmanacPropertiesDestructionEngineExtension
|
||||
extends PhabricatorDestructionEngineExtension {
|
||||
|
||||
const EXTENSIONKEY = 'almanac.properties';
|
||||
|
||||
public function getExtensionName() {
|
||||
return pht('Almanac Properties');
|
||||
}
|
||||
|
||||
public function canDestroyObject(
|
||||
PhabricatorDestructionEngine $engine,
|
||||
$object) {
|
||||
return ($object instanceof AlmanacPropertyInterface);
|
||||
}
|
||||
|
||||
public function destroyObject(
|
||||
PhabricatorDestructionEngine $engine,
|
||||
$object) {
|
||||
|
||||
$table = new AlmanacProperty();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'DELETE FROM %T WHERE objectPHID = %s',
|
||||
$table->getTableName(),
|
||||
$object->getPHID());
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ final class PhabricatorSearchEngineExtensionModule
|
|||
}
|
||||
|
||||
public function getModuleName() {
|
||||
return pht('SearchEngine Extensions');
|
||||
return pht('Engine: Search');
|
||||
}
|
||||
|
||||
public function renderModuleStatus(AphrontRequest $request) {
|
||||
|
|
|
@ -17,14 +17,9 @@ final class PhabricatorDestructionEngine extends Phobject {
|
|||
$log->setRootLogID($this->rootLogID);
|
||||
}
|
||||
|
||||
$object_phid = null;
|
||||
if (method_exists($object, 'getPHID')) {
|
||||
try {
|
||||
$object_phid = $object->getPHID();
|
||||
$object_phid = $this->getObjectPHID($object);
|
||||
if ($object_phid) {
|
||||
$log->setObjectPHID($object_phid);
|
||||
} catch (Exception $ex) {
|
||||
// Ignore.
|
||||
}
|
||||
}
|
||||
|
||||
if (method_exists($object, 'getMonogram')) {
|
||||
|
@ -43,6 +38,18 @@ final class PhabricatorDestructionEngine extends Phobject {
|
|||
|
||||
$object->destroyObjectPermanently($this);
|
||||
|
||||
$extensions = PhabricatorDestructionEngineExtension::getAllExtensions();
|
||||
foreach ($extensions as $key => $extension) {
|
||||
if (!$extension->canDestroyObject($this, $object)) {
|
||||
unset($extensions[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($extensions as $key => $extension) {
|
||||
$extension->destroyObject($this, $object);
|
||||
}
|
||||
|
||||
if ($object_phid) {
|
||||
$this->destroyEdges($object_phid);
|
||||
|
||||
|
@ -92,10 +99,6 @@ final class PhabricatorDestructionEngine extends Phobject {
|
|||
$token->delete();
|
||||
}
|
||||
}
|
||||
|
||||
if ($object instanceof AlmanacPropertyInterface) {
|
||||
$this->destroyAlmanacProperties($object_phid);
|
||||
}
|
||||
}
|
||||
|
||||
private function destroyEdges($src_phid) {
|
||||
|
@ -152,15 +155,22 @@ final class PhabricatorDestructionEngine extends Phobject {
|
|||
$object_phid);
|
||||
}
|
||||
|
||||
private function destroyAlmanacProperties($object_phid) {
|
||||
$table = new AlmanacProperty();
|
||||
$conn_w = $table->establishConnection('w');
|
||||
private function destroyAlmanacProperties($object_phid) {}
|
||||
|
||||
queryfx(
|
||||
$conn_w,
|
||||
'DELETE FROM %T WHERE objectPHID = %s',
|
||||
$table->getTableName(),
|
||||
$object_phid);
|
||||
public function getObjectPHID($object) {
|
||||
if (!is_object($object)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!method_exists($object, 'getPHID')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return $object->getPHID();
|
||||
} catch (Exception $ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorDestructionEngineExtension extends Phobject {
|
||||
|
||||
final public function getExtensionKey() {
|
||||
return $this->getPhobjectClassConstant('EXTENSIONKEY');
|
||||
}
|
||||
|
||||
abstract public function getExtensionName();
|
||||
abstract public function canDestroyObject(
|
||||
PhabricatorDestructionEngine $engine,
|
||||
$object);
|
||||
abstract public function destroyObject(
|
||||
PhabricatorDestructionEngine $engine,
|
||||
$object);
|
||||
|
||||
final public static function getAllExtensions() {
|
||||
return id(new PhutilClassMapQuery())
|
||||
->setAncestorClass(__CLASS__)
|
||||
->setUniqueMethod('getExtensionKey')
|
||||
->execute();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDestructionEngineExtensionModule
|
||||
extends PhabricatorConfigModule {
|
||||
|
||||
public function getModuleKey() {
|
||||
return 'destructionengine';
|
||||
}
|
||||
|
||||
public function getModuleName() {
|
||||
return pht('Engine: Destruction');
|
||||
}
|
||||
|
||||
public function renderModuleStatus(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$extensions = PhabricatorDestructionEngineExtension::getAllExtensions();
|
||||
|
||||
$rows = array();
|
||||
foreach ($extensions as $extension) {
|
||||
$rows[] = array(
|
||||
get_class($extension),
|
||||
$extension->getExtensionName(),
|
||||
);
|
||||
}
|
||||
|
||||
$table = id(new AphrontTableView($rows))
|
||||
->setHeaders(
|
||||
array(
|
||||
pht('Class'),
|
||||
pht('Name'),
|
||||
))
|
||||
->setColumnClasses(
|
||||
array(
|
||||
null,
|
||||
'wide pri',
|
||||
));
|
||||
|
||||
return id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('DestructionEngine Extensions'))
|
||||
->setTable($table);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@ final class PhabricatorEditEngineExtensionModule
|
|||
}
|
||||
|
||||
public function getModuleName() {
|
||||
return pht('EditEngine Extensions');
|
||||
return pht('Engine: Edit');
|
||||
}
|
||||
|
||||
public function renderModuleStatus(AphrontRequest $request) {
|
||||
|
|
Loading…
Reference in a new issue