Page MenuHomePhorge

D25051.1732326696.diff
No OneTemporary

D25051.1732326696.diff

diff --git a/resources/sql/autopatches/20230917.fileattachment.01.delete.sql b/resources/sql/autopatches/20230917.fileattachment.01.delete.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20230917.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)
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
@@ -3456,6 +3456,7 @@
'PhabricatorFileAES256StorageFormat' => 'applications/files/format/PhabricatorFileAES256StorageFormat.php',
'PhabricatorFileAltTextTransaction' => 'applications/files/xaction/PhabricatorFileAltTextTransaction.php',
'PhabricatorFileAttachment' => 'applications/files/storage/PhabricatorFileAttachment.php',
+ 'PhabricatorFileAttachmentDestructionEngineExtension' => 'applications/files/engineextension/PhabricatorFileAttachmentDestructionEngineExtension.php',
'PhabricatorFileAttachmentQuery' => 'applications/files/query/PhabricatorFileAttachmentQuery.php',
'PhabricatorFileBundleLoader' => 'applications/files/query/PhabricatorFileBundleLoader.php',
'PhabricatorFileChunk' => 'applications/files/storage/PhabricatorFileChunk.php',
@@ -9917,6 +9918,7 @@
'PhabricatorPolicyInterface',
'PhabricatorExtendedPolicyInterface',
),
+ 'PhabricatorFileAttachmentDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
'PhabricatorFileAttachmentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorFileBundleLoader' => 'Phobject',
'PhabricatorFileChunk' => array(
diff --git a/src/applications/files/engineextension/PhabricatorFileAttachmentDestructionEngineExtension.php b/src/applications/files/engineextension/PhabricatorFileAttachmentDestructionEngineExtension.php
new file mode 100644
--- /dev/null
+++ b/src/applications/files/engineextension/PhabricatorFileAttachmentDestructionEngineExtension.php
@@ -0,0 +1,22 @@
+<?php
+
+final class PhabricatorFileAttachmentDestructionEngineExtension
+ extends PhabricatorDestructionEngineExtension {
+
+ const EXTENSIONKEY = 'file.attachments';
+
+ public function getExtensionName() {
+ return pht('File Attachments');
+ }
+
+ public function destroyObject(
+ PhabricatorDestructionEngine $engine,
+ $object) {
+ $attachments = id(new PhabricatorFileAttachment())->loadAllWhere(
+ 'objectPHID = %s',
+ $object->getPHID());
+ foreach ($attachments as $attachment) {
+ $attachment->delete();
+ }
+ }
+}
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -1705,6 +1705,14 @@
PhabricatorDestructionEngine $engine) {
$this->openTransaction();
+
+ $attachments = id(new PhabricatorFileAttachment())->loadAllWhere(
+ 'filePHID = %s',
+ $this->getPHID());
+ foreach ($attachments as $attachment) {
+ $attachment->delete();
+ }
+
$this->delete();
$this->saveTransaction();
}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 01:51 (16 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
989456
Default Alt Text
D25051.1732326696.diff (3 KB)

Event Timeline