A few changes to topic moving. TOPIC_MOVE constant gets set to the topic_status field so that moved topics don't 'stick' at the top of viewforum. Also, added topic_moved_id field to store the ID that the topic moves to.

git-svn-id: file:///svn/phpbb/trunk@877 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
James Atkinson 2001-08-14 20:43:56 +00:00
parent bd8652f186
commit e2710a5101
5 changed files with 325 additions and 388 deletions

View file

@ -416,6 +416,7 @@ CREATE TABLE phpbb_topics (
topic_status tinyint(3) DEFAULT '0' NOT NULL,
topic_type tinyint(3) DEFAULT '0' NOT NULL,
topic_last_post_id int(11) DEFAULT '0' NOT NULL,
topic_moved_id int(10),
topic_notify tinyint(1) DEFAULT '0' NOT NULL,
PRIMARY KEY (topic_id),
KEY forum_id (forum_id),

View file

@ -412,6 +412,7 @@ CREATE TABLE phpbb_topics (
topic_type int2 DEFAULT '0' NOT NULL,
topic_notify int2 DEFAULT '0',
topic_last_post_id int4 DEFAULT '0' NOT NULL,
topic_moved_id int4,
CONSTRAINT phpbb_topics_pkey PRIMARY KEY (topic_id)
);
CREATE INDEX _phpbb_topics_index ON phpbb_topics (forum_id, topic_id);

View file

@ -40,18 +40,20 @@ define(ADMIN, 1);
define(FORUM_UNLOCKED, 0);
define(FORUM_LOCKED, 1);
// Topic state
// Topic status
define(TOPIC_UNLOCKED, 0);
define(TOPIC_LOCKED, 1);
define(TOPIC_MOVED, 2);
define(TOPIC_WATCH_NOTIFIED, 1);
define(TOPIC_WATCH_UN_NOTIFIED, 0);
// Topic types
define(POST_NORMAL, 0);
define(POST_STICKY, 1);
define(POST_ANNOUNCE, 2);
define(POST_GLOBAL_ANNOUNCE, 3);
define(TOPIC_MOVED,4);
// SQL codes
define(BEGIN_TRANSACTION, 1);

View file

@ -315,8 +315,7 @@ switch($mode)
topic_id = $topics[$x]";
if(!$result = $db->sql_query($sql_select))
{
message_die(GENERAL_ERROR, "Could not select from topic table!", "Error", __LINE__, __FILE__
, $sql_select);
message_die(GENERAL_ERROR, "Could not select from topic table!", "Error", __LINE__, __FILE__, $sql_select);
}
else
{
@ -325,13 +324,12 @@ switch($mode)
$tpost = $row[0]['topic_poster'];
$ttime = $row[0]['topic_time'];
$sql_insert = 'INSERT INTO '.TOPICS_TABLE."
(forum_id,topic_title,topic_poster,topic_time,topic_status,topic_type)
(forum_id, topic_title, topic_poster, topic_time, topic_moved_id, topic_status)
VALUES
($old_forum, '$ttitle', '$tpost', $ttime, $topics[$x], ".TOPIC_MOVED.')';
if(!$result = $db->sql_query($sql_insert))
{
message_die(GENERAL_ERROR, "Could not insert into topics table!", "Error", __LINE__,
__FILE__, $sql_insert);
message_die(GENERAL_ERROR, "Could not insert into topics table!", "Error", __LINE__, __FILE__, $sql_insert);
}
$newtopic_id = $db->sql_nextid();
$sql_insert = 'INSERT INTO '.POSTS_TABLE."
@ -340,16 +338,15 @@ switch($mode)
($newtopic_id,$old_forum,$tpost,$ttime)";
if(!$result = $db->sql_query($sql_insert))
{
message_die(GENERAL_ERROR, "Could not insert into posts table!", "Error", __LINE__,
__FILE__, $sql_insert);
message_die(GENERAL_ERROR, "Could not insert into posts table!", "Error", __LINE__, __FILE__, $sql_insert);
}
//Finally, update the last_post_id column to reflect the new post just inserted
$newpost_id = $db->sql_nextid();
$sql = 'UPDATE '.TOPICS_TABLE." SET topic_last_post_id = $newpost_id WHERE topic_id = $newtopic_id";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not update the topics table!", "Error", __LINE__,
__FILE__, $sql);
message_die(GENERAL_ERROR, "Could not update the topics table!", "Error", __LINE__, __FILE__, $sql);
}
}
}
@ -375,72 +372,12 @@ __FILE__, $sql);
{
message_die(GENERAL_ERROR, "Could not update topics table!", "Error", __LINE__, __FILE__, $sql_topic);
}
if(SQL_LAYER != 'mysql')
{
$sql_forums_new = 'UPDATE '.FORUMS_TABLE." SET
forum_posts = forum_posts + $posts,
forum_topics = forum_topics + ".count($topics).",
forum_last_post_id =
(select max(post_id) FROM ".POSTS_TABLE."
WHERE forum_id = $new_forum)
WHERE forum_id = ".$new_forum;
$sql_forums_old = 'UPDATE '.FORUMS_TABLE." SET
forum_posts = forum_posts - $posts + ".count($topics).",
forum_last_post_id =
(select max(post_id) FROM ".POSTS_TABLE."
WHERE forum_id = $old_forum)
WHERE forum_id = ".$old_forum;
}
else
{
$sql_lastpost = "select max(post_id) AS last_post FROM ".POSTS_TABLE." WHERE forum_id = $new_forum";
if(!$result = $db->sql_query($sql_lastpost))
{
message_die(GENERAL_ERROR, "Could not get last post id from posts table", "Error", __LINE__,__FILE__, $sql_lastpost);
}
else
{
$last_post_row = $db->sql_fetchrowset($result);
$last_post_new = $last_post_row[0]['last_post'];
if($last_post_new == "")
{
$last_post_new = "''";
}
}
$sql_lastpost = "select max(post_id) AS last_post FROM ".POSTS_TABLE." WHERE forum_id = $old_forum";
if(!$result = $db->sql_query($sql_lastpost))
{
message_die(GENERAL_ERROR, "Could not get last post id from posts table", "Error", __LINE__,__FILE__, $sql_lastpost);
}
else
{
$last_post_row = $db->sql_fetchrowset($result);
$last_post_old = $last_post_row[0]['last_post'];
if($last_post_old == "")
{
$last_post_old = "''";
}
}
$sql_forums_new = 'UPDATE '.FORUMS_TABLE." SET
forum_posts = forum_posts + $posts,
forum_topics = forum_topics + ".count($topics).",
forum_last_post_id = $last_post_new
WHERE forum_id = $new_forum";
$sql_forums_old = 'UPDATE '.FORUMS_TABLE." SET
forum_posts = forum_posts - $posts + ".count($topics).",
forum_last_post_id = $last_post_old
WHERE forum_id = $old_forum";
}
if(!$result = $db->sql_query($sql_forums_new))
{
message_die(GENERAL_ERROR, "Could not update forums table!", "Error", __LINE__, __FILE__, $sql_forums_new);
}
else if(!$result = $db->sql_query($sql_forums_old))
{
message_die(GENERAL_ERROR, "Could not update forums table!", "Error", __LINE__, __FILE__, $sql_forums_old);
}
else
{
// Sync the forum indexes
sync("forum", $new_forum);
sync("forum", $old_forum);
if($quick_op)
{
$next_page = "viewtopic.$phpEx?".POST_TOPIC_URL."=$topic_id";
@ -454,7 +391,6 @@ __FILE__, $sql);
$msg = $lang['Topics_Moved'] . "<br />" . "<a href=\"".append_sid($next_page)."\">". $lang['Click']. " " . $lang['Here'] ."</a> " . $return_message;
message_die(GENERAL_MESSAGE, $msg);
}
}
else
{
$hidden_fields = '<input type="hidden" name="mode" value="'.$mode.'"><input type="hidden" name="'.POST_FORUM_URL.'" value="'.$forum_id.'"><input type="hidden" name="quick_op" value="'.$quick_op.'">';
@ -471,15 +407,12 @@ __FILE__, $sql);
{
$hidden_fields .= '<input type="hidden" name="'.POST_TOPIC_URL.'" value="'.$topic_id.'">';
}
$template->assign_vars( array (
"MESSAGE_TITLE" => $lang['Confirm'],
$template->assign_vars(array("MESSAGE_TITLE" => $lang['Confirm'],
"MESSAGE_TEXT" => $lang['Confirm_move_topic'],
"L_YES" => $lang['Yes'],
"L_NO" => $lang['No'],
"S_CONFIRM_ACTION" => append_sid("modcp.$phpEx"),
"S_HIDDEN_FIELDS" => $hidden_fields
)
);
"S_HIDDEN_FIELDS" => $hidden_fields));
$template->pparse("confirm");
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}

View file

@ -380,18 +380,12 @@ if($total_topics || $total_announcements)
{
$topic_type = $lang['Topic_Sticky'] . " ";
}
else if($topic_type == TOPIC_MOVED)
{
$topic_type = $lang['Topic_Moved'] . " ";
//New topic is hidden in topic_status
$topic_rowset[$i]['topic_id'] = $topic_rowset[$i]['topic_status'];
$topic_rowset[$i]['topic_status'] = TOPIC_UNLOCKED;
}
else
{
$topic_type = "";
}
$topic_id = $topic_rowset[$i]['topic_id'];
$replies = $topic_rowset[$i]['topic_replies'];
@ -431,6 +425,12 @@ if($total_topics || $total_announcements)
{
$folder_image = "<img src=\"" . $images['folder_locked'] . "\" alt=\"" . $lang['Topic_locked'] . "\" />";
}
else if($topic_rowset[$i]['topic_status'] == TOPIC_MOVED)
{
$topic_type = $lang['Topic_Moved'] . " ";
$topic_id = $topic_rowset[$i]['topic_moved_id'];
}
else
{