Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4315922
D26026.1748086719.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.1748086719.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,56 @@
+<?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 this extension supports a "Before 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.
+ *
+ * @return array<self>
+ */
+ 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
Sat, May 24, 11:38 (13 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1643964
Default Alt Text
D26026.1748086719.diff (3 KB)
Attached To
Mode
D26026: Add a Before-Destruction Engine
Attached
Detach File
Event Timeline
Log In to Comment