/** * This function sets the stats for a thread like count, timestamp, etc. */ function phorum_update_thread_info($thread) { $PHORUM = $GLOBALS["PHORUM"]; $messages = phorum_db_get_messages($thread, 0, 1, 1); //these are not needed here unset($messages['users']); // Compute the threadviewcount, based on the individual message views. // This can be useful for updating the view counters after enabling // the view_count_per_thread option. $threadviewcount = 0; foreach ($messages as $id => $message) { $threadviewcount += $message['viewcount']; } // remove hidden/unapproved messages from the array $filtered_messages = array_filter($messages, "phorum_remove_hidden"); $thread_count = count($filtered_messages); if ($thread_count > 0) { $message_ids = array_keys($filtered_messages); sort($message_ids); $parent_message = $filtered_messages[$thread]; // find the latest post in the thread (aka recent_message) $last_message_id_by_time = 0; $last_post_time = 0; foreach ($filtered_messages as $message_id => $message_data) { if ($message_data['datestamp'] > $last_post_time) { $last_post_time = $message_data['datestamp']; $last_message_id_by_time = $message_id; } elseif ($message_data['datestamp'] == $last_post_time && $message_id > $last_message_id_by_time) { $last_post_time = $message_data['datestamp']; $last_message_id_by_time = $message_id; } } $recent_message = $filtered_messages[$last_message_id_by_time]; // prep the message to save $message = array(); $message["thread_count"] = $thread_count; $message["threadviewcount"] = $threadviewcount; $message["modifystamp"] = $recent_message["datestamp"]; $message["recent_message_id"] = $recent_message["message_id"]; $message["recent_user_id"] = $recent_message["user_id"]; $message["recent_author"] = $recent_message["author"]; $message["meta"] = $parent_message["meta"]; // For cleaning up pre-5.2 recent post data. unset($message["meta"]["recent_post"]); $message["meta"]["message_ids"] = $message_ids; // used only for mods $message_ids_moderator = array_keys($messages); sort($message_ids_moderator); $message["meta"]["message_ids_moderator"] = $message_ids_moderator; if ($PHORUM['cache_messages']) { // we can simply store them here again, no need to invalidate the cache // this function is called in any place where we change something to the thread phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-1", $message["meta"]["message_ids"]); phorum_cache_put('message_index', $PHORUM['forum_id'] . "-{$thread}-0", $message["meta"]["message_ids_moderator"]); // but we need to invalidate the main-message as its changed for the recent author/message phorum_cache_remove('message', $thread); } phorum_db_update_message($thread, $message); } }
/** * This function sets the stats for a thread like count, timestamp, etc. */ function phorum_update_thread_info($thread) { $PHORUM = $GLOBALS["PHORUM"]; $messages=phorum_db_get_messages($thread); //these are not needed here unset($messages['users']); // remove hidden/unapproved messages from the array $filtered_messages=array_filter($messages, "phorum_remove_hidden"); $thread_count=count($filtered_messages); if($thread_count>0){ $message_ids=array_keys($filtered_messages); $parent_message=$filtered_messages[$thread]; if (isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) { reset($filtered_messages); $recent_message=current($filtered_messages); } else { $recent_message=end($filtered_messages); } // prep the message to save $message["thread_count"]=$thread_count; $message["modifystamp"]=$recent_message["datestamp"]; $message["meta"]=$parent_message["meta"]; $message["meta"]["recent_post"]["user_id"]=$recent_message["user_id"]; $message["meta"]["recent_post"]["author"]=$recent_message["author"]; $message["meta"]["recent_post"]["message_id"]=$recent_message["message_id"]; $message["meta"]["message_ids"]=$message_ids; // used only for mods $message["meta"]["message_ids_moderator"]=array_keys($messages); phorum_db_update_message($thread, $message); } }
phorum_cache_put('message', $mid, $message); $data[$mid] = $message; $data['users'][] = $data[$mid]['user_id']; } if ($PHORUM['threaded_read'] && isset($PHORUM["reverse_threading"]) && $PHORUM["reverse_threading"]) { krsort($data); } else { ksort($data); } } } else { $data = array('users' => array()); } } else { // Get the thread $data = phorum_db_get_messages($thread, $page); } if ($page > 1 && !isset($data[$thread])) { $first_message = phorum_db_get_message($thread); $data["users"][] = $first_message["user_id"]; $data[$first_message["message_id"]] = $first_message; } //timing_mark("after database"); if (!empty($data) && isset($data[$thread]) && isset($data[$message_id])) { // setup the url-templates needed later $read_url_template_thread = phorum_get_url(PHORUM_READ_URL, '%thread_id%'); $read_url_template_both = phorum_get_url(PHORUM_READ_URL, '%thread_id%', '%message_id%'); $read_page_url_template = phorum_get_url(PHORUM_READ_URL, '%thread_id%', 'page=%page_num%'); $edit_url_template = phorum_get_url(PHORUM_POSTING_URL, '%action_id%', '%message_id%'); $reply_url_template = phorum_get_url(PHORUM_REPLY_URL, '%thread_id%', '%message_id%'); $reply_url_template_quote = phorum_get_url(PHORUM_REPLY_URL, '%thread_id%', '%message_id%', 'quote=1');
/** * Move a thread to another forum. * * @param integer $thread_id * The id of the thread that has to be moved. * * @param integer * The id of the destination forum. */ function phorum_db_move_thread($thread_id, $toforum) { $PHORUM = $GLOBALS['PHORUM']; settype($thread_id, 'int'); settype($toforum, 'int'); if ($toforum > 0 && $thread_id > 0) { // Retrieve the messages from the thread, so we know for which // messages we have to update the newflags and search data below. $thread_messages = phorum_db_get_messages($thread_id); unset($thread_messages['users']); // All we have to do to move the thread to a different forum, // is update the forum_id for the messages in that thread. // Simple, isn't it? phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['message_table']}\n SET forum_id = {$toforum}\n WHERE thread = {$thread_id}", NULL, DB_MASTERQUERY); // Update the stats for the source forum. phorum_db_update_forum_stats(TRUE); // Update the stats for the destination forum. $old_id = $GLOBALS['PHORUM']['forum_id']; $GLOBALS['PHORUM']['forum_id'] = $toforum; phorum_db_update_forum_stats(TRUE); $GLOBALS['PHORUM']['forum_id'] = $old_id; // Move the newflags and search data to the destination forum. /** * @todo In the move thread code, there are some flaws. The * newflags for the user that is moving the message * are used as the source for deciding what flags * to delete or move for all other users. This results * in strange newflag problems. * * This main issue here is that the newflags should be * handled separately for each user; no updates should be * based on the newflags for the active user. The current * algorithm will only make sure that the newflags will look * correct for that specific user. The problem is that we * do not yet have an idea on how to handle this with * enough performance. */ // First, gather information for doing the updates. $new_newflags = phorum_db_newflag_get_flags($toforum); $message_ids = array(); $delete_ids = array(); $search_ids = array(); foreach ($thread_messages as $mid => $data) { // Gather information for updating the newflags. // Moving the newflag is only useful if it is higher than the // min_id of the target forum. if (!empty($new_newflags['min_id'][$toforum]) && $mid > $new_newflags['min_id'][$toforum]) { $message_ids[] = $mid; } else { // Other newflags can be deleted. $delete_ids[] = $mid; } // gather the information for updating the search table $search_ids[] = $mid; } // Move newflags. if (count($message_ids)) { phorum_db_newflag_update_forum($message_ids); } // Update subscriptions. if (count($message_ids)) { $ids_str = implode(', ', $message_ids); phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['subscribers_table']}\n SET forum_id = {$toforum}\n WHERE thread IN ({$ids_str})", NULL, DB_MASTERQUERY); } // Delete newflags. if (count($delete_ids)) { $ids_str = implode(', ', $delete_ids); phorum_db_interact(DB_RETURN_RES, "DELETE FROM {$PHORUM['user_newflags_table']}\n WHERE message_id IN({$ids_str})", NULL, DB_MASTERQUERY); } // Update search data. if (count($search_ids)) { $ids_str = implode(', ', $search_ids); phorum_db_interact(DB_RETURN_RES, "UPDATE {$PHORUM['search_table']}\n SET forum_id = {$toforum}\n WHERE message_id in ({$ids_str})", NULL, DB_MASTERQUERY); } } }
$delids = phorum_db_delete_message($msg["message_id"], $delmode); // Cleanup the attachments for all deleted messages. foreach ($delids as $delid) { $files = phorum_db_get_message_file_list($delid); foreach ($files as $file_id => $data) { phorum_api_file_delete($file_id); } } // For deleted threads, check if we have move notifications // to delete. We unset the forum id, so phorum_db_get_messages() // will return messages with the same thread id in // other forums as well (those are the move notifications). if ($delmode == PHORUM_DELETE_TREE) { $forum_id = $PHORUM["forum_id"]; $PHORUM["forum_id"] = 0; $moved = phorum_db_get_messages($msg["message_id"]); $PHORUM["forum_id"] = $forum_id; foreach ($moved as $id => $data) { if (!empty($data["moved"])) { phorum_db_delete_message($id, PHORUM_DELETE_MESSAGE); } } } } // Run a hook for performing custom actions after cleanup. phorum_hook("delete", $delids); // Keep track of deleted messages ids for counting the deleted // messages at the end. We can't simply add the number of messages // in the message array, because there might be overlap between // messages and threads here. foreach ($delids as $id) {
* } * } * </hookcode> */ if (isset($PHORUM["hooks"]["after_edit"])) { phorum_hook("after_edit", $dbmessage); } // remove the message from the cache if caching is enabled // no need to clear the thread-index as the message has only been changed if ($PHORUM['cache_messages']) { phorum_cache_remove('message', $message["message_id"]); phorum_db_update_forum(array('forum_id' => $PHORUM['forum_id'], 'cache_version' => $PHORUM['cache_version'] + 1)); } // Update children to the same sort setting. if (!$message["parent_id"] && $origmessage["sort"] != $dbmessage["sort"]) { $messages = phorum_db_get_messages($message["thread"], 0); unset($messages["users"]); foreach ($messages as $message_id => $msg) { if ($msg["sort"] != $dbmessage["sort"] || $msg["forum_id"] != $dbmessage["forum_id"]) { $msg["sort"] = $dbmessage["sort"]; phorum_db_update_message($message_id, $msg); if ($PHORUM['cache_messages']) { phorum_cache_remove('message', $message_id); } } } } // Update all thread messages to the same closed setting. if (!$message["parent_id"] && $origmessage["closed"] != $dbmessage["closed"]) { if ($dbmessage["closed"]) { phorum_db_close_thread($message["thread"]);
// this is the last step of a thread merge if (isset($_POST['thread1']) && $_POST['thread1']) { // Commit Thread Merge settype($_POST['thread1'], "int"); settype($_POST['thread'], "int"); // Thread 2 $PHORUM['DATA']['OKMSG'] = $PHORUM["DATA"]['LANG']['MsgMergeOk']; $PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["LIST"]; $PHORUM["reverse_threading"] = 0; // Get the target thread. $target = phorum_db_get_message($_POST['thread1'], "message_id", true); if (!$target) { trigger_error("Can't retrieve target thread " . $_POST['thread1'], E_USER_ERROR); } // Get all messages from the thread that we have to merge. $merge_messages = phorum_db_get_messages($_POST['thread']); unset($merge_messages['users']); // Create new messages in the target thread for // all messages that have to be merged. $msgid_translation = array(); foreach ($merge_messages as $msg) { $oldid = $msg['message_id']; $msg['thread'] = $target['thread']; // the thread we merge with $msg['forum_id'] = $target['forum_id']; // the forum_id of the new thread $msg['sort'] = $target['sort']; // the sort type of the new thread if ($msg['message_id'] == $msg['thread']) { $msg['parent_id'] = $target['thread']; } elseif (isset($msgid_translation[$msg['parent_id']])) {
/** * actually moves a thread to the given forum */ function phorum_db_move_thread($thread_id, $toforum) { $PHORUM = $GLOBALS["PHORUM"]; settype($thread_id, "int"); settype($toforum, "int"); if($toforum > 0 && $thread_id > 0){ $conn = phorum_db_postgresql_connect(); // retrieving the messages for the newflags and search updates below $thread_messages=phorum_db_get_messages($thread_id); // just changing the forum-id, simple isn't it? $sql = "UPDATE {$PHORUM['message_table']} SET forum_id=$toforum where thread=$thread_id"; $res = pg_query($conn, $sql); if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql"); // we need to update the number of posts in the current forum phorum_db_update_forum_stats(true); // and of the new forum $old_id=$GLOBALS["PHORUM"]["forum_id"]; $GLOBALS["PHORUM"]["forum_id"]=$toforum; phorum_db_update_forum_stats(true); $GLOBALS["PHORUM"]["forum_id"]=$old_id; // move the new-flags and the search records for this thread // to the new forum too unset($thread_messages['users']); $new_newflags=phorum_db_newflag_get_flags($toforum); $message_ids = array(); $delete_ids = array(); $search_ids = array(); foreach($thread_messages as $mid => $data) { // gather information for updating the newflags if($mid > $new_newflags['min_id']) { // only using it if its higher than min_id $message_ids[]=$mid; } else { // newflags to delete $delete_ids[]=$mid; } // gather the information for updating the search table $search_ids[] = $mid; } if(count($message_ids)) { // we only go in if there are messages ... otherwise an error occured $ids_str=implode(",",$message_ids); // then doing the update to newflags $sql="UPDATE {$PHORUM['user_newflags_table']} SET forum_id = $toforum where message_id IN($ids_str)"; $res = pg_query($conn, $sql); if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql"); // then doing the update to subscriptions $sql="UPDATE {$PHORUM['subscribers_table']} SET forum_id = $toforum where thread IN($ids_str)"; $res = pg_query($conn, $sql); if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql"); } if(count($delete_ids)) { $ids_str=implode(",",$delete_ids); // then doing the delete $sql="DELETE FROM {$PHORUM['user_newflags_table']} where message_id IN($ids_str)"; pg_query($conn, $sql); if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql"); } if (count($search_ids)) { $ids_str = implode(",",$search_ids); // then doing the search table update $sql = "UPDATE {$PHORUM['search_table']} set forum_id = $toforum where message_id in ($ids_str)"; pg_query($conn, $sql); if ($err = pg_last_error()) phorum_db_pg_last_error("$err: $sql"); } } }