From f005665794fd456c7c8d645ed60c053d3d82a5e3 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Sun, 20 Apr 2014 00:51:31 +0200 Subject: [PATCH] Added stat rebuild worker --- com.woltlab.wcf/objectType.xml | 6 ++ .../StatDailyRebuildDataWorker.class.php | 99 +++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/worker/StatDailyRebuildDataWorker.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 94738961e9..95d095a02f 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -310,6 +310,12 @@ 100 + + com.woltlab.wcf.statDaily + com.woltlab.wcf.rebuildData + + 110 + diff --git a/wcfsetup/install/files/lib/system/worker/StatDailyRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/StatDailyRebuildDataWorker.class.php new file mode 100644 index 0000000000..e3916b1462 --- /dev/null +++ b/wcfsetup/install/files/lib/system/worker/StatDailyRebuildDataWorker.class.php @@ -0,0 +1,99 @@ + + * @package com.woltlab.wcf + * @subpackage system.worker + * @category Community Framework + */ +class StatDailyRebuildDataWorker extends AbstractRebuildDataWorker { + /** + * @see \wcf\system\worker\AbstractRebuildDataWorker::$objectListClassName + */ + protected $objectListClassName = 'wcf\data\attachment\AttachmentList'; + + /** + * @see \wcf\system\worker\AbstractWorker::$limit + */ + protected $limit = 30; + + /** + * start timestamp + * @var integer + */ + protected $startDate = 0; + + /** + * @see \wcf\system\worker\AbstractRebuildDataWorker::initObjectList() + */ + protected function initObjectList() {} + + /** + * @see \wcf\system\worker\IWorker::countObjects() + */ + public function countObjects() { + $this->getStartDate(); + + $this->count = ceil((TIME_NOW - $this->startDate) / 86400); + } + + /** + * @see \wcf\system\worker\IWorker::execute() + */ + public function execute() { + EventHandler::getInstance()->fireAction($this, 'execute'); + + if (!$this->loopCount) { + // delete existing stat + $sql = "DELETE FROM wcf".WCF_N."_stat_daily"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); + } + + // prepare insert statement + $sql = "INSERT IGNORE INTO wcf".WCF_N."_stat_daily + (objectTypeID, date, counter, total) + VALUES (?, ?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + $this->getStartDate(); + $d = DateUtil::getDateTimeByTimestamp($this->startDate); + $d->setTimezone(new \DateTimeZone(TIMEZONE)); + $d->setTime(0, 0); + if ($this->loopCount) { + $d->add(new \DateInterval('P'.($this->loopCount * $this->limit).'D')); + } + for ($i = 0; $i < $this->limit; $i++) { + // get object types + foreach (ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.statDailyHandler') as $objectType) { + $data = $objectType->getProcessor()->getData($d->getTimestamp()); + $statement->execute(array($objectType->objectTypeID, $d->format('Y-m-d'), $data['counter'], $data['total'])); + } + + $d->add(new \DateInterval('P1D')); + } + } + + /** + * Gets the start timestamp. + * + * @return integer + */ + protected function getStartDate() { + if ($this->startDate) return; + $sql = "SELECT MIN(registrationDate) + FROM wcf".WCF_N."_user"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); + $this->startDate = $statement->fetchColumn(); + } +} -- 2.20.1