From: Alexander Ebert Date: Thu, 2 Mar 2017 19:03:03 +0000 (+0100) Subject: Added rebuild data worker for comments X-Git-Tag: 3.1.0_Alpha_1~619 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7d00c4eb6694bdbedaa0b653922e72d6416b8993;p=GitHub%2FWoltLab%2FWCF.git Added rebuild data worker for comments See #2222 --- diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 45d5888da3..ea76c95669 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -384,6 +384,12 @@ wcf\system\worker\StatDailyRebuildDataWorker 110 + + com.woltlab.wcf.comment + com.woltlab.wcf.rebuildData + wcf\system\worker\CommentRebuildDataWorker + 120 + 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 index 0000000000..f572328264 --- /dev/null +++ b/wcfsetup/install/files/lib/system/worker/CommentRebuildDataWorker.class.php @@ -0,0 +1,91 @@ + + * @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; + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 5866f135d2..14c72a2c7d 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1489,6 +1489,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]> + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 00c3157523..42d35455b3 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1454,6 +1454,8 @@ Examples for medium ID detection: + +