From 10753454bf697f411051988e7c841d1eb80cd114 Mon Sep 17 00:00:00 2001 From: "Victor A. Safronov" Date: Wed, 30 Nov 2016 23:59:36 +0400 Subject: [PATCH] [ticket/13757] Prevents the count of unread PMs from being negative Sometimes the user_unread_privmsg flag in users table can become negative. It happens when the unread message is requested by simultaneous concurrent requests. Both requests will decrement the value of the flag. This commit prevents updating the flag if the message already marked as read. PHPBB3-13757 --- phpBB/includes/functions_privmsgs.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 1639eb1a4c..d7a87ca356 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -892,6 +892,12 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) AND folder_id = $folder_id"; $db->sql_query($sql); + // If the message is already marked as read, we just skip the rest to avoid negative PM count + if (!$db->sql_affectedrows()) + { + return; + } + $sql = 'UPDATE ' . USERS_TABLE . " SET user_unread_privmsg = user_unread_privmsg - 1 WHERE user_id = $user_id";