Fix the `tmpHash` being set for files with an object id
authorAlexander Ebert <ebert@woltlab.com>
Thu, 15 Aug 2024 11:21:30 +0000 (13:21 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 15 Aug 2024 11:21:30 +0000 (13:21 +0200)
wcfsetup/install/files/lib/system/file/processor/AttachmentFileProcessor.class.php

index 9d0f62dbd744e5c8a09f3d4c44adbfbb5c53d4fc..6de38a51aee0432f3414afde6c7eaddf199cd602 100644 (file)
@@ -51,10 +51,16 @@ final class AttachmentFileProcessor extends AbstractFileProcessor
             return;
         }
 
+        $objectID = $attachmentHandler->getObjectID();
+        $tmpHash = $attachmentHandler->getTmpHashes()[0] ?? '';
+        if ($objectID > 0) {
+            $tmpHash = '';
+        }
+
         AttachmentEditor::fastCreate([
             'objectTypeID' => $attachmentHandler->getObjectType()->objectTypeID,
-            'objectID' => $attachmentHandler->getObjectID(),
-            'tmpHash' => $attachmentHandler->getTmpHashes()[0] ?? '',
+            'objectID' => $objectID,
+            'tmpHash' => $tmpHash,
             'fileID' => $file->fileID,
             'userID' => WCF::getUser()->userID ?: null,
             'uploadTime' => \TIME_NOW,
@@ -298,6 +304,5 @@ final class AttachmentFileProcessorContext
         public readonly int $parentObjectID,
 
         public readonly string $tmpHash,
-    ) {
-    }
+    ) {}
 }