Add AbstractDiskUsageStatDailyHandler
authorMatthias Schmidt <gravatronics@live.com>
Wed, 9 Jul 2014 15:40:12 +0000 (17:40 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 9 Jul 2014 15:40:12 +0000 (17:40 +0200)
wcfsetup/install/files/lib/system/stat/AbstractDiskUsageStatDailyHandler.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/stat/AttachmentDiskUsageStatDailyHandler.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 (file)
index 0000000..5e5c1ab
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+namespace wcf\system\stat;
+use wcf\system\WCF;
+
+/**
+ * Abstract stat handler implementation for disk usage.
+ * 
+ * @author     Matthias Schmidt
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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
+       }
+}
index 066300065e6632e26fcb5f9ca50b155eacaa7afd..7f12aea4c119534db23def3aa1dcbb70e25a5f1a 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\stat;
-use wcf\system\WCF;
 
 /**
  * Stat handler implementation for attachment disk usage.
@@ -12,35 +11,14 @@ use wcf\system\WCF;
  * @subpackage system.stat
  * @category   Community Framework
  */
-class AttachmentDiskUsageStatDailyHandler extends AbstractStatDailyHandler {
+class AttachmentDiskUsageStatDailyHandler extends AbstractDiskUsageStatDailyHandler {
        /**
         * @see \wcf\system\stat\IStatDailyHandler::getData()
         */
        public function getData($date) {
-               $sql = "SELECT  CEIL(SUM(filesize) / 1000)
-                       FROM    wcf".WCF_N."_attachment
-                       WHERE   uploadTime BETWEEN ? AND ?";
-               $statement = WCF::getDB()->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
-       }
 }