function testCreateThreadOfMessages() { $message1 = new Phorum_message(); $message1->create(1, 'Message 1', 'la la'); $message2 = new Phorum_message(); $message2->create(1, 'Message 2', 'wow', $message1->getThreadId(), $message1->getMessageId()); $message3 = new Phorum_message(); $message3->create(1, 'Message 3', 'cool', $message1->getThreadId(), $message1->getMessageId()); $messages = Phorum_message::GetMessages(array("thread" => $message1->getThreadId())); if (count($messages) != 3) { $this->fail("Creating a thread of messages failed."); } $message1->delete(PHORUM_DELETE_TREE); $message2->fetch(); $message3->fetch(); if ($message2->exists() || $message3->exists()) { $this->fail("Thread not deleted correctly"); } } // fn testCreateThreadOfMessages
/** * Update the thread info. * Thread info is stored in the first message in the thread. * The first message in the thread is the one where * the message_id is equal to the thread_id. * * This code is mainly copied from phorum_update_thread_info(), * but that function uses phorum_db_get_messages(), * which uses external function calls to APIs outside of * mysql.php, which we want to avoid. * * @return void */ private function __updateThreadInfo() { $thread_id = $this->m_data['thread']; $searchConditions = array("thread" => $thread_id, "forum_id" => $this->m_data['forum_id'], "status" => PHORUM_STATUS_APPROVED); $messages = Phorum_message::GetMessages($searchConditions); $thread_count = count($messages); // If there are any messages left in the thread, // then update the thread data. if ($thread_count > 0) { $threadBeginMessage = array(); $message_ids = array_keys($messages); if (isset($messages[$thread_id])) { $parent_message = $messages[$thread_id]; // Paul Baranowski: my hack so that multiple top-level messages // are allowed within a thread. Disabled but here for // reference, because this worked. // $parent_message = isset($messages[$thread_id]) ? $messages[$thread_id] : current($messages); // $thread_id = $parent_message->getMessageId(); // The most recent message in the thread. $recent_message = end($messages); // Updates to the first thread message. $threadBeginMessage["thread_count"] = $thread_count; $threadBeginMessage["modifystamp"] = $recent_message->m_data["datestamp"]; $threadBeginMessage["meta"] = $parent_message->m_data["meta"]; $threadBeginMessage["meta"]["recent_post"]["user_id"] = $recent_message->m_data["user_id"]; $threadBeginMessage["meta"]["recent_post"]["author"] = $recent_message->m_data["author"]; $threadBeginMessage["meta"]["recent_post"]["message_id"] = $recent_message->m_data["message_id"]; $threadBeginMessage["meta"]["message_ids"] = $message_ids; // Used only for mods // Get the message IDs of all messages in the thread, // regardless of status. // // ??? Note: why are these stored in this way? // Why not just grab these from the database when you // want them - it would probably be just as fast. $searchConditions = array("thread" => $thread_id, "forum_id" => $this->m_data['forum_id']); $allMessages = Phorum_message::GetMessages($searchConditions); $threadBeginMessage["meta"]["message_ids_moderator"] = array_keys($allMessages); phorum_db_update_message($thread_id, $threadBeginMessage); } } } // fn __updateThreadInfo