aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/mcp
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2007-04-18 19:52:29 +0000
committerDavid M <davidmj@users.sourceforge.net>2007-04-18 19:52:29 +0000
commitb729c32dc908d73834742ea7d4ab8542632734c4 (patch)
treeb419f66f4111fdaa92c259c094f4235451cc8abc /phpBB/includes/mcp
parentc8f138d4bd8c0a4d515034c37fccca6e70faf1d2 (diff)
downloadforums-b729c32dc908d73834742ea7d4ab8542632734c4.tar
forums-b729c32dc908d73834742ea7d4ab8542632734c4.tar.gz
forums-b729c32dc908d73834742ea7d4ab8542632734c4.tar.bz2
forums-b729c32dc908d73834742ea7d4ab8542632734c4.tar.xz
forums-b729c32dc908d73834742ea7d4ab8542632734c4.zip
MCP move topics is much faster now
git-svn-id: file:///svn/phpbb/trunk@7370 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/mcp')
-rw-r--r--phpBB/includes/mcp/mcp_main.php141
1 files changed, 138 insertions, 3 deletions
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php
index ab43f53b6c..3b7ecc8dde 100644
--- a/phpBB/includes/mcp/mcp_main.php
+++ b/phpBB/includes/mcp/mcp_main.php
@@ -520,6 +520,40 @@ function mcp_move_topic($topic_ids)
$topic_data = get_topic_data($topic_ids);
$leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;
+ $topics_moved = sizeof($topic_ids);
+ $topics_authed_moved = 0;
+ $forum_sync_data = array();
+
+ $forum_sync_data[$forum_id] = current($topic_data);
+ $forum_sync_data[$to_forum_id] = $forum_data;
+
+ foreach ($topic_data as $topic_id => $topic_info)
+ {
+ if ($topic_info['topic_approved'] == '1')
+ {
+ $topics_authed_moved++;
+ }
+ }
+
+ $sql = 'SELECT COUNT(p.post_id) AS topic_posts, MAX(p.post_id) AS last_post_id
+ FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
+ WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids) . '
+ AND p.topic_id = t.topic_id
+ AND t.topic_approved = 1
+ AND p.post_approved = 1';
+ $result = $db->sql_query($sql);
+ $row_data = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ $forum_sync_data[$forum_id]['forum_posts'] -= (int) $row_data['topic_posts'];
+ $forum_sync_data[$to_forum_id]['forum_posts'] += (int) $row_data['topic_posts'];
+ $forum_sync_data[$forum_id]['forum_topics'] -= (int) $topics_moved;
+ $forum_sync_data[$to_forum_id]['forum_topics'] += (int) $topics_moved;
+ $forum_sync_data[$forum_id]['forum_topics_real'] -= (int) $topics_authed_moved;
+ $forum_sync_data[$to_forum_id]['forum_topics_real'] += (int) $topics_authed_moved;
+
+ $db->sql_transaction('begin');
+
// Move topics, but do not resync yet
move_topics($topic_ids, $to_forum_id, false);
@@ -575,14 +609,115 @@ function mcp_move_topic($topic_ids)
);
$db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
+
+ $forum_sync_data[(int) $row['forum_id']]['forum_topics']++;
}
}
unset($topic_data);
- // Now sync forums
- sync('forum', 'forum_id', $forum_ids);
-
$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
+
+ // we must update the info, this post is being moved and is not the newest anymore
+ if ($forum_sync_data[$forum_id]['forum_last_post_id'] == $row_data['last_post_id'])
+ {
+ $forum_sync_data[$forum_id]['forum_last_post_id'] = 0;
+ $forum_sync_data[$forum_id]['forum_last_post_subject'] = '';
+ $forum_sync_data[$forum_id]['forum_last_post_time'] = 0;
+ $forum_sync_data[$forum_id]['forum_last_poster_id'] = 0;
+ $forum_sync_data[$forum_id]['forum_last_poster_name'] = '';
+ $forum_sync_data[$forum_id]['forum_last_poster_colour'] = '';
+
+ // I want the newest post that is not in the collection
+ // TODO: this is the last trouble maker
+ $sql = 'SELECT MAX(p.post_id) AS last_post_id
+ FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
+ WHERE p.topic_id = t.topic_id
+ AND t.topic_approved = 1
+ AND p.post_approved = 1
+ AND t.forum_id = ' . $forum_id;
+ $result = $db->sql_query($sql);
+
+ if ($last_post_id = $db->sql_fetchfield('last_post_id', false, $result))
+ {
+ $sql = 'SELECT p.post_subject, p.post_time, p.post_username, p.poster_id, u.username as poster_name, u.user_colour as poster_colour
+ FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
+ WHERE p.post_id = ' . $last_post_id . '
+ AND p.poster_id = u.user_id';
+ $result2 = $db->sql_query($sql);
+ $post_data = $db->sql_fetchrow($result2);
+ $db->sql_freeresult($result2);
+
+ $post_data['post_id'] = $last_post_id;
+
+ if ($post_data['poster_id'] == ANONYMOUS)
+ {
+ $post_data['poster_name'] = $post_data['post_username'];
+ }
+ unset($post_data['post_username']);
+
+ foreach ($post_data as $row => $val)
+ {
+ $forum_sync_data[$forum_id]['forum_last_' . $row] = $val;
+ }
+ }
+
+ $db->sql_freeresult($result);
+ }
+
+ // we must update the info, this post is being moved and is not the newest anymore
+ if ($forum_sync_data[$to_forum_id]['forum_last_post_id'] < $row_data['last_post_id'])
+ {
+ $forum_sync_data[$to_forum_id]['forum_last_post_id'] = 0;
+ $forum_sync_data[$to_forum_id]['forum_last_post_subject'] = '';
+ $forum_sync_data[$to_forum_id]['forum_last_post_time'] = 0;
+ $forum_sync_data[$to_forum_id]['forum_last_poster_id'] = 0;
+ $forum_sync_data[$to_forum_id]['forum_last_poster_name'] = '';
+ $forum_sync_data[$to_forum_id]['forum_last_poster_colour'] = '';
+
+ // mod just moved all the posts out of the forum!
+ $sql = 'SELECT p.post_subject, p.post_time, p.post_username, p.poster_id, u.username as poster_name, u.user_colour as poster_colour
+ FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
+ WHERE p.post_id = ' . $row_data['last_post_id'] . '
+ AND p.poster_id = u.user_id';
+ $result2 = $db->sql_query($sql);
+ $post_data = $db->sql_fetchrow($result2);
+ $db->sql_freeresult($result2);
+
+ if ($post_data)
+ {
+ $post_data['post_id'] = $row_data['last_post_id'];
+
+ if ($post_data['poster_id'] == ANONYMOUS)
+ {
+ $post_data['poster_name'] = $post_data['post_username'];
+ }
+ unset($post_data['post_username']);
+
+ foreach ($post_data as $row => $val)
+ {
+ $forum_sync_data[$to_forum_id]['forum_last_' . $row] = $val;
+ }
+ }
+ }
+
+ foreach ($forum_sync_data as $forum_id_key => $sql_ary)
+ {
+ foreach ($sql_ary as $key => $value)
+ {
+ if (strpos($key, 'forum_last_') === 0 || $key === 'forum_posts' || $key === 'forum_topics' || $key === 'forum_topics_real')
+ {
+ continue;
+ }
+ unset($sql_ary[$key]);
+ }
+
+ $sql = 'UPDATE ' . FORUMS_TABLE . '
+ SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
+ WHERE forum_id = ' . $forum_id_key;
+ $db->sql_query($sql);
+ }
+
+ $db->sql_transaction('commit');
}
else
{