Skip to content

Commit

Permalink
Scripts: Include all "deleted" status messages in old attachments del…
Browse files Browse the repository at this point in the history
…etion process - refs BT#19673
  • Loading branch information
ywarnier committed Mar 22, 2022
1 parent cd76e38 commit cd57102
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/scripts/delete_old_message_attachments.php
Expand Up @@ -61,6 +61,8 @@
while ($message = Database::fetch_assoc($res)) {
switch ($message['msg_status']) {
case '4':
// This message is in status "outbox", meaning it's in the
// sender's outbox.
//echo "Message ".$message['mid']." is in user ".$message['user_sender_id']." outbox".PHP_EOL;
$usi = $message['user_sender_id'];
$filePath = substr($usi, 0, 1).'/'.$usi.'/message_attachments/'.$message['path'];
Expand Down Expand Up @@ -90,6 +92,7 @@
//echo "Message ".$message['mid']." can be in two different folders".PHP_EOL;
$usi = $message['user_receiver_id'];
$filePath = substr($usi, 0, 1).'/'.$usi.'/message_attachments/'.$message['path'];
// Check if this file is on the receiver's side
if (file_exists($userBasePath.$filePath)) {
//echo " File found in receiver's path".PHP_EOL;
$totalSize += filesize($userBasePath.$filePath);
Expand All @@ -101,11 +104,22 @@
echo "Query: ".$sqlDeleteAttach.$message['maid'].PHP_EOL;
}
} else {
// Not on the receiver's side, so must be on the sender's side
$usi = $message['user_sender_id'];
$filePath = substr($usi, 0, 1).'/'.$usi.'/message_attachments/'.$message['path'];
if (file_exists($userBasePath.$filePath)) {
//echo " File found in sender's path".PHP_EOL;
$senderMessageSize += filesize($userBasePath.$filePath);
$totalSize += filesize($userBasePath.$filePath);
if ($simulate == false) {
// Even though we would normally not delete sender files
// indiscriminately, status=3 means the message was
// deleted by the user, so... no mercy!
exec('rm '.$userBasePath.$filePath);
$deleteResult = Database::query($sqlDeleteAttach.$message['maid']);
} else {
echo "Would delete ".$userBasePath.$filePath.PHP_EOL;
echo "Query: ".$sqlDeleteAttach.$message['maid'].PHP_EOL;
}
}
}
break;
Expand Down

0 comments on commit cd57102

Please sign in to comment.