mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/10950] Recreated the behaviour of phpbb_delete_user_pms()
- Get delete_ids, pms of the user as receipt - Get undelivered_msg, pms of the user as sender - Delete undelivered_msg, if there are only NO_BOX, OUTBOX and SENTBOX links - Correct the _new and _unread user values for the receipts - Delete delete_ids, if there are no links to them anymore - Reset _new and _unread values for the user we delete PHPBB3-10950
This commit is contained in:
parent
7988045bda
commit
5c8c7b1352
1 changed files with 75 additions and 59 deletions
|
@ -1103,10 +1103,10 @@ function phpbb_delete_user_pms($user_id)
|
||||||
|
|
||||||
// Get PM Information for later deleting
|
// Get PM Information for later deleting
|
||||||
// The two queries where split, so we can use our indexes
|
// The two queries where split, so we can use our indexes
|
||||||
$undelivered_msg = $undelivered_user = $delete_ids = array();
|
$undelivered_msg = $delete_ids = array();
|
||||||
|
|
||||||
// Part 1: get PMs the user received
|
// Part 1: get PMs the user received
|
||||||
$sql = 'SELECT msg_id, user_id, author_id, folder_id
|
$sql = 'SELECT msg_id
|
||||||
FROM ' . PRIVMSGS_TO_TABLE . '
|
FROM ' . PRIVMSGS_TO_TABLE . '
|
||||||
WHERE user_id = ' . $user_id;
|
WHERE user_id = ' . $user_id;
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
@ -1115,26 +1115,13 @@ function phpbb_delete_user_pms($user_id)
|
||||||
{
|
{
|
||||||
$msg_id = (int) $row['msg_id'];
|
$msg_id = (int) $row['msg_id'];
|
||||||
$delete_ids[$msg_id] = $msg_id;
|
$delete_ids[$msg_id] = $msg_id;
|
||||||
|
|
||||||
if ($row['author_id'] == $user_id && $row['folder_id'] == PRIVMSGS_NO_BOX)
|
|
||||||
{
|
|
||||||
// Undelivered messages
|
|
||||||
$undelivered_msg[] = $msg_id;
|
|
||||||
|
|
||||||
if (isset($undelivered_user[$row['user_id']]))
|
|
||||||
{
|
|
||||||
++$undelivered_user[$row['user_id']];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$undelivered_user[$row['user_id']] = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
// Part 2: get PMs the user sent, but has yet to be received
|
// Part 2: get PMs the user sent, but has yet to be received
|
||||||
$sql = 'SELECT msg_id, user_id
|
// We can not simply delete them. First we have to check,
|
||||||
|
// whether another user already received and read the message.
|
||||||
|
$sql = 'SELECT msg_id
|
||||||
FROM ' . PRIVMSGS_TO_TABLE . '
|
FROM ' . PRIVMSGS_TO_TABLE . '
|
||||||
WHERE author_id = ' . $user_id . '
|
WHERE author_id = ' . $user_id . '
|
||||||
AND folder_id = ' . PRIVMSGS_NO_BOX;
|
AND folder_id = ' . PRIVMSGS_NO_BOX;
|
||||||
|
@ -1143,61 +1130,90 @@ function phpbb_delete_user_pms($user_id)
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$msg_id = (int) $row['msg_id'];
|
$msg_id = (int) $row['msg_id'];
|
||||||
$delete_ids[$msg_id] = $msg_id;
|
$undelivered_msg[$msg_id] = $msg_id;
|
||||||
|
|
||||||
// Undelivered messages
|
|
||||||
$undelivered_msg[] = $msg_id;
|
|
||||||
|
|
||||||
if (isset($undelivered_user[$row['user_id']]))
|
|
||||||
{
|
|
||||||
++$undelivered_user[$row['user_id']];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$undelivered_user[$row['user_id']] = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
if (empty($delete_ids))
|
if (empty($delete_ids) && empty($undelivered_msg))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->sql_transaction('begin');
|
$db->sql_transaction('begin');
|
||||||
|
|
||||||
if (sizeof($undelivered_msg))
|
if (!empty($undelivered_msg))
|
||||||
{
|
{
|
||||||
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
|
// A pm is not undelivered, if for any receipt the message was moved
|
||||||
WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg);
|
// from their NO_BOX to another folder.
|
||||||
$db->sql_query($sql);
|
$sql = 'SELECT msg_id
|
||||||
|
FROM ' . PRIVMSGS_TO_TABLE . '
|
||||||
|
WHERE author_id = ' . $user_id . '
|
||||||
|
AND folder_id <> ' . PRIVMSGS_NO_BOX . '
|
||||||
|
AND folder_id <> ' . PRIVMSGS_OUTBOX . '
|
||||||
|
AND folder_id <> ' . PRIVMSGS_SENTBOX;
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$msg_id = (int) $row['msg_id'];
|
||||||
|
unset($undelivered_msg[$msg_id]);
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if (!empty($undelivered_msg))
|
||||||
|
{
|
||||||
|
$undelivered_user = array();
|
||||||
|
|
||||||
|
// Count the messages we delete, so we can correct the user pm data
|
||||||
|
$sql = 'SELECT user_id
|
||||||
|
FROM ' . PRIVMSGS_TO_TABLE . '
|
||||||
|
WHERE author_id = ' . $user_id . '
|
||||||
|
AND folder_id = ' . PRIVMSGS_NO_BOX . '
|
||||||
|
AND ' . $db->sql_in_set('msg_id', $undelivered_msg);
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
if (isset($undelivered_user[$row['user_id']]))
|
||||||
|
{
|
||||||
|
++$undelivered_user[$row['user_id']];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$undelivered_user[$row['user_id']] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
foreach ($undelivered_user as $undelivered_user_id => $count)
|
||||||
|
{
|
||||||
|
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||||
|
SET user_new_privmsg = user_new_privmsg - ' . $count . ',
|
||||||
|
user_unread_privmsg = user_unread_privmsg - ' . $count . '
|
||||||
|
WHERE user_id = ' . $undelivered_user_id;
|
||||||
|
$db->sql_query($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . '
|
||||||
|
WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg);
|
||||||
|
$db->sql_query($sql);
|
||||||
|
|
||||||
|
$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
|
||||||
|
WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg);
|
||||||
|
$db->sql_query($sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the user's pm count to 0
|
// Reset the user's pm count to 0
|
||||||
if (isset($undelivered_user[$user_id]))
|
$sql = 'UPDATE ' . USERS_TABLE . '
|
||||||
{
|
SET user_new_privmsg = 0,
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
user_unread_privmsg = 0
|
||||||
SET user_new_privmsg = 0,
|
WHERE user_id = ' . $user_id;
|
||||||
user_unread_privmsg = 0
|
$db->sql_query($sql);
|
||||||
WHERE user_id = ' . $user_id;
|
|
||||||
$db->sql_query($sql);
|
|
||||||
|
|
||||||
unset($undelivered_user[$user_id]);
|
// Delete private message data of the user
|
||||||
}
|
$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . '
|
||||||
|
WHERE user_id = ' . (int) $user_id;
|
||||||
foreach ($undelivered_user as $_user_id => $count)
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . '
|
|
||||||
SET user_new_privmsg = user_new_privmsg - ' . $count . ',
|
|
||||||
user_unread_privmsg = user_unread_privmsg - ' . $count . '
|
|
||||||
WHERE user_id = ' . $_user_id;
|
|
||||||
$db->sql_query($sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete private message data
|
|
||||||
$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . "
|
|
||||||
WHERE user_id = $user_id
|
|
||||||
AND " . $db->sql_in_set('msg_id', $delete_ids);
|
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
// Now we have to check which messages we can delete completely
|
// Now we have to check which messages we can delete completely
|
||||||
|
|
Loading…
Add table
Reference in a new issue