diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2007-03-12 19:43:33 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2007-03-12 19:43:33 +0000 |
commit | fa014e05e94fbd683208fd38b66410efdb806304 (patch) | |
tree | f7ec9d01a6524f510ec6fda9146c21bf191012af | |
parent | c64e48a3722f73b8c1549683994850c7e5ae7920 (diff) | |
download | forums-fa014e05e94fbd683208fd38b66410efdb806304.tar forums-fa014e05e94fbd683208fd38b66410efdb806304.tar.gz forums-fa014e05e94fbd683208fd38b66410efdb806304.tar.bz2 forums-fa014e05e94fbd683208fd38b66410efdb806304.tar.xz forums-fa014e05e94fbd683208fd38b66410efdb806304.zip |
it could happen that new private messages are wrongly tagged. We try to "repair" this when releasing messages.
git-svn-id: file:///svn/phpbb/trunk@7178 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/includes/functions_privmsgs.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 7677f4ba34..54ef426ca4 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -330,6 +330,7 @@ function place_pm_into_folder(&$global_privmsgs_rules, $release = false) $action_ary = $move_into_folder = array(); + // Newly processing on-hold messages if ($release) { $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' @@ -337,6 +338,51 @@ function place_pm_into_folder(&$global_privmsgs_rules, $release = false) WHERE folder_id = ' . PRIVMSGS_HOLD_BOX . " AND user_id = $user_id"; $db->sql_query($sql); + + // If there are no rows affected there is something wrong with the new and unread message count. + // We try to fix this on our way down... + if (!$db->sql_affectedrows()) + { + // Update unread count + $sql = 'SELECT COUNT(msg_id) as num_messages + FROM ' . PRIVMSGS_TO_TABLE . ' + WHERE pm_unread = 1 + AND folder_id <> ' . PRIVMSGS_OUTBOX . ' + AND user_id = ' . $user_id; + $result = $db->sql_query($sql); + $num_messages = (int) $db->sql_fetchfield('num_messages'); + $db->sql_freeresult($result); + + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_unread_privmsg = ' . $num_messages . ' WHERE user_id = ' . $user_id); + $user->data['user_unread_privmsg'] = $num_messages; + + // Update new pm count + $sql = 'SELECT COUNT(msg_id) as num_messages + FROM ' . PRIVMSGS_TO_TABLE . ' + WHERE pm_new = 1 + AND folder_id IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ') + AND user_id = ' . $user_id; + $result = $db->sql_query($sql); + $num_messages = (int) $db->sql_fetchfield('num_messages'); + $db->sql_freeresult($result); + + $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_new_privmsg = ' . $num_messages . ' WHERE user_id = ' . $user_id); + $user->data['user_new_privmsg'] = $num_messages; + + // Ok, here we need to repair something, other boxes than privmsgs_no_box and privmsgs_hold_box should not carry the pm_new flag. + if (!$num_messages) + { + $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' + SET pm_new = 0 + WHERE pm_new = 1 + AND folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ') + AND user_id = ' . $user_id; + $db->sql_query($sql); + } + + // The function needs this value to be up-to-date + $user_new_privmsg = (int) $user->data['user_new_privmsg']; + } } // Get those messages not yet placed into any box |