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_status tinyint(3) DEFAULT '0' NOT NULL,
topic_type 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_last_post_id int(11) DEFAULT '0' NOT NULL,
topic_moved_id int(10),
topic_notify tinyint(1) DEFAULT '0' NOT NULL, topic_notify tinyint(1) DEFAULT '0' NOT NULL,
PRIMARY KEY (topic_id), PRIMARY KEY (topic_id),
KEY forum_id (forum_id), KEY forum_id (forum_id),

View file

@ -412,6 +412,7 @@ CREATE TABLE phpbb_topics (
topic_type int2 DEFAULT '0' NOT NULL, topic_type int2 DEFAULT '0' NOT NULL,
topic_notify int2 DEFAULT '0', topic_notify int2 DEFAULT '0',
topic_last_post_id int4 DEFAULT '0' NOT NULL, topic_last_post_id int4 DEFAULT '0' NOT NULL,
topic_moved_id int4,
CONSTRAINT phpbb_topics_pkey PRIMARY KEY (topic_id) CONSTRAINT phpbb_topics_pkey PRIMARY KEY (topic_id)
); );
CREATE INDEX _phpbb_topics_index ON phpbb_topics (forum_id, 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_UNLOCKED, 0);
define(FORUM_LOCKED, 1); define(FORUM_LOCKED, 1);
// Topic state // Topic status
define(TOPIC_UNLOCKED, 0); define(TOPIC_UNLOCKED, 0);
define(TOPIC_LOCKED, 1); define(TOPIC_LOCKED, 1);
define(TOPIC_MOVED, 2);
define(TOPIC_WATCH_NOTIFIED, 1); define(TOPIC_WATCH_NOTIFIED, 1);
define(TOPIC_WATCH_UN_NOTIFIED, 0); define(TOPIC_WATCH_UN_NOTIFIED, 0);
// Topic types // Topic types
define(POST_NORMAL, 0); define(POST_NORMAL, 0);
define(POST_STICKY, 1); define(POST_STICKY, 1);
define(POST_ANNOUNCE, 2); define(POST_ANNOUNCE, 2);
define(POST_GLOBAL_ANNOUNCE, 3); define(POST_GLOBAL_ANNOUNCE, 3);
define(TOPIC_MOVED,4);
// SQL codes // SQL codes
define(BEGIN_TRANSACTION, 1); define(BEGIN_TRANSACTION, 1);

View file

@ -287,203 +287,136 @@ switch($mode)
break; break;
case 'move': case 'move':
if($confirm) if($confirm)
{ {
$new_forum = $HTTP_POST_VARS['new_forum']; $new_forum = $HTTP_POST_VARS['new_forum'];
$old_forum = $HTTP_POST_VARS[POST_FORUM_URL]; $old_forum = $HTTP_POST_VARS[POST_FORUM_URL];
if($HTTP_POST_VARS['preform_op']) if($HTTP_POST_VARS['preform_op'])
{ {
$topics = $HTTP_POST_VARS['preform_op']; $topics = $HTTP_POST_VARS['preform_op'];
} }
else else
{ {
$topics = array($HTTP_POST_VARS[POST_TOPIC_URL]); $topics = array($HTTP_POST_VARS[POST_TOPIC_URL]);
} }
for($x = 0; $x < count($topics); $x++) for($x = 0; $x < count($topics); $x++)
{ {
if($x != 0) if($x != 0)
{ {
$sql_clause .= ' OR '; $sql_clause .= ' OR ';
} }
$sql_clause .= 'topic_id = '.$topics[$x]; $sql_clause .= 'topic_id = '.$topics[$x];
$sql_select = 'SELECT $sql_select = 'SELECT
topic_title, topic_title,
topic_poster, topic_poster,
topic_time topic_time
FROM '. FROM '.
TOPICS_TABLE." WHERE TOPICS_TABLE." WHERE
topic_id = $topics[$x]"; topic_id = $topics[$x]";
if(!$result = $db->sql_query($sql_select)) if(!$result = $db->sql_query($sql_select))
{ {
message_die(GENERAL_ERROR, "Could not select from topic table!", "Error", __LINE__, __FILE__ message_die(GENERAL_ERROR, "Could not select from topic table!", "Error", __LINE__, __FILE__, $sql_select);
, $sql_select); }
} else
else {
{ $row = $db->sql_fetchrowset($result);
$row = $db->sql_fetchrowset($result); $ttitle = $row[0]['topic_title'];
$ttitle = $row[0]['topic_title']; $tpost = $row[0]['topic_poster'];
$tpost = $row[0]['topic_poster']; $ttime = $row[0]['topic_time'];
$ttime = $row[0]['topic_time']; $sql_insert = 'INSERT INTO '.TOPICS_TABLE."
$sql_insert = 'INSERT INTO '.TOPICS_TABLE." (forum_id, topic_title, topic_poster, topic_time, topic_moved_id, topic_status)
(forum_id,topic_title,topic_poster,topic_time,topic_status,topic_type) VALUES
VALUES ($old_forum, '$ttitle', '$tpost', $ttime, $topics[$x], ".TOPIC_MOVED.')';
($old_forum,'$ttitle','$tpost',$ttime,$topics[$x],".TOPIC_MOVED.')'; if(!$result = $db->sql_query($sql_insert))
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."
$newtopic_id = $db->sql_nextid(); (topic_id,forum_id,poster_id,post_time)
$sql_insert = 'INSERT INTO '.POSTS_TABLE." VALUES
(topic_id,forum_id,poster_id,post_time) ($newtopic_id,$old_forum,$tpost,$ttime)";
VALUES if(!$result = $db->sql_query($sql_insert))
($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);
}
}
}
$sql_replies = 'SELECT SUM(topic_replies) AS total_posts FROM '.TOPICS_TABLE.' WHERE '.$sql_clause; //Finally, update the last_post_id column to reflect the new post just inserted
if(!$result = $db->sql_query($sql_replies)) $newpost_id = $db->sql_nextid();
{ $sql = 'UPDATE '.TOPICS_TABLE." SET topic_last_post_id = $newpost_id WHERE topic_id = $newtopic_id";
message_die(GENERAL_ERROR, "Could not sum topic replies in topics table!", "Error", __LINE__, __FILE__, $sql_replies); if(!$result = $db->sql_query($sql))
} {
else message_die(GENERAL_ERROR, "Could not update the topics table!", "Error", __LINE__, __FILE__, $sql);
{ }
$posts_row = $db->sql_fetchrowset($result); }
$posts = $posts_row[0]['total_posts'] + count($topics); }
}
$sql_post = 'UPDATE '.POSTS_TABLE." SET forum_id = $new_forum WHERE $sql_clause"; $sql_replies = 'SELECT SUM(topic_replies) AS total_posts FROM '.TOPICS_TABLE.' WHERE '.$sql_clause;
$sql_topic = 'UPDATE '.TOPICS_TABLE." SET forum_id = $new_forum WHERE $sql_clause"; if(!$result = $db->sql_query($sql_replies))
if(!$result = $db->sql_query($sql_post)) {
{ message_die(GENERAL_ERROR, "Could not sum topic replies in topics table!", "Error", __LINE__, __FILE__, $sql_replies);
message_die(GENERAL_ERROR, "Could not update posts table!", "Error", __LINE__, __FILE__, $sql_post); }
} else
else if(!$result = $db->sql_query($sql_topic)) {
{ $posts_row = $db->sql_fetchrowset($result);
message_die(GENERAL_ERROR, "Could not update topics table!", "Error", __LINE__, __FILE__, $sql_topic); $posts = $posts_row[0]['total_posts'] + count($topics);
} }
if(SQL_LAYER != 'mysql')
{ $sql_post = 'UPDATE '.POSTS_TABLE." SET forum_id = $new_forum WHERE $sql_clause";
$sql_forums_new = 'UPDATE '.FORUMS_TABLE." SET $sql_topic = 'UPDATE '.TOPICS_TABLE." SET forum_id = $new_forum WHERE $sql_clause";
forum_posts = forum_posts + $posts, if(!$result = $db->sql_query($sql_post))
forum_topics = forum_topics + ".count($topics).", {
forum_last_post_id = message_die(GENERAL_ERROR, "Could not update posts table!", "Error", __LINE__, __FILE__, $sql_post);
(select max(post_id) FROM ".POSTS_TABLE." }
WHERE forum_id = $new_forum) else if(!$result = $db->sql_query($sql_topic))
WHERE forum_id = ".$new_forum; {
$sql_forums_old = 'UPDATE '.FORUMS_TABLE." SET message_die(GENERAL_ERROR, "Could not update topics table!", "Error", __LINE__, __FILE__, $sql_topic);
forum_posts = forum_posts - $posts + ".count($topics).", }
forum_last_post_id =
(select max(post_id) FROM ".POSTS_TABLE." // Sync the forum indexes
WHERE forum_id = $old_forum) sync("forum", $new_forum);
WHERE forum_id = ".$old_forum; sync("forum", $old_forum);
}
else
{ if($quick_op)
$sql_lastpost = "select max(post_id) AS last_post FROM ".POSTS_TABLE." WHERE forum_id = $new_forum"; {
if(!$result = $db->sql_query($sql_lastpost)) $next_page = "viewtopic.$phpEx?".POST_TOPIC_URL."=$topic_id";
{ $return_message = $lang['to_return_topic'];
message_die(GENERAL_ERROR, "Could not get last post id from posts table", "Error", __LINE__,__FILE__, $sql_lastpost); }
} else
else {
{ $next_page = "modcp.$phpEx?".POST_FORUM_URL."=$forum_id";
$last_post_row = $db->sql_fetchrowset($result); $return_message = $lang['Return_to_modcp'];
$last_post_new = $last_post_row[0]['last_post']; }
if($last_post_new == "") $msg = $lang['Topics_Moved'] . "<br />" . "<a href=\"".append_sid($next_page)."\">". $lang['Click']. " " . $lang['Here'] ."</a> " . $return_message;
{ message_die(GENERAL_MESSAGE, $msg);
$last_post_new = "''"; }
} else
} {
$sql_lastpost = "select max(post_id) AS last_post FROM ".POSTS_TABLE." WHERE forum_id = $old_forum"; $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.'">';
if(!$result = $db->sql_query($sql_lastpost)) $hidden_fields .= $lang['New_forum'] . ': ' . make_forum_box('new_forum'). '</select><br><br>';
{ if($HTTP_POST_VARS['preform_op'])
message_die(GENERAL_ERROR, "Could not get last post id from posts table", "Error", __LINE__,__FILE__, $sql_lastpost); {
} $topics = $HTTP_POST_VARS['preform_op'];
else for($x = 0; $x < count($topics); $x++)
{ {
$last_post_row = $db->sql_fetchrowset($result); $hidden_fields .= '<input type="hidden" name="preform_op[]" value="'.$topics[$x].'">';
$last_post_old = $last_post_row[0]['last_post']; }
if($last_post_old == "") }
{ else
$last_post_old = "''"; {
} $hidden_fields .= '<input type="hidden" name="'.POST_TOPIC_URL.'" value="'.$topic_id.'">';
} }
$sql_forums_new = 'UPDATE '.FORUMS_TABLE." SET $template->assign_vars(array("MESSAGE_TITLE" => $lang['Confirm'],
forum_posts = forum_posts + $posts, "MESSAGE_TEXT" => $lang['Confirm_move_topic'],
forum_topics = forum_topics + ".count($topics).", "L_YES" => $lang['Yes'],
forum_last_post_id = $last_post_new "L_NO" => $lang['No'],
WHERE forum_id = $new_forum"; "S_CONFIRM_ACTION" => append_sid("modcp.$phpEx"),
$sql_forums_old = 'UPDATE '.FORUMS_TABLE." SET "S_HIDDEN_FIELDS" => $hidden_fields));
forum_posts = forum_posts - $posts + ".count($topics).", $template->pparse("confirm");
forum_last_post_id = $last_post_old include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
WHERE forum_id = $old_forum"; }
} break;
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
{
if($quick_op)
{
$next_page = "viewtopic.$phpEx?".POST_TOPIC_URL."=$topic_id";
$return_message = $lang['to_return_topic'];
}
else
{
$next_page = "modcp.$phpEx?".POST_FORUM_URL."=$forum_id";
$return_message = $lang['Return_to_modcp'];
}
$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.'">';
$hidden_fields .= $lang['New_forum'] . ': ' . make_forum_box('new_forum'). '</select><br><br>';
if($HTTP_POST_VARS['preform_op'])
{
$topics = $HTTP_POST_VARS['preform_op'];
for($x = 0; $x < count($topics); $x++)
{
$hidden_fields .= '<input type="hidden" name="preform_op[]" value="'.$topics[$x].'">';
}
}
else
{
$hidden_fields .= '<input type="hidden" name="'.POST_TOPIC_URL.'" value="'.$topic_id.'">';
}
$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
)
);
$template->pparse("confirm");
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
}
break;
case 'lock': case 'lock':
if($confirm) if($confirm)

View file

@ -380,18 +380,12 @@ if($total_topics || $total_announcements)
{ {
$topic_type = $lang['Topic_Sticky'] . " "; $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 else
{ {
$topic_type = ""; $topic_type = "";
} }
$topic_id = $topic_rowset[$i]['topic_id']; $topic_id = $topic_rowset[$i]['topic_id'];
$replies = $topic_rowset[$i]['topic_replies']; $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'] . "\" />"; $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 else
{ {