Bugzilla – Attachment 107415 Details for
Bug 24541
Database clean-up: purge messages
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24541: Purge old messages
Bug-24541-Purge-old-messages.patch (text/plain), 4.23 KB, created by
Didier Gautheron
on 2020-07-27 13:03:23 UTC
(
hide
)
Description:
Bug 24541: Purge old messages
Filename:
MIME Type:
Creator:
Didier Gautheron
Created:
2020-07-27 13:03:23 UTC
Size:
4.23 KB
patch
obsolete
>From 171c88edba3354561286f5a2e483142e5db4e7da Mon Sep 17 00:00:00 2001 >From: Didier Gautheron <didier.gautheron@biblibre.com> >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 --confirm --messages 365 >- Recount messages >--- > misc/cronjobs/cleanup_database.pl | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index c2d8e9832c..062efe6041 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; >@@ -50,6 +51,7 @@ use Koha::Old::Holds; > use Koha::Old::Patrons; > use Koha::Item::Transfers; > use Koha::PseudonymizedTransactions; >+use Koha::Patron::Messages; > > sub usage { > print STDERR <<USAGE; >@@ -68,6 +70,8 @@ Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] > -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 >@@ -137,6 +141,7 @@ my $pOldIssues; > my $pOldReserves; > my $pTransfers; > my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo ); >+my $pMessages; > > GetOptions( > 'h|help' => \$help, >@@ -150,6 +155,7 @@ GetOptions( > 'import:i' => \$pImport, > 'z3950' => \$pZ3950, > 'logs:i' => \$pLogs, >+ 'messages:i' => \$pMessages, > 'fees:i' => \$fees_days, > 'searchhistory:i' => \$pSearchhistory, > 'list-invites:i' => \$pListShareInvites, >@@ -182,6 +188,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); >@@ -214,6 +221,7 @@ unless ( $sessions > || defined $pPseudoTransactions > || $pPseudoTransactionsFrom > || $pPseudoTransactionsTo >+ || $pMessages > ) { > print "You did not specify any cleanup work for the script to do.\n\n"; > usage(1); >@@ -334,6 +342,19 @@ if ($pLogs) { > print "Done with purging action_logs.\n" if $verbose; > } > >+if ($pMessages) { >+ print "Purging messages older than $pMessages days.\n" if $verbose; >+ my $messages = Koha::Patron::Messages->filter_by_last_update( >+ { timestamp_column_name => 'message_date', days => $pMessages } ); >+ my $count = $messages->count; >+ $messages->delete if $confirm; >+ if ( $verbose ) { >+ say $confirm >+ ? sprintf( "Done with purging %d messages", $count ) >+ : sprintf( "%d messages would have been removed", $count ); >+ } >+} >+ > if ($fees_days) { > print "Purging records from accountlines.\n" if $verbose; > purge_zero_balance_fees( $fees_days ) if $confirm; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24541
:
98152
|
101509
|
101541
|
107369
|
107415
|
112933
|
114711