Added rebuild polls worker
authorMarcel Werk <burntime@woltlab.com>
Fri, 27 May 2016 12:49:20 +0000 (14:49 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 27 May 2016 12:49:27 +0000 (14:49 +0200)
CHANGELOG.md
com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/worker/PollRebuildDataWorker.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 522870642221e82bb969ef93a7b96a7922ad5028..89bf9d88728365ba648d8b59c3dade3861b16583 100644 (file)
@@ -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
 
index df9fcecad9fe3c73389d002f8fc4b8690948af18..a5203a3771e3b644533faa0b48098d7bb662f76c 100644 (file)
                        <classname><![CDATA[wcf\system\worker\LikeUserRebuildDataWorker]]></classname>
                        <nicevalue>-90</nicevalue>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.poll</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname><![CDATA[wcf\system\worker\PollRebuildDataWorker]]></classname>
+                       <nicevalue>60</nicevalue>
+               </type>
                <type>
                        <name>com.woltlab.wcf.user</name>
                        <definitionname>com.woltlab.wcf.rebuildData</definitionname>
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 (file)
index 0000000..ef28a39
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+namespace wcf\system\worker;
+use wcf\data\poll\PollList;
+use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\WCF;
+
+/**
+ * Worker implementation for updating polls.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2016 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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());
+               }
+       }
+}
index 5a8ff6ef9c6d4b9203ba8bd185110aa66179917e..40949f00010cdc59276aa938abec12e3c1dc8ca4 100644 (file)
@@ -1275,6 +1275,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment.description"><![CDATA[Erzeugt Vorschaubilder neu]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily"><![CDATA[Statistiken aktualisieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily.description"><![CDATA[Erzeugt die täglichen Statistiken neu]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll"><![CDATA[Umfragen aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll.description"><![CDATA[Aktualisiert Zähler der Umfragen]]></item>
        </category>
        
        <category name="wcf.acp.rescueMode">
index 294770dbd626f37deff82c6053468295b648205e..d7a5855b48c7c2a7a30ce7454fab09baf023b5f1 100644 (file)
@@ -1281,6 +1281,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.attachment.description"><![CDATA[Rebuilds the attachment preview images.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily"><![CDATA[Rebuild Statistics]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.statDaily.description"><![CDATA[Rebuilds the daily statistics.]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll"><![CDATA[Rebuild Polls]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.poll.description"><![CDATA[Rebuilds the poll counters.]]></item>
        </category>
        
        <category name="wcf.acp.rescueMode">