Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2644132
D25051.1732275734.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
2 KB
Referenced Files
None
Subscribers
None
D25051.1732275734.diff
View Options
diff --git a/resources/sql/autopatches/20220912.fileattachment.01.delete.sql b/resources/sql/autopatches/20220912.fileattachment.01.delete.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20220912.fileattachment.01.delete.sql
@@ -0,0 +1,6 @@
+USE {$NAMESPACE}_file;
+ DELETE FROM file_attachment
+ WHERE NOT EXISTS
+ (SELECT *
+ FROM file
+ WHERE phid=file_attachment.filePHID)
\ No newline at end of file
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
@@ -3457,6 +3457,7 @@
'PhabricatorFileAltTextTransaction' => 'applications/files/xaction/PhabricatorFileAltTextTransaction.php',
'PhabricatorFileAttachment' => 'applications/files/storage/PhabricatorFileAttachment.php',
'PhabricatorFileAttachmentQuery' => 'applications/files/query/PhabricatorFileAttachmentQuery.php',
+ 'PhabricatorFileAttachmentsDestructionEngineExtension' => 'applications/files/engineextension/PhabricatorFilesAttachmentsDestructionEngineExtension.php',
'PhabricatorFileBundleLoader' => 'applications/files/query/PhabricatorFileBundleLoader.php',
'PhabricatorFileChunk' => 'applications/files/storage/PhabricatorFileChunk.php',
'PhabricatorFileChunkIterator' => 'applications/files/engine/PhabricatorFileChunkIterator.php',
@@ -9918,6 +9919,7 @@
'PhabricatorExtendedPolicyInterface',
),
'PhabricatorFileAttachmentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorFileAttachmentsDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
'PhabricatorFileBundleLoader' => 'Phobject',
'PhabricatorFileChunk' => array(
'PhabricatorFileDAO',
diff --git a/src/applications/files/engineextension/PhabricatorFilesAttachmentsDestructionEngineExtension.php b/src/applications/files/engineextension/PhabricatorFilesAttachmentsDestructionEngineExtension.php
new file mode 100644
--- /dev/null
+++ b/src/applications/files/engineextension/PhabricatorFilesAttachmentsDestructionEngineExtension.php
@@ -0,0 +1,28 @@
+<?php
+
+final class PhabricatorFileAttachmentsDestructionEngineExtension
+ extends PhabricatorDestructionEngineExtension {
+
+ const EXTENSIONKEY = 'attachments';
+
+ public function getExtensionName() {
+ return pht('File Attachments');
+ }
+
+ public function canDestroyObject(
+ PhabricatorDestructionEngine $engine,
+ $object) {
+ return ($object instanceof PhabricatorFile);
+ }
+
+ public function destroyObject(
+ PhabricatorDestructionEngine $engine,
+ $object) {
+ $file_phid = $object->getPHID();
+ $attachments = id(new PhabricatorFileAttachmentQuery())
+ ->setViewer(PhabricatorUser::getOmnipotentUser())
+ ->withFilePHIDs(array($file_phid))
+ ->execute();
+ mpull($attachments, 'delete');
+ }
+}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 11:42 (13 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
989153
Default Alt Text
D25051.1732275734.diff (2 KB)
Attached To
Mode
D25051: Destroy file attachments when file is deleted, or object is deleted
Attached
Detach File
Event Timeline
Log In to Comment