diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index dfba1179a3..b952e4d07d 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -271,6 +271,7 @@ p a {
[Fix] Do not erase ranks and avatars when changing default groups (Bugs #13701, #13697)
[Fix] Limit author searches to firstpost, if selected (Bug #13579)
[Fix] store Date custom profile field defaults on multi-lingual boards
+ [Fix] Properly resync user post counts for users that have no posts (Bug #13581)
diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php
index b43ca5f9dd..770c82552f 100644
--- a/phpBB/includes/acp/acp_main.php
+++ b/phpBB/includes/acp/acp_main.php
@@ -161,15 +161,15 @@ class acp_main
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
}
- $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
- FROM ' . POSTS_TABLE . '
- WHERE post_postcount = 1
- GROUP BY poster_id';
+ $sql = 'SELECT COUNT(p.post_id) AS num_posts, u.user_id
+ FROM ' . USERS_TABLE . ' u
+ LEFT JOIN ' . POSTS_TABLE . ' p ON (u.user_id = p.poster_id AND p.post_postcount = 1)
+ GROUP BY u.user_id';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
- $db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['poster_id']}");
+ $db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['user_id']}");
}
$db->sql_freeresult($result);