From fc1e420a7c1b094b4a84aecef7fdbc8652af3027 Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Fri, 8 Aug 2014 12:35:31 +0200 Subject: [PATCH 1/3] [ticket/11520] Re-adjust userpost count on topic fork PHPBB3-11520 --- phpBB/includes/mcp/mcp_main.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 9f6125f256..bb466ec976 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1114,6 +1114,7 @@ function mcp_fork_topic($topic_ids) $forum_id = request_var('f', 0); $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); $additional_msg = $success_msg = ''; + $counter = array(); $s_hidden_fields = build_hidden_fields(array( 'topic_id_list' => $topic_ids, @@ -1306,9 +1307,22 @@ function mcp_fork_topic($topic_ids) 'post_edit_time' => (int) $row['post_edit_time'], 'post_edit_count' => (int) $row['post_edit_count'], 'post_edit_locked' => (int) $row['post_edit_locked'], - 'post_postcount' => 0, + 'post_postcount' => $row['post_postcount'], ); - + // Adjust post counts... only if the post can be incremented to the user counter (else, it was not added the users post count anyway) + //Fixed an error of phpBB: http://tracker.phpbb.com/browse/PHPBB3-11520 + //Do not do the query here but later, we just increment the count of posts until the loop is finished, then do new posts counters. + if ($row['post_postcount']) + { + if (isset($counter[$row['poster_id']])) + { + $counter[$row['poster_id']]++; + } + else + { + $counter[$row['poster_id']] = 1; + } + } $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $new_post_id = $db->sql_nextid(); @@ -1428,6 +1442,18 @@ function mcp_fork_topic($topic_ids) WHERE forum_id = ' . $to_forum_id; $db->sql_query($sql); + if (sizeof($counter)) + { + //Do only one query per user and not a query PER post!! + foreach ($counter AS $uid => $count) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts + ' . (int) $count . ' + WHERE user_id = ' . (int) $uid; + $db->sql_query($sql); + } + } + sync('topic', 'topic_id', $new_topic_id_list); sync('forum', 'forum_id', $to_forum_id); From af67bd3ea52ee59324e9446665b5bdbe79158f32 Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Fri, 8 Aug 2014 13:35:08 +0200 Subject: [PATCH 2/3] [ticket/11520] Coding guideline compliance PHPBB3-11520 --- phpBB/includes/mcp/mcp_main.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index bb466ec976..25d3e7380f 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1309,14 +1309,13 @@ function mcp_fork_topic($topic_ids) 'post_edit_locked' => (int) $row['post_edit_locked'], 'post_postcount' => $row['post_postcount'], ); - // Adjust post counts... only if the post can be incremented to the user counter (else, it was not added the users post count anyway) - //Fixed an error of phpBB: http://tracker.phpbb.com/browse/PHPBB3-11520 - //Do not do the query here but later, we just increment the count of posts until the loop is finished, then do new posts counters. + // Adjust post count only if the post can be incremented to the user counter else, it was not added the users post count anyway + // Do not do the query here but later, we just increment the count of posts until the loop is finished, then do new posts counters. if ($row['post_postcount']) { if (isset($counter[$row['poster_id']])) { - $counter[$row['poster_id']]++; + ++$counter[$row['poster_id']]; } else { @@ -1442,14 +1441,14 @@ function mcp_fork_topic($topic_ids) WHERE forum_id = ' . $to_forum_id; $db->sql_query($sql); - if (sizeof($counter)) + if (!empty($counter)) { - //Do only one query per user and not a query PER post!! - foreach ($counter AS $uid => $count) + // Do only one query per user and not a query per post. + foreach ($counter as $user_id => $count) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts + ' . (int) $count . ' - WHERE user_id = ' . (int) $uid; + WHERE user_id = ' . (int) $user_id; $db->sql_query($sql); } } From 3825aee1306d60040677e15e237772e0666dfdd7 Mon Sep 17 00:00:00 2001 From: Geolim4 Date: Fri, 8 Aug 2014 13:48:04 +0200 Subject: [PATCH 3/3] [ticket/11520] Re-adjust userpost count on topic fork PHPBB3-11520 --- phpBB/includes/mcp/mcp_main.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 25d3e7380f..92000c6ceb 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1309,8 +1309,7 @@ function mcp_fork_topic($topic_ids) 'post_edit_locked' => (int) $row['post_edit_locked'], 'post_postcount' => $row['post_postcount'], ); - // Adjust post count only if the post can be incremented to the user counter else, it was not added the users post count anyway - // Do not do the query here but later, we just increment the count of posts until the loop is finished, then do new posts counters. + // Adjust post count only if the post can be incremented to the user counter if ($row['post_postcount']) { if (isset($counter[$row['poster_id']]))