From 868ac0de1f646db96747b935255e04d2bb0aeaaa Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 9 Jul 2014 17:40:12 +0200 Subject: [PATCH] Add AbstractDiskUsageStatDailyHandler --- ...bstractDiskUsageStatDailyHandler.class.php | 46 +++++++++++++++++++ ...achmentDiskUsageStatDailyHandler.class.php | 28 ++--------- 2 files changed, 49 insertions(+), 25 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/stat/AbstractDiskUsageStatDailyHandler.class.php diff --git a/wcfsetup/install/files/lib/system/stat/AbstractDiskUsageStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/AbstractDiskUsageStatDailyHandler.class.php new file mode 100644 index 0000000000..5e5c1ab8b4 --- /dev/null +++ b/wcfsetup/install/files/lib/system/stat/AbstractDiskUsageStatDailyHandler.class.php @@ -0,0 +1,46 @@ + + * @package com.woltlab.wcf + * @subpackage system.stat + * @category Community Framework + */ +abstract class AbstractDiskUsageStatDailyHandler extends AbstractStatDailyHandler { + /** + * @see \wcf\system\stat\AbstractStatDailyHandler::getCounter() + */ + protected function getCounter($date, $tableName, $dateColumnName) { + $sql = "SELECT CEIL(SUM(filesize) / 1000) + FROM ".$tableName." + WHERE ".$dateColumnName." BETWEEN ? AND ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($date, $date + 86399)); + return $statement->fetchColumn(); + } + + /** + * @see \wcf\system\stat\AbstractStatDailyHandler::getTotal() + */ + protected function getTotal($date, $tableName, $dateColumnName) { + $sql = "SELECT CEIL(SUM(filesize) / 1000) + FROM ".$tableName." + WHERE ".$dateColumnName." < ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(array($date + 86400)); + return $statement->fetchColumn(); + } + + /** + * @see \wcf\system\stat\IStatDailyHandler::getFormattedCounter() + */ + public function getFormattedCounter($counter) { + return round($counter / 1000, 2); // return mb + } +} diff --git a/wcfsetup/install/files/lib/system/stat/AttachmentDiskUsageStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/AttachmentDiskUsageStatDailyHandler.class.php index 066300065e..7f12aea4c1 100644 --- a/wcfsetup/install/files/lib/system/stat/AttachmentDiskUsageStatDailyHandler.class.php +++ b/wcfsetup/install/files/lib/system/stat/AttachmentDiskUsageStatDailyHandler.class.php @@ -1,6 +1,5 @@ prepareStatement($sql); - $statement->execute(array($date, $date + 86399)); - $counter = intval($statement->fetchColumn()); - - $sql = "SELECT CEIL(SUM(filesize) / 1000) - FROM wcf".WCF_N."_attachment - WHERE uploadTime < ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($date + 86400)); - $total = intval($statement->fetchColumn()); - return array( - 'counter' => $counter, - 'total' => $total + 'counter' => $this->getCounter($date, 'wcf'.WCF_N.'_attachment', 'uploadTime'), + 'total' => $this->getTotal($date, 'wcf'.WCF_N.'_attachment', 'uploadTime') ); } - - /** - * @see \wcf\system\stat\IStatDailyHandler::getFormattedCounter() - */ - public function getFormattedCounter($counter) { - return round($counter / 1000, 2); // return mb - } } -- 2.20.1