Skip to content

Commit

Permalink
GH-126 Delegate batch deletions by non-selected IDs to Messages\Comma…
Browse files Browse the repository at this point in the history
…nds\batchDeleteMessagesByID
  • Loading branch information
mdziekon committed Aug 2, 2020
1 parent 053bcef commit e89f6bb
Showing 1 changed file with 10 additions and 65 deletions.
75 changes: 10 additions & 65 deletions messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,10 @@
{
// User is deleting all Unmarked messages
$DeleteIDs = false;
if(!empty($_POST['sm_all']))
{
if (!empty($_POST['sm_all'])) {
preg_match_all('#([0-9]{1,})#si', $_POST['sm_all'], $DeleteIDs);
$DeleteIDs = $DeleteIDs[0];
}
else
{
} else {
foreach($_POST as $Message => $Answer)
{
if(preg_match("/^sm([0-9]{1,})$/D", $Message, $MsgMatch))
Expand All @@ -490,71 +487,19 @@
}
}
}
if($DeleteIDs !== FALSE)
{
$IDs = implode(',', $DeleteIDs);

$SelectMsgs = doquery(
"SELECT `id`, `Thread_ID` FROM {{table}} WHERE `id` IN ({$IDs}) AND `id_owner` = {$_User['id']} AND `type` != 80;",
'messages'
);
if ($DeleteIDs !== FALSE) {
$cmdResult = Messages\Commands\batchDeleteMessagesByID([
'messageIDs' => $DeleteIDs,
'userID' => $_User['id'],
]);

if($SelectMsgs->num_rows > 0)
{
if ($cmdResult['deletedMessagesCount'] > 0) {
$DelMsgs[] = $_Lang['Delete_UnselectedDeleted'];

$UpdateThreads = array();
while($SelectData = $SelectMsgs->fetch_assoc())
{
$UpdateIDs[] = $SelectData['id'];
if($SelectData['Thread_ID'] > 0)
{
if(!in_array($SelectData['Thread_ID'], $UpdateThreads))
{
$UpdateThreads[] = $SelectData['Thread_ID'];
}
}
}
$IDs = implode(',', $UpdateIDs);
$UpdateIDs = array();

doquery(
"UPDATE {{table}} SET `deleted` = true, `Thread_IsLast` = 0 WHERE `id` IN ({$IDs});",
'messages'
);

if(!empty($UpdateThreads))
{
$IDs = implode(',', $UpdateThreads);

$SelectIDs = doquery(
"SELECT MAX(`id`) AS `id` FROM {{table}} WHERE `Thread_ID` IN ({$IDs}) AND `id_owner` = {$_User['id']} AND `deleted` = false GROUP BY `Thread_ID`;",
'messages'
);

if($SelectIDs->num_rows > 0)
{
while($SelectData = $SelectIDs->fetch_assoc())
{
$UpdateIDs[] = $SelectData['id'];
}

$IDs = implode(',', $UpdateIDs);

doquery(
"UPDATE {{table}} SET `Thread_IsLast` = 1 WHERE `id` IN ({$IDs});",
'messages'
);
}
}
}
else
{
} else {
$DelNotifs[] = $_Lang['Delete_BadSelections'];
}
}
else
{
} else {
$DelNotifs[] = $_Lang['Delete_NoMsgsUnselected'];
}
}
Expand Down

0 comments on commit e89f6bb

Please sign in to comment.