From 0ec18c9fbfeb6e19fd8f3da698a6e14e618a8aad Mon Sep 17 00:00:00 2001 From: Ivan Dziuba Date: Wed, 4 Nov 2020 08:37:39 -0500 Subject: [PATCH] Bug 21214: I changed cleanup_database.pl and some corrections with --keep-lc to dodge deletion in message_queue based on letter_code --- misc/cronjobs/cleanup_database.pl | 43 ++++++++++--------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 8e29581f3e..01845fd10e 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -229,18 +229,16 @@ if ($pDebarments && $allDebarments) { usage(1); } -<<<<<<< HEAD say "Confirm flag not passed, running in dry-run mode..." unless $confirm; cronlogaction() unless $confirm; -======= + if (!$mail && $letter_codes) { print "You should not specify --keep-lc if you're not cleaning emails.\n\n"; usage(1); } cronlogaction(); ->>>>>>> Bug 21214: cleanup_database.pl --keep-lc to dodge deletion in message_queue based on letter_code my $dbh = C4::Context->dbh(); my $sth; @@ -297,39 +295,24 @@ if ($zebraqueue_days) { if ($mail) { my $count = 0; print "Mail queue purge triggered for $mail days.\n" if $verbose; -<<<<<<< HEAD - $sth = $dbh->prepare( - q{ - DELETE FROM message_queue - WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY) - } - ); - if ( $confirm ) { - $sth->execute($mail) or die $dbh->errstr; - $count = $sth->rows; - } - if ( $verbose ) { - say $confirm ? "$count messages were deleted from the mail queue." : "Message from message_queue would have been deleted"; - say "Done with message_queue purge."; - } -======= print "Not deleting emails of type $letter_codes.\n" if ($verbose && $letter_codes); - my $query = q{ - DELETE FROM message_queue - WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY) - AND letter_code NOT IN ( ? ) - }; - my $quoted_codes = ''; + + my (@codes, $quoted_codes); + if ($letter_codes) { - my @codes = map { "'$_'" } split(',', $letter_codes); - my $quoted_codes = join(',', @codes); + $letter_codes =~ s/ //g; + @codes = map { "$_" } split(',', $letter_codes); + $quoted_codes = join ",", ("?") x @codes; } - $sth = $dbh->prepare($query); - $sth->execute($mail, $quoted_codes) or die $dbh->errstr; + + $sth = $dbh->prepare(" + DELETE FROM message_queue + WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY) + AND letter_code NOT IN ( $quoted_codes )"); + $sth->execute($mail, @codes) or die $dbh->errstr; $count = $sth->rows; $sth->finish; print "$count messages were deleted from the mail queue.\nDone with message_queue purge.\n" if $verbose; ->>>>>>> Bug 21214: cleanup_database.pl --keep-lc to dodge deletion in message_queue based on letter_code } if ($purge_merged) { -- 2.17.1