From 0f05f1c4d751099a7e05fd0b9a8da1ac81ff32ac Mon Sep 17 00:00:00 2001 From: Didier Gautheron Date: Thu, 30 Jan 2020 10:35:31 +0100 Subject: [PATCH] Bug 24541: Purge old messages misc/cronjobs/cleanup_database.pl provides some database cleanup. This patch adds cleanup for messages table. Test plan : - Count messages : select count(*),date(message_date) from messages group by date(message_date); - Run cleanup : misc/cronjobs/cleanup_database.pl -v --messages 365 - Recount messages --- misc/cronjobs/cleanup_database.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index a1a9cae442..b3002699e6 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -23,6 +23,7 @@ use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30; use constant DEFAULT_MAIL_PURGEDAYS => 30; use constant DEFAULT_IMPORT_PURGEDAYS => 60; use constant DEFAULT_LOGS_PURGEDAYS => 180; +use constant DEFAULT_MESSAGES_PURGEDAYS => 365; use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30; use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14; use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; @@ -59,6 +60,8 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu -m --mail DAYS purge items from the mail queue that are older than DAYS days. Defaults to 30 days if no days specified. --merged purged completed entries from need_merge_authorities. + --messages DAYS purge entries from messages table older than DAYS days. + Defaults to 365 days if no days specified. --import DAYS purge records from import tables older than DAYS days. Defaults to 60 days if no days specified. --z3950 purge records from import tables that are the result @@ -122,6 +125,7 @@ my $pDeletedPatrons; my $pOldIssues; my $pOldReserves; my $pTransfers; +my $pMessages; GetOptions( 'h|help' => \$help, @@ -134,6 +138,7 @@ GetOptions( 'import:i' => \$pImport, 'z3950' => \$pZ3950, 'logs:i' => \$pLogs, + 'messages:i' => \$pMessages, 'fees:i' => \$fees_days, 'searchhistory:i' => \$pSearchhistory, 'list-invites:i' => \$pListShareInvites, @@ -163,6 +168,7 @@ $mail = DEFAULT_MAIL_PURGEDAYS if defined($mail) $pSearchhistory = DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhistory) && $pSearchhistory == 0; $pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0; $pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarments) && $pDebarments == 0; +$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; if ($help) { usage(0); @@ -192,6 +198,7 @@ unless ( $sessions || $pOldIssues || $pOldReserves || $pTransfers + || $pMessages ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -293,6 +300,18 @@ if ($pLogs) { print "Done with purging action_logs.\n" if $verbose; } +if ($pMessages) { + print "Purging records from messages.\n" if $verbose; + $sth = $dbh->prepare( + q{ + DELETE FROM messages + WHERE message_date < date_sub(curdate(), INTERVAL ? DAY) + } + ); + $sth->execute($pMessages) or die $dbh->errstr; + print "Done with purging messages.\n" if $verbose; +} + if ($fees_days) { print "Purging records from accountlines.\n" if $verbose; purge_zero_balance_fees( $fees_days ); -- 2.11.0