/** * Rebuilds the conversation data of the relevant conversations. */ public function rebuild() { if (empty($this->objects)) { $this->readObjects(); } // collect number of messages for each conversation $conditionBuilder = new PreparedStatementConditionBuilder(); $conditionBuilder->add('conversation_message.conversationID IN (?)', array($this->objectIDs)); $sql = "SELECT\t\tconversationID, COUNT(messageID) AS messages, SUM(attachments) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_message conversation_message\n\t\t\t" . $conditionBuilder . "\n\t\t\tGROUP BY\tconversationID"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute($conditionBuilder->getParameters()); $objectIDs = array(); while ($row = $statement->fetchArray()) { if (!$row['messages']) { continue; } $objectIDs[] = $row['conversationID']; $conversationEditor = new ConversationEditor(new Conversation(null, array('conversationID' => $row['conversationID']))); $conversationEditor->update(array('attachments' => $row['attachments'], 'replies' => $row['messages'] - 1)); $conversationEditor->updateFirstMessage(); $conversationEditor->updateLastMessage(); } // delete conversations without messages $deleteConversationIDs = array_diff($this->objectIDs, $objectIDs); if (!empty($deleteConversationIDs)) { $conversationAction = new ConversationAction($deleteConversationIDs, 'delete'); $conversationAction->executeAction(); } }