aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-10-09 12:23:15 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-10-09 12:23:15 +0200
commit7cc8b3eef82a70a1aa708614e37fd82482d9d7d2 (patch)
tree190596bbf7a2e579d0172f1ba2deb4df1f660010 /phpBB/includes
parent2841ecc44f2c9773fe3eb19134f52bfcf4beb05e (diff)
downloadforums-7cc8b3eef82a70a1aa708614e37fd82482d9d7d2.tar
forums-7cc8b3eef82a70a1aa708614e37fd82482d9d7d2.tar.gz
forums-7cc8b3eef82a70a1aa708614e37fd82482d9d7d2.tar.bz2
forums-7cc8b3eef82a70a1aa708614e37fd82482d9d7d2.tar.xz
forums-7cc8b3eef82a70a1aa708614e37fd82482d9d7d2.zip
[feature/soft-delete] Correctly update user_posts count
Before soft delete this was much easier, as an unapproved topic could only have one post, because no one could reply to unapproved topics. Now we need to run multiple queries to correctly reduce the post counts. PHPBB3-9567
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/content_visibility.php38
1 files changed, 29 insertions, 9 deletions
diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php
index dcb7f363f8..8854981303 100644
--- a/phpBB/includes/content_visibility.php
+++ b/phpBB/includes/content_visibility.php
@@ -518,17 +518,37 @@ class phpbb_content_visibility
set_config_count('num_topics', -1, true);
set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-1), true);
- // Only decrement this post, since this is the one non-approved now
- //
- /**
- * @todo: this is wrong, it should rely on post_postcount
- * also a user might have more than one post in the topic
- *
- if ($auth->acl_get('f_postcount', $forum_id))
+ // Get user post count information
+ $sql = 'SELECT poster_id, COUNT(post_id) AS num_posts
+ FROM ' . POSTS_TABLE . '
+ WHERE topic_id = ' . $topic_id . '
+ AND post_postcount = 1
+ AND post_visibility = ' . ITEM_APPROVED . '
+ GROUP BY poster_id';
+ $result = $db->sql_query($sql);
+
+ $postcounts = array();
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $postcounts[(int) $row['num_posts']][] = (int) $row['poster_id'];
+ }
+ $db->sql_freeresult($result);
+
+ // Decrement users post count
+ foreach ($postcounts as $num_posts => $poster_ids)
{
- $sql_data[USERS_TABLE] = 'user_posts = user_posts - 1';
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET user_posts = 0
+ WHERE user_posts < ' . $num_posts . '
+ AND ' . $db->sql_in_set('user_id', $poster_ids);
+ $db->sql_query($sql);
+
+ $sql = 'UPDATE ' . USERS_TABLE . '
+ SET user_posts = user_posts - ' . $num_posts . '
+ WHERE user_posts >= ' . $num_posts . '
+ AND ' . $db->sql_in_set('user_id', $poster_ids);
+ $db->sql_query($sql);
}
- */
}
/**