Added rebuild data worker for comments
authorAlexander Ebert <ebert@woltlab.com>
Thu, 2 Mar 2017 19:03:03 +0000 (20:03 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 2 Mar 2017 19:03:03 +0000 (20:03 +0100)
See #2222

com.woltlab.wcf/objectType.xml
wcfsetup/install/files/lib/system/worker/CommentRebuildDataWorker.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 45d5888da3e05bf620e98d09c0cf3462d87022f3..ea76c956691288fc6c609ee7c1d5cafd1700693b 100644 (file)
                        <classname>wcf\system\worker\StatDailyRebuildDataWorker</classname>
                        <nicevalue>110</nicevalue>
                </type>
+               <type>
+                       <name>com.woltlab.wcf.comment</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname>wcf\system\worker\CommentRebuildDataWorker</classname>
+                       <nicevalue>120</nicevalue>
+               </type>
                <!-- /rebuild data workers -->
                
                <!-- stat handlers -->
diff --git a/wcfsetup/install/files/lib/system/worker/CommentRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/CommentRebuildDataWorker.class.php
new file mode 100644 (file)
index 0000000..f572328
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+namespace wcf\system\worker;
+use wcf\data\comment\Comment;
+use wcf\data\comment\CommentEditor;
+use wcf\data\comment\CommentList;
+use wcf\system\html\input\HtmlInputProcessor;
+use wcf\system\WCF;
+
+/**
+ * Worker implementation for updating comments.
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2017 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\Worker
+ */
+class CommentRebuildDataWorker extends AbstractRebuildDataWorker {
+       /**
+        * @inheritDoc
+        */
+       protected $limit = 500;
+       
+       /**
+        * @var HtmlInputProcessor
+        */
+       protected $htmlInputProcessor;
+       
+       /** @noinspection PhpMissingParentCallCommonInspection */
+       /**
+        * @inheritDoc
+        */
+       public function countObjects() {
+               if ($this->count === null) {
+                       $this->count = 0;
+                       $sql = "SELECT  MAX(commentID) AS commentID
+                               FROM    wcf".WCF_N."_comment";
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute();
+                       $row = $statement->fetchArray();
+                       if ($row !== false) $this->count = $row['commentID'];
+               }
+       }
+       
+       /** @noinspection PhpMissingParentCallCommonInspection */
+       /**
+        * @inheritDoc
+        */
+       protected function initObjectList() {
+               $this->objectList = new CommentList();
+               $this->objectList->sqlOrderBy = 'comment.commentID';
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function execute() {
+               $this->objectList->getConditionBuilder()->add('comment.commentID BETWEEN ? AND ?', [$this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit]);
+               
+               parent::execute();
+               
+               if (!count($this->objectList)) {
+                       return;
+               }
+               
+               WCF::getDB()->beginTransaction();
+               /** @var Comment $comment */
+               foreach ($this->objectList as $comment) {
+                       // update message
+                       if (!$comment->enableHtml) {
+                               $this->getHtmlInputProcessor()->process($comment->message, 'com.woltlab.wcf.comment', $comment->commentID, true);
+                               
+                               (new CommentEditor($comment))->update([
+                                       'message' => $this->getHtmlInputProcessor()->getHtml(),
+                                       'enableHtml' => 1
+                               ]);
+                       }
+               }
+               WCF::getDB()->commitTransaction();
+       }
+       
+       /**
+        * @return HtmlInputProcessor
+        */
+       protected function getHtmlInputProcessor() {
+               if ($this->htmlInputProcessor === null) {
+                       $this->htmlInputProcessor = new HtmlInputProcessor();
+               }
+               
+               return $this->htmlInputProcessor;
+       }
+}
index 5866f135d2644aad6b9acdaa045365de3a8d8070..14c72a2c7da5d7874d26e4156b1145e44f166135 100644 (file)
@@ -1489,6 +1489,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.article.description"><![CDATA[Aktualisiert den Suchindex für Artikel]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding"><![CDATA[Datenbank-Kodierung konvertieren]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding.description"><![CDATA[Warnung: Die Ausführung dieser Aktion kann bei umfangreichen Datenbanken sehr lange dauern.]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.comment"><![CDATA[Kommentare aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.comment.description"><![CDATA[Aktualisiert die Kommentare]]></item>
        </category>
        
        <category name="wcf.acp.rescueMode">
index 00c3157523bdf6a267859fa1454c35b4c3807791..42d35455b35644c981d9db88b03721e212445c0f 100644 (file)
@@ -1454,6 +1454,8 @@ Examples for medium ID detection:
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.article.description"><![CDATA[Rebuilds the article search index.]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding"><![CDATA[Convert Database Encoding]]></item>
                <item name="wcf.acp.rebuildData.com.woltlab.wcf.databaseConvertEncoding.description"><![CDATA[Warning: This action may take a while to complete on large databases.]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.comment"><![CDATA[Rebuild Comments]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.comment.description"><![CDATA[Rebuilds the comments.]]></item>
        </category>
        
        <category name="wcf.acp.rescueMode">