mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[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
This commit is contained in:
parent
2841ecc44f
commit
7cc8b3eef8
1 changed files with 29 additions and 9 deletions
|
@ -518,17 +518,37 @@ class phpbb_content_visibility
|
||||||
set_config_count('num_topics', -1, true);
|
set_config_count('num_topics', -1, true);
|
||||||
set_config_count('num_posts', ($topic_row['topic_replies'] + 1) * (-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
|
// Get user post count information
|
||||||
//
|
$sql = 'SELECT poster_id, COUNT(post_id) AS num_posts
|
||||||
/**
|
FROM ' . POSTS_TABLE . '
|
||||||
* @todo: this is wrong, it should rely on post_postcount
|
WHERE topic_id = ' . $topic_id . '
|
||||||
* also a user might have more than one post in the topic
|
AND post_postcount = 1
|
||||||
*
|
AND post_visibility = ' . ITEM_APPROVED . '
|
||||||
if ($auth->acl_get('f_postcount', $forum_id))
|
GROUP BY poster_id';
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
$postcounts = array();
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$sql_data[USERS_TABLE] = 'user_posts = user_posts - 1';
|
$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 = '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);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue