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) 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,28 @@ +getPHID(); + $attachments = id(new PhabricatorFileAttachmentQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withFilePHIDs(array($file_phid)) + ->execute(); + mpull($attachments, 'delete'); + } +}