Increase the grace period for temporary attachments for logged-in users
authorAlexander Ebert <ebert@woltlab.com>
Sat, 15 Jun 2024 10:25:02 +0000 (12:25 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 15 Jun 2024 10:25:02 +0000 (12:25 +0200)
wcfsetup/install/files/lib/system/cronjob/AttachmentCleanUpCronjob.class.php
wcfsetup/install/files/lib/system/file/processor/AttachmentFileProcessor.class.php

index c28ab23fb8fc94a72ce01da9cce3414df03c9852..f3e6b383e367c694c1a56af859f619d85666cf0e 100644 (file)
@@ -25,13 +25,23 @@ class AttachmentCleanUpCronjob extends AbstractCronjob
 
         // delete orphaned attachments
         $sql = "SELECT  attachmentID
-                FROM    wcf" . WCF_N . "_attachment
+                FROM    wcf1_attachment
                 WHERE   objectID = ?
-                    AND uploadTime < ?";
-        $statement = WCF::getDB()->prepareStatement($sql);
+                    AND (
+                            (
+                                userID IS NULL
+                                AND uploadTime < ?
+                            )
+                            OR (
+                                userID IS NOT NULL
+                                AND uploadTime < ?
+                            )
+                        )";
+        $statement = WCF::getDB()->prepare($sql);
         $statement->execute([
             0,
             TIME_NOW - 86400,
+            TIME_NOW - (86400 * 3),
         ]);
         $attachmentIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
 
index 3c9f5d3c48ebc3e75d6a0e203b69586a66985b5d..9d0f62dbd744e5c8a09f3d4c44adbfbb5c53d4fc 100644 (file)
@@ -57,6 +57,7 @@ final class AttachmentFileProcessor extends AbstractFileProcessor
             'tmpHash' => $attachmentHandler->getTmpHashes()[0] ?? '',
             'fileID' => $file->fileID,
             'userID' => WCF::getUser()->userID ?: null,
+            'uploadTime' => \TIME_NOW,
         ]);
     }