From: Marcel Werk Date: Fri, 27 May 2016 12:49:20 +0000 (+0200) Subject: Added rebuild polls worker X-Git-Tag: 3.0.0_Beta_1~1600 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e3b8abb0bb3da2ce8f4f6af0f32f269b884f74e1;p=GitHub%2FWoltLab%2FWCF.git Added rebuild polls worker --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 5228706422..89bf9d8872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,7 @@ * Overhauled page tracking in sessions / user online locations * Overhauled language import form * Removed sitemap function/overlay +* Added rebuild polls worker #### CMS diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index df9fcecad9..a5203a3771 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -254,6 +254,12 @@ -90 + + com.woltlab.wcf.poll + com.woltlab.wcf.rebuildData + + 60 + com.woltlab.wcf.user com.woltlab.wcf.rebuildData diff --git a/wcfsetup/install/files/lib/system/worker/PollRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/PollRebuildDataWorker.class.php new file mode 100644 index 0000000000..ef28a393e7 --- /dev/null +++ b/wcfsetup/install/files/lib/system/worker/PollRebuildDataWorker.class.php @@ -0,0 +1,76 @@ + + * @package com.woltlab.wcf + * @subpackage system.worker + * @category Community Framework + */ +class PollRebuildDataWorker extends AbstractRebuildDataWorker { + /** + * @inheritDoc + */ + protected $objectListClassName = PollList::class; + + /** + * @inheritDoc + */ + protected $limit = 10; + + /** + * @inheritDoc + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->objectList->sqlOrderBy = 'poll.pollID'; + } + + /** + * @inheritDoc + */ + public function execute() { + parent::execute(); + + $pollIDs = []; + foreach ($this->getObjectList() as $poll) { + $pollIDs[] = $poll->pollID; + } + + if (!empty($pollIDs)) { + // update poll options + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('poll_option.pollID IN (?)', [$pollIDs]); + $sql = "UPDATE wcf" . WCF_N . "_poll_option poll_option + SET votes = ( + SELECT COUNT(*) + FROM wcf" . WCF_N . "_poll_option_vote + WHERE optionID = poll_option.optionID + ) + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + + // update polls + $conditionBuilder = new PreparedStatementConditionBuilder(); + $conditionBuilder->add('poll.pollID IN (?)', [$pollIDs]); + $sql = "UPDATE wcf" . WCF_N . "_poll poll + SET votes = ( + SELECT COUNT(*) + FROM wcf" . WCF_N . "_poll_option_vote + WHERE pollID = poll.pollID + ) + " . $conditionBuilder; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditionBuilder->getParameters()); + } + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 5a8ff6ef9c..40949f0001 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1275,6 +1275,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 294770dbd6..d7a5855b48 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1281,6 +1281,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> + +