From: Matthias Schmidt Date: Fri, 8 May 2015 16:09:38 +0000 (+0200) Subject: Add update script for 2.1.4 to update image attachment filesizes X-Git-Tag: 2.1.4~30 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=38c39b93416f4b89bc9afda782693941215a81fd;p=GitHub%2FWoltLab%2FWCF.git Add update script for 2.1.4 to update image attachment filesizes --- diff --git a/wcfsetup/install/files/acp/rebuild_attachments_com.woltlab.wcf_2.1.4.php b/wcfsetup/install/files/acp/rebuild_attachments_com.woltlab.wcf_2.1.4.php new file mode 100644 index 0000000000..a891d723ae --- /dev/null +++ b/wcfsetup/install/files/acp/rebuild_attachments_com.woltlab.wcf_2.1.4.php @@ -0,0 +1,86 @@ + + * @package com.woltlab.wcf + * @category Community Framework + */ +$minimumAttachmentTime = 1425219870; // time of the release note + +$attachmentsPerRun = 100; +$rebuildData = WCF::getSession()->getVar('__wcfUpdateRebuildAttachments'); +if ($rebuildData === null) { + $sql = "SELECT COUNT(*) + FROM wcf".WCF_N."_attachment + WHERE isImage = ? + AND uploadTime >= ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array( + 1, + $minimumAttachmentTime + )); + $count = $statement->fetchColumn(); + + $rebuildData = array( + 'i' => 0, + 'max' => 0 + ); + + if ($count) { + $rebuildData['max'] = ceil($count / $attachmentsPerRun); + } +} + +if ($rebuildData['max']) { + // get attachment file data + $attachmentList = new AttachmentList(); + $attachmentList->getConditionBuilder()->add('isImage = ?', array(1)); + $attachmentList->getConditionBuilder()->add('uploadTime >= ?', array($minimumAttachmentTime)); + $attachmentList->sqlOffset = $rebuildData['i'] * $attachmentsPerRun; + $attachmentList->sqlLimit = $attachmentsPerRun; + $attachmentList->readObjects(); + + if (!count($attachmentList)) { + // all relevant attachments have been processed + WCF::getSession()->unregister('__wcfUpdateRebuildAttachments'); + } + else { + $attachmentUpdates = array(); + foreach ($attachmentList as $attachment) { + $filesize = filesize($attachment->getLocation()); + if ($filesize != $attachment->filesize) { + $attachmentUpdates[$attachment->attachmentID] = $filesize; + } + } + + if (!empty($attachmentUpdates)) { + $sql = "UPDATE wcf".WCF_N."_attachment + SET filesize = ? + WHERE attachmentID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($attachmentUpdates as $attachmentID => $filesize) { + $statement->execute(array( + $filesize, + $attachmentID + )); + } + WCF::getDB()->commitTransaction(); + } + + // update rebuiled data + $rebuildData['i']++; + WCF::getSession()->register('__wcfUpdateRebuildAttachments', $rebuildData); + + throw new SplitNodeException(); + } +}