From 336dfb2945dddac5a3e95c3da4039cc753d75fa6 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 12 Jul 2013 16:33:13 +0200 Subject: [PATCH] Added rebuild data workers --- ...ersationMessageRebuildDataWorker.class.php | 52 ++++++++ .../ConversationRebuildDataWorker.class.php | 119 ++++++++++++++++++ language/de.xml | 5 + language/en.xml | 5 + objectType.xml | 14 +++ 5 files changed, 195 insertions(+) create mode 100644 files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php create mode 100644 files/lib/system/worker/ConversationRebuildDataWorker.class.php diff --git a/files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php b/files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php new file mode 100644 index 0000000..4d5408f --- /dev/null +++ b/files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php @@ -0,0 +1,52 @@ + + * @package com.woltlab.wcf + * @subpackage system.worker + * @category Community Framework + */ +class ConversationMessageRebuildDataWorker extends AbstractRebuildDataWorker { + /** + * @see wcf\system\worker\AbstractRebuildDataWorker::$objectListClassName + */ + protected $objectListClassName = 'wcf\data\conversation\message\ConversationMessageList'; + + /** + * @see wcf\system\worker\AbstractWorker::$limit + */ + protected $limit = 500; + + /** + * @see wcf\system\worker\AbstractRebuildDataWorker::initObjectList + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->objectList->sqlOrderBy = 'conversation_message.messageID'; + $this->objectList->sqlSelects = 'conversation.subject'; + $this->objectList->sqlJoins = 'LEFT JOIN wcf'.WCF_N.'_conversation conversation ON (conversation.firstMessageID = conversation_message.messageID)'; + } + + /** + * @see wcf\system\worker\IWorker::execute() + */ + public function execute() { + parent::execute(); + + if (!$this->loopCount) { + // reset search index + SearchIndexManager::getInstance()->reset('com.woltlab.wcf.conversation.message'); + } + + foreach ($this->objectList as $message) { + SearchIndexManager::getInstance()->add('com.woltlab.wcf.conversation.message', $message->messageID, $message->message, ($message->subject ?: ''), $message->time, $message->userID, $message->username); + } + } +} diff --git a/files/lib/system/worker/ConversationRebuildDataWorker.class.php b/files/lib/system/worker/ConversationRebuildDataWorker.class.php new file mode 100644 index 0000000..43e3c79 --- /dev/null +++ b/files/lib/system/worker/ConversationRebuildDataWorker.class.php @@ -0,0 +1,119 @@ + + * @package com.woltlab.wcf + * @subpackage system.worker + * @category Community Framework + */ +class ConversationRebuildDataWorker extends AbstractRebuildDataWorker { + /** + * @see wcf\system\worker\AbstractRebuildDataWorker::$objectListClassName + */ + protected $objectListClassName = 'wcf\data\conversation\ConversationList'; + + /** + * @see wcf\system\worker\AbstractWorker::$limit + */ + protected $limit = 100; + + /** + * @see wcf\system\worker\AbstractRebuildDataWorker::initObjectList + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->objectList->sqlOrderBy = 'conversation.conversationID'; + } + + /** + * @see wcf\system\worker\IWorker::execute() + */ + public function execute() { + parent::execute(); + + // prepare statements + $sql = "SELECT messageID, time, userID, username + FROM wcf".WCF_N."_conversation_message + WHERE conversationID = ? + ORDER BY time"; + $firstMessageStatement = WCF::getDB()->prepareStatement($sql, 1); + $sql = "SELECT time, userID, username + FROM wcf".WCF_N."_conversation_message + WHERE conversationID = ? + ORDER BY time DESC"; + $lastMessageStatement = WCF::getDB()->prepareStatement($sql, 1); + $sql = "SELECT COUNT(*) AS messages, + SUM(attachments) AS attachments + FROM wcf".WCF_N."_conversation_message + WHERE conversationID = ?"; + $statsStatement = WCF::getDB()->prepareStatement($sql); + $sql = "SELECT COUNT(*) AS participants + FROM wcf".WCF_N."_conversation_to_user conversation_to_user + WHERE conversation_to_user.conversationID = ? + AND conversation_to_user.hideConversation <> ? + AND conversation_to_user.participantID <> ? + AND conversation_to_user.isInvisible = ?"; + $participantCounterStatement = WCF::getDB()->prepareStatement($sql); + $sql = "SELECT conversation_to_user.participantID AS userID, conversation_to_user.hideConversation, user_table.username + FROM wcf".WCF_N."_conversation_to_user conversation_to_user + LEFT JOIN wcf".WCF_N."_user user_table + ON (user_table.userID = conversation_to_user.participantID) + WHERE conversation_to_user.conversationID = ? + AND conversation_to_user.participantID <> ? + AND conversation_to_user.isInvisible = ? + ORDER BY user_table.username"; + $participantStatement = WCF::getDB()->prepareStatement($sql); + + foreach ($this->objectList as $conversation) { + $editor = new ConversationEditor($conversation); + $data = array(); + + // get first post + $firstMessageStatement->execute(array($conversation->conversationID)); + if (($row = $firstMessageStatement->fetchArray()) !== false) { + $data['firstMessageID'] = $row['messageID']; + $data['time'] = $row['time']; + $data['userID'] = $row['userID']; + $data['username'] = $row['username']; + } + + // get last post + $lastMessageStatement->execute(array($conversation->conversationID)); + if (($row = $lastMessageStatement->fetchArray()) !== false) { + $data['lastPostTime'] = $row['time']; + $data['lastPosterID'] = $row['userID']; + $data['lastPoster'] = $row['username']; + } + + // get stats + $statsStatement->execute(array($conversation->conversationID)); + $row = $statsStatement->fetchArray(); + $data['replies'] = ($row['messages'] ? $row['messages'] - 1 : 0); + $data['attachments'] = ($row['attachments'] ?: 0); + + // get number of participants + $participantCounterStatement->execute(array($conversation->conversationID, Conversation::STATE_LEFT, $conversation->userID, 0)); + $row = $participantCounterStatement->fetchArray(); + $data['participants'] = $row['participants']; + + // get participant summary + $participantStatement->execute(array($conversation->conversationID, $conversation->userID, 0)); + $users = array(); + while ($row = $participantStatement->fetchArray()) { + $users[] = $row; + } + $data['participantSummary'] = serialize($users); + + $editor->update($data); + } + } +} diff --git a/language/de.xml b/language/de.xml index 0652dce..dc115bf 100644 --- a/language/de.xml +++ b/language/de.xml @@ -28,6 +28,11 @@ + + + + + diff --git a/language/en.xml b/language/en.xml index f575bae..ceff824 100644 --- a/language/en.xml +++ b/language/en.xml @@ -28,6 +28,11 @@ + + + + + diff --git a/objectType.xml b/objectType.xml index 83e22a3..19fb464 100644 --- a/objectType.xml +++ b/objectType.xml @@ -115,5 +115,19 @@ + + + + com.woltlab.wcf.conversation + com.woltlab.wcf.rebuildData + + -5 + + + com.woltlab.wcf.conversation.message + com.woltlab.wcf.rebuildData + + + \ No newline at end of file -- 2.20.1