Added rebuild data workers
authorMarcel Werk <burntime@woltlab.com>
Fri, 12 Jul 2013 14:33:13 +0000 (16:33 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 12 Jul 2013 14:33:13 +0000 (16:33 +0200)
files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php [new file with mode: 0644]
files/lib/system/worker/ConversationRebuildDataWorker.class.php [new file with mode: 0644]
language/de.xml
language/en.xml
objectType.xml

diff --git a/files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php b/files/lib/system/worker/ConversationMessageRebuildDataWorker.class.php
new file mode 100644 (file)
index 0000000..4d5408f
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+namespace wcf\system\worker;
+use wcf\system\search\SearchIndexManager;
+
+/**
+ * Worker implementation for updating conversation messages.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2013 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 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 (file)
index 0000000..43e3c79
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+namespace wcf\system\worker;
+use wcf\data\conversation\Conversation;
+use wcf\data\conversation\ConversationEditor;
+use wcf\system\WCF;
+
+/**
+ * Worker implementation for updating conversations.
+ * 
+ * @author     Marcel Werk
+ * @copyright  2001-2013 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 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);
+               }
+       }
+}
index 0652dce08e9fd0ee527f7835a8c16c9b77b73487..dc115bf74ebdbe33ca06fcea58bb363483a124da 100644 (file)
                <item name="wcf.acp.option.conversation_reply_show_messages_max.description"><![CDATA[Anzahl der letzten Antworten auf eine Konversation, die beim Erstellen einer Antwort unter dem Eingabeformular angezeigt werden.]]></item>
        </category>
        
+       <category name="wcf.acp.rebuildData">
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.conversation"><![CDATA[Konversationen aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.conversation.message"><![CDATA[Konversationsnachrichten aktualisieren]]></item>
+       </category>
+       
        <category name="wcf.clipboard">
                <item name="wcf.clipboard.item.com.woltlab.wcf.conversation.conversation.assignLabel"><![CDATA[Label zuweisen ({#$count})]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.conversation.conversation.close"><![CDATA[Schließen ({#$count})]]></item>
index f575baef8b24879b9fbcb6b79e7abbe6dc12442f..ceff82468a94ef58e75f47cedcdc70a3d29574be 100644 (file)
                <item name="wcf.acp.option.conversation_reply_show_messages_max.description"><![CDATA[Number of previous messages displayed on extended reply form.]]></item>
        </category>
        
+       <category name="wcf.acp.rebuildData">
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.conversation"><![CDATA[TODO: Konversationen aktualisieren]]></item>
+               <item name="wcf.acp.rebuildData.com.woltlab.wcf.conversation.message"><![CDATA[TODO: Konversationsnachrichten aktualisieren]]></item>
+       </category>
+       
        <category name="wcf.clipboard">
                <item name="wcf.clipboard.item.com.woltlab.wcf.conversation.conversation.assignLabel"><![CDATA[Assign Label ({#$count})]]></item>
                <item name="wcf.clipboard.item.com.woltlab.wcf.conversation.conversation.close"><![CDATA[Close ({#$count})]]></item>
index 83e22a37c446a0400b67a61df3b576dd17403bfb..19fb464a27dfa0cb8d2a3e2e27602dea9c7e652c 100644 (file)
                        <classname><![CDATA[wcf\system\importer\ConversationAttachmentImporter]]></classname>
                </type>
                <!-- /importers -->
+               
+               <!-- rebuild data workers -->
+               <type>
+                       <name>com.woltlab.wcf.conversation</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname><![CDATA[wcf\system\worker\ConversationRebuildDataWorker]]></classname>
+                       <nicevalue>-5</nicevalue>
+               </type>
+               <type>
+                       <name>com.woltlab.wcf.conversation.message</name>
+                       <definitionname>com.woltlab.wcf.rebuildData</definitionname>
+                       <classname><![CDATA[wcf\system\worker\ConversationMessageRebuildDataWorker]]></classname>
+               </type>
+               <!-- /rebuild data workers -->
        </import>
 </data>
\ No newline at end of file