Retrieve the total size of attachments from `wcf1_file`
authorAlexander Ebert <ebert@woltlab.com>
Mon, 23 Dec 2024 13:35:44 +0000 (14:35 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 23 Dec 2024 13:35:44 +0000 (14:35 +0100)
See https://www.woltlab.com/community/thread/310063-fehlerhafte-berechnung-der-gesamtgr%C3%B6%C3%9Fe-aller-dateianh%C3%A4nge/

wcfsetup/install/files/lib/data/attachment/AdministrativeAttachmentList.class.php

index 3aea4be7abe75109e85d8408294f8d2cda0c0ef5..87751e18d02971d4aeff5db4a30c94558e2844a2 100644 (file)
@@ -92,11 +92,13 @@ class AdministrativeAttachmentList extends AttachmentList
     public function getStats()
     {
         $sql = "SELECT  COUNT(*) AS count,
-                        COALESCE(SUM(attachment.filesize), 0) AS size,
+                        COALESCE(SUM(file.fileSize), 0) AS size,
                         COALESCE(SUM(downloads), 0) AS downloads
-                FROM    wcf" . WCF_N . "_attachment attachment
+                FROM    wcf1_attachment attachment
+                LEFT JOIN   wcf1_file file
+                ON          (file.fileID = attachment.fileID)
                 " . $this->getConditionBuilder();
-        $statement = WCF::getDB()->prepareStatement($sql);
+        $statement = WCF::getDB()->prepare($sql);
         $statement->execute($this->getConditionBuilder()->getParameters());
 
         return $statement->fetchArray();