Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4304797
D26026.1747811400.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
3 KB
Referenced Files
None
Subscribers
None
D26026.1747811400.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2613,6 +2613,7 @@
'PhabricatorBarePageView' => 'view/page/PhabricatorBarePageView.php',
'PhabricatorBaseURISetupCheck' => 'applications/config/check/PhabricatorBaseURISetupCheck.php',
'PhabricatorBcryptPasswordHasher' => 'infrastructure/util/password/PhabricatorBcryptPasswordHasher.php',
+ 'PhabricatorBeforeDestructionEngineExtension' => 'applications/system/engine/PhabricatorBeforeDestructionEngineExtension.php',
'PhabricatorBinariesSetupCheck' => 'applications/config/check/PhabricatorBinariesSetupCheck.php',
'PhabricatorBitbucketAuthProvider' => 'applications/auth/provider/PhabricatorBitbucketAuthProvider.php',
'PhabricatorBoardColumnsSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorBoardColumnsSearchEngineAttachment.php',
@@ -8974,6 +8975,7 @@
'PhabricatorBarePageView' => 'AphrontPageView',
'PhabricatorBaseURISetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorBcryptPasswordHasher' => 'PhabricatorPasswordHasher',
+ 'PhabricatorBeforeDestructionEngineExtension' => 'Phobject',
'PhabricatorBinariesSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorBitbucketAuthProvider' => 'PhabricatorOAuth1AuthProvider',
'PhabricatorBoardColumnsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
diff --git a/src/applications/system/engine/PhabricatorBeforeDestructionEngineExtension.php b/src/applications/system/engine/PhabricatorBeforeDestructionEngineExtension.php
new file mode 100644
--- /dev/null
+++ b/src/applications/system/engine/PhabricatorBeforeDestructionEngineExtension.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * Abstract "Before Destruction Engine",
+ * to fire an hook before something is permamently destroyed.
+ */
+abstract class PhabricatorBeforeDestructionEngineExtension extends Phobject {
+
+ /**
+ * Get the extension internal key.
+ *
+ * @return string
+ */
+ final public function getExtensionKey(): string {
+ return $this->getPhobjectClassConstant('EXTENSIONKEY');
+ }
+
+ /**
+ * Get the extension human name.
+ *
+ * @return string
+ */
+ abstract public function getExtensionName(): string;
+
+ /**
+ * Check whenever your extension supports a "Berfore Destruction" hook
+ * on the specified object.
+ */
+ public function canBeforeDestroyObject(
+ PhabricatorDestructionEngine $destruction_engine,
+ $object): bool {
+ return true;
+ }
+
+ /**
+ * Call your "Berfore Destruction" hook on the specified object.
+ * The object is guaranteed to be consistent with canBeforeDestroyObject().
+ */
+ abstract public function beforeDestroyObject(
+ PhabricatorDestructionEngine $engine,
+ $object);
+
+ /**
+ * Get all "Before Destruction Engine" extensions.
+ */
+ final public static function getAllExtensions(): array {
+ $map = new PhutilClassMapQuery();
+ return $map
+ ->setAncestorClass(__CLASS__)
+ ->setUniqueMethod('getExtensionKey')
+ ->execute();
+ }
+
+}
diff --git a/src/applications/system/engine/PhabricatorDestructionEngine.php b/src/applications/system/engine/PhabricatorDestructionEngine.php
--- a/src/applications/system/engine/PhabricatorDestructionEngine.php
+++ b/src/applications/system/engine/PhabricatorDestructionEngine.php
@@ -73,6 +73,17 @@
}
}
+ if ($object_phid) {
+ // Allow extension to do something before the destruction.
+ $before_extensions =
+ PhabricatorBeforeDestructionEngineExtension::getAllExtensions();
+ foreach ($before_extensions as $key => $before_extension) {
+ if ($before_extension->canBeforeDestroyObject($this, $object)) {
+ $before_extension->beforeDestroyObject($this, $object);
+ }
+ }
+ }
+
$object->destroyObjectPermanently($this);
if ($object_phid) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, May 21, 07:10 (14 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1637357
Default Alt Text
D26026.1747811400.diff (3 KB)
Attached To
Mode
D26026: Add a Before-Destruction Engine
Attached
Detach File
Event Timeline
Log In to Comment