Added stat handlers (WIP)
authorMarcel Werk <burntime@woltlab.com>
Sun, 13 Apr 2014 21:19:53 +0000 (23:19 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 13 Apr 2014 21:19:53 +0000 (23:19 +0200)
com.woltlab.wcf/cronjob.xml
com.woltlab.wcf/objectType.xml
com.woltlab.wcf/objectTypeDefinition.xml
wcfsetup/install/files/lib/system/cronjob/StatDailyBuilderCronjob.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/stat/AttachmentStatDailyHandler.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/stat/IStatDailyHandler.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/stat/UserStatDailyHandler.class.php [new file with mode: 0644]
wcfsetup/setup/db/install.sql

index e4e3b1dbcdeec03cbcd18e2f163eece1815c62f7..de2e28988de83e943394fc9c6d757af7c7bd3b2d 100644 (file)
                
                <cronjob>
                        <classname><![CDATA[wcf\system\cronjob\ModerationQueueCronjob]]></classname>
-                       <description><![CDATA[Moderation Queue Cleanup]]></description>
+                       <description><![CDATA[Moderation queue cleanup]]></description>
+                       <description language="de"><![CDATA[Löscht veraltete Einträge in der Moderation]]></description>
+                       <startminute>0</startminute>
+                       <starthour>1</starthour>
+                       <startdom>*</startdom>
+                       <startmonth>*</startmonth>
+                       <startdow>*</startdow>
+                       <active>1</active>
+                       <canbeedited>1</canbeedited>
+                       <canbedisabled>1</canbedisabled>
+               </cronjob>
+               
+               <cronjob>
+                       <classname><![CDATA[wcf\system\cronjob\StatDailyBuilderCronjob]]></classname>
+                       <description><![CDATA[Builds the daily statistics]]></description>
+                       <description language="de"><![CDATA[Generiert die täglichen Statistiken]]></description>
                        <startminute>0</startminute>
                        <starthour>1</starthour>
                        <startdom>*</startdom>
index bc9bcb86456f00b8a14d2be4a74dd5ae8cb156e2..9c74b0cefc8cb511cee5c3c4618003889ab112f5 100644 (file)
                        <nicevalue>100</nicevalue>
                </type>
                <!-- /rebuild data workers -->
+               
+               <!-- stat handlers -->
+               <type>
+                       <name>com.woltlab.wcf.user</name>
+                       <definitionname>com.woltlab.wcf.statDailyHandler</definitionname>
+                       <classname><![CDATA[wcf\system\stat\UserStatDailyHandler]]></classname>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.attachment</name>
+                       <definitionname>com.woltlab.wcf.statDailyHandler</definitionname>
+                       <classname><![CDATA[wcf\system\stat\AttachmentStatDailyHandler]]></classname>
+               </type>
+               <!-- /stat handlers -->
        </import>
 </data>
\ No newline at end of file
index 8f4baff22bbd602715889daa286b72f18ba17386..aa717e42fb024c8fd077ca97486291f374380f44 100644 (file)
                        <name>com.woltlab.wcf.rebuildData</name>
                        <interfacename><![CDATA[wcf\system\worker\IRebuildDataWorker]]></interfacename>
                </definition>
+               
+               <definition>
+                       <name>com.woltlab.wcf.statDailyHandler</name>
+                       <interfacename><![CDATA[wcf\system\stat\IStatDailyHandler]]></interfacename>
+               </definition>
        </import>
 </data>
diff --git a/wcfsetup/install/files/lib/system/cronjob/StatDailyBuilderCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/StatDailyBuilderCronjob.class.php
new file mode 100644 (file)
index 0000000..2704311
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+namespace wcf\system\cronjob;
+use wcf\data\cronjob\Cronjob;
+use wcf\data\object\type\ObjectTypeCache;
+use wcf\system\WCF;
+use wcf\util\DateUtil;
+
+/**
+ * Builds daily statistics.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2014 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    com.woltlab.wcf
+ * @subpackage system.cronjob
+ * @category   Community Framework
+ */
+class StatDailyBuilderCronjob extends AbstractCronjob {
+       /**
+        * @see \wcf\system\cronjob\ICronjob::execute()
+        */
+       public function execute(Cronjob $cronjob) {
+               parent::execute($cronjob);
+               
+               // get date
+               $d = DateUtil::getDateTimeByTimestamp(TIME_NOW);
+               $d->setTimezone(new \DateTimeZone(TIMEZONE));
+               $d->sub(new \DateInterval('P1D'));
+               $d->setTime(0, 0);
+               $date = $d->getTimestamp();
+               
+               // prepare insert statement
+               $sql = "INSERT IGNORE INTO      wcf".WCF_N."_stat_daily
+                                               (objectTypeID, date, counter, total)
+                       VALUES                  (?, ?, ?, ?)";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               
+               // get object types
+               foreach (ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.statDailyHandler') as $objectType) {
+                       $data = $objectType->getProcessor()->getData($date);
+                       
+                       $statement->execute(array($objectType->objectTypeID, $d->format('Y-m-d'), $data['counter'], $data['total']));
+               }
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/AbstractStatDailyHandler.class.php
new file mode 100644 (file)
index 0000000..df2d314
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+namespace wcf\system\stat;
+use wcf\system\WCF;
+
+/**
+ * Abstract implementation of a stat handler.
+ *
+ * @author     Marcel Werk
+ * @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 AbstractStatDailyHandler implements IStatDailyHandler {
+       /**
+        * Counts the number of rows for a single day.
+        * 
+        * @param       integer         $date
+        * @param       string          $tableName
+        * @param       string          $dateColumnName
+        * @return      integer
+        */
+       protected function getCounter($date, $tableName, $dateColumnName) {
+               $sql = "SELECT  COUNT(*) AS count
+                       FROM    " . $tableName . "
+                       WHERE   " . $dateColumnName . " BETWEEN ? AND ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($date, $date + 86400));
+               return $statement->fetchColumn();
+       }
+       
+       /**
+        * Counts the total number of rows.
+        *
+        * @param       integer         $date
+        * @param       string          $tableName
+        * @param       string          $dateColumnName
+        * @return      integer
+        */
+       protected function getTotal($date, $tableName, $dateColumnName) {
+               $sql = "SELECT  COUNT(*) AS count
+                       FROM    " . $tableName . "
+                       WHERE   " . $dateColumnName . " < ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($date + 86400));
+               return $statement->fetchColumn();
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/stat/AttachmentStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/AttachmentStatDailyHandler.class.php
new file mode 100644 (file)
index 0000000..44395d5
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+namespace wcf\system\stat;
+use wcf\system\WCF;
+
+/**
+ * Stat handler implementation for attachment stats.
+ *
+ * @author     Marcel Werk
+ * @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
+ */
+class AttachmentStatDailyHandler extends AbstractStatDailyHandler {
+       /**
+        * @see \wcf\system\stat\IStatDailyHandler::getData()
+        */
+       public function getData($date) {
+               $sql = "SELECT  SUM(filesize)
+                       FROM    wcf".WCF_N."_attachment
+                       WHERE   uploadTime BETWEEN ? AND ?";
+               $statement = WCF::getDB()->prepareStatement($sql);
+               $statement->execute(array($date, $date + 86400));
+               $counter = intval($statement->fetchColumn());
+               
+               $sql = "SELECT  SUM(filesize)
+                       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
+               );
+       }
+}
diff --git a/wcfsetup/install/files/lib/system/stat/IStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/IStatDailyHandler.class.php
new file mode 100644 (file)
index 0000000..ef1d3d8
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace wcf\system\stat;
+
+/**
+ * Provides a general interface for statistic handler.
+ * 
+ * @author     Marcel Werk
+ * @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
+ */
+interface IStatDailyHandler {
+       /**
+        * Returns the stats.
+        * 
+        * @param       integer         $date
+        * @return      array
+        */
+       public function getData($date);
+}
diff --git a/wcfsetup/install/files/lib/system/stat/UserStatDailyHandler.class.php b/wcfsetup/install/files/lib/system/stat/UserStatDailyHandler.class.php
new file mode 100644 (file)
index 0000000..4ebae65
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace wcf\system\stat;
+
+/**
+ * Stat handler implementation for user stats.
+ *
+ * @author     Marcel Werk
+ * @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
+ */
+class UserStatDailyHandler extends AbstractStatDailyHandler {
+       /**
+        * @see \wcf\system\stat\IStatDailyHandler::getData()
+        */
+       public function getData($date) {
+               return array(
+                       'counter' => $this->getCounter($date, 'wcf'.WCF_N.'_user', 'registrationDate'),
+                       'total' => $this->getTotal($date, 'wcf'.WCF_N.'_user', 'registrationDate')
+               );
+       }
+}
index fe09ea57c43310982be9e9b4300de874d1fe99cc..552c78298c38494f744c7776ee9f72a6412ef93b 100644 (file)
@@ -846,6 +846,16 @@ CREATE TABLE wcf1_spider (
        UNIQUE KEY spiderIdentifier (spiderIdentifier)
 );
 
+DROP TABLE IF EXISTS wcf1_stat_daily;
+CREATE TABLE wcf1_stat_daily (
+       objectTypeID INT(10) NOT NULL,
+       date DATE NOT NULL,
+       counter INT(10) NOT NULL DEFAULT 0,
+       total INT(10) NOT NULL DEFAULT 0,
+       
+       UNIQUE KEY (objectTypeID, date)
+);
+
 DROP TABLE IF EXISTS wcf1_style;
 CREATE TABLE wcf1_style (
        styleID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -1534,6 +1544,8 @@ ALTER TABLE wcf1_tag_to_object ADD FOREIGN KEY (tagID) REFERENCES wcf1_tag (tagI
 ALTER TABLE wcf1_tag_to_object ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE CASCADE;
 ALTER TABLE wcf1_tag_to_object ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
 
+ALTER TABLE wcf1_stat_daily ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
+
 ALTER TABLE wcf1_search_index ADD FOREIGN KEY (objectTypeID) REFERENCES wcf1_object_type (objectTypeID) ON DELETE CASCADE;
 ALTER TABLE wcf1_search_index ADD FOREIGN KEY (languageID) REFERENCES wcf1_language (languageID) ON DELETE SET NULL;