Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4908166
D26026.1749507461.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
5 KB
Referenced Files
None
Subscribers
None
D26026.1749507461.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,83 @@
+<?php
+
+/**
+ * Abstract "Before Destruction Engine",
+ * to fire a hook before something is permamently destroyed.
+ *
+ * This class is to be considered unstable and may receive variations
+ * over time. If you want to use this engine or extend its features, please
+ * share your use-case here, even if the task is closed:
+ * https://we.phorge.it/T16079
+ */
+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 if this extension supports a "Before Destruction" hook
+ * on the specified object.
+ *
+ * The object is guaranteed to have a PHID and still exist but
+ * will be destroyed later.
+ * This method should not contain write operations.
+ * This method exposes a PhabricatorDestructionEngine since it can give
+ * useful info, but here you should not use it to destroy objects.
+ * When this method returns true, the method beforeDestroyObject()
+ * will be fired.
+ *
+ * @param PhabricatorDestructionEngine $destruction_engine
+ * Available destruction engine
+ * @param object $object
+ * Object that will be destroyed
+ * @return bool If true, beforeDestroyObject()
+ * will be fired.
+ */
+ public function canBeforeDestroyObject(
+ PhabricatorDestructionEngine $destruction_engine,
+ $object): bool {
+ return true;
+ }
+
+ /**
+ * Call your "Before Destruction" hook on the specified object.
+ * The object is guaranteed to have a PHID and still exist but
+ * will be destroyed later.
+ * This method is not called if canBeforeDestroyObject() returns false.
+ *
+ * @param PhabricatorDestructionEngine $destruction_engine
+ * Available destruction engine
+ * @param object $object
+ * Object that will be destroyed
+ */
+ abstract public function beforeDestroyObject(
+ PhabricatorDestructionEngine $destruction_engine,
+ $object);
+
+ /**
+ * Get all "Before Destruction Engine" extensions.
+ *
+ * @return list<PhabricatorDestructionEngineExtension>
+ */
+ 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
Mon, Jun 9, 22:17 (6 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1784280
Default Alt Text
D26026.1749507461.diff (5 KB)
Attached To
Mode
D26026: Add a Before-Destruction Engine
Attached
Detach File
Event Timeline
Log In to Comment