1
0
Fork 0
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:
epriestley 2015-12-20 07:44:03 -08:00
parent 5fecd55d6e
commit 674388ce6a
7 changed files with 138 additions and 22 deletions

View file

@ -71,6 +71,7 @@ phutil_register_library_map(array(
'AlmanacNetworkTransaction' => 'applications/almanac/storage/AlmanacNetworkTransaction.php', 'AlmanacNetworkTransaction' => 'applications/almanac/storage/AlmanacNetworkTransaction.php',
'AlmanacNetworkTransactionQuery' => 'applications/almanac/query/AlmanacNetworkTransactionQuery.php', 'AlmanacNetworkTransactionQuery' => 'applications/almanac/query/AlmanacNetworkTransactionQuery.php',
'AlmanacNetworkViewController' => 'applications/almanac/controller/AlmanacNetworkViewController.php', 'AlmanacNetworkViewController' => 'applications/almanac/controller/AlmanacNetworkViewController.php',
'AlmanacPropertiesDestructionEngineExtension' => 'applications/almanac/engineextension/AlmanacPropertiesDestructionEngineExtension.php',
'AlmanacProperty' => 'applications/almanac/storage/AlmanacProperty.php', 'AlmanacProperty' => 'applications/almanac/storage/AlmanacProperty.php',
'AlmanacPropertyController' => 'applications/almanac/controller/AlmanacPropertyController.php', 'AlmanacPropertyController' => 'applications/almanac/controller/AlmanacPropertyController.php',
'AlmanacPropertyDeleteController' => 'applications/almanac/controller/AlmanacPropertyDeleteController.php', 'AlmanacPropertyDeleteController' => 'applications/almanac/controller/AlmanacPropertyDeleteController.php',
@ -2126,6 +2127,8 @@ phutil_register_library_map(array(
'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php', 'PhabricatorDesktopNotificationsSettingsPanel' => 'applications/settings/panel/PhabricatorDesktopNotificationsSettingsPanel.php',
'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php', 'PhabricatorDestructibleInterface' => 'applications/system/interface/PhabricatorDestructibleInterface.php',
'PhabricatorDestructionEngine' => 'applications/system/engine/PhabricatorDestructionEngine.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', 'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php', 'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php', 'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php',
@ -3924,6 +3927,7 @@ phutil_register_library_map(array(
'AlmanacNetworkTransaction' => 'PhabricatorApplicationTransaction', 'AlmanacNetworkTransaction' => 'PhabricatorApplicationTransaction',
'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'AlmanacNetworkTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'AlmanacNetworkViewController' => 'AlmanacNetworkController', 'AlmanacNetworkViewController' => 'AlmanacNetworkController',
'AlmanacPropertiesDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
'AlmanacProperty' => array( 'AlmanacProperty' => array(
'PhabricatorCustomFieldStorage', 'PhabricatorCustomFieldStorage',
'PhabricatorPolicyInterface', 'PhabricatorPolicyInterface',
@ -6295,6 +6299,8 @@ phutil_register_library_map(array(
'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', 'PhabricatorDefaultRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler',
'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorDesktopNotificationsSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDestructionEngine' => 'Phobject', 'PhabricatorDestructionEngine' => 'Phobject',
'PhabricatorDestructionEngineExtension' => 'Phobject',
'PhabricatorDestructionEngineExtensionModule' => 'PhabricatorConfigModule',
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel', 'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorSettingsPanel',
'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery', 'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',

View file

@ -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());
}
}

View file

@ -8,7 +8,7 @@ final class PhabricatorSearchEngineExtensionModule
} }
public function getModuleName() { public function getModuleName() {
return pht('SearchEngine Extensions'); return pht('Engine: Search');
} }
public function renderModuleStatus(AphrontRequest $request) { public function renderModuleStatus(AphrontRequest $request) {

View file

@ -17,14 +17,9 @@ final class PhabricatorDestructionEngine extends Phobject {
$log->setRootLogID($this->rootLogID); $log->setRootLogID($this->rootLogID);
} }
$object_phid = null; $object_phid = $this->getObjectPHID($object);
if (method_exists($object, 'getPHID')) { if ($object_phid) {
try { $log->setObjectPHID($object_phid);
$object_phid = $object->getPHID();
$log->setObjectPHID($object_phid);
} catch (Exception $ex) {
// Ignore.
}
} }
if (method_exists($object, 'getMonogram')) { if (method_exists($object, 'getMonogram')) {
@ -43,6 +38,18 @@ final class PhabricatorDestructionEngine extends Phobject {
$object->destroyObjectPermanently($this); $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) { if ($object_phid) {
$this->destroyEdges($object_phid); $this->destroyEdges($object_phid);
@ -92,10 +99,6 @@ final class PhabricatorDestructionEngine extends Phobject {
$token->delete(); $token->delete();
} }
} }
if ($object instanceof AlmanacPropertyInterface) {
$this->destroyAlmanacProperties($object_phid);
}
} }
private function destroyEdges($src_phid) { private function destroyEdges($src_phid) {
@ -152,15 +155,22 @@ final class PhabricatorDestructionEngine extends Phobject {
$object_phid); $object_phid);
} }
private function destroyAlmanacProperties($object_phid) { private function destroyAlmanacProperties($object_phid) {}
$table = new AlmanacProperty();
$conn_w = $table->establishConnection('w');
queryfx( public function getObjectPHID($object) {
$conn_w, if (!is_object($object)) {
'DELETE FROM %T WHERE objectPHID = %s', return null;
$table->getTableName(), }
$object_phid);
if (!method_exists($object, 'getPHID')) {
return null;
}
try {
return $object->getPHID();
} catch (Exception $ex) {
return null;
}
} }
} }

View file

@ -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();
}
}

View file

@ -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);
}
}

View file

@ -8,7 +8,7 @@ final class PhabricatorEditEngineExtensionModule
} }
public function getModuleName() { public function getModuleName() {
return pht('EditEngine Extensions'); return pht('Engine: Edit');
} }
public function renderModuleStatus(AphrontRequest $request) { public function renderModuleStatus(AphrontRequest $request) {