Bugzilla – Attachment 189527 Details for
Bug 21214
cleanup_database.pl --mail should let admin choose which letter codes to keep
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21214: cleanup_database.pl --keep-lc to dodge deletion in message_queue based on letter_code
Bug-21214-cleanupdatabasepl---keep-lc-to-dodge-del.patch (text/plain), 3.86 KB, created by
Hammat wele
on 2025-11-12 20:24:20 UTC
(
hide
)
Description:
Bug 21214: cleanup_database.pl --keep-lc to dodge deletion in message_queue based on letter_code
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2025-11-12 20:24:20 UTC
Size:
3.86 KB
patch
obsolete
>From 13e8cb59f9bebf1f58068cad2fed598265649a5c Mon Sep 17 00:00:00 2001 >From: Hammat Wele <hammat.wele@inlibro.com> >Date: Wed, 12 Nov 2025 20:22:48 +0000 >Subject: [PATCH] Bug 21214: cleanup_database.pl --keep-lc to dodge deletion in > message_queue based on letter_code > >Librarians sometime worry if a certain email was sent or not to a patron (PREDUES, ODUES, etc.), and iirc, there are no way to have that information once the cleanup_database.pl has run, unless we dig back an archive of their database. >This patch would let an admin choose which letters to keep in the message_queue, based on its letter_code, by passing a comma-separated list to the script. > >TEST PLAN: >1) Either you have already have data, or you'll want to add some new test lines in your message_queue table > . INSERT INTO message_queue(borrowernumber,letter_code,message_transport_type,status,time_queued) > VALUES(1,<YOUR CODE OF CHOICE>,'email','sent','2018-01-01 00:00:42'); >2) Make a backup of this table >3) Run the script patchless with the --mail 1 option > 3.1) Messages older than 1 day should have been deleted >4) Put the data back in >5) Apply patch >6) Choose a letter_code you'd like to keep, and run the script with --mail 1 --keep-lc <CODE1>[,<CODE2>] >7) Messages older than 1 day that don't have the code <CODE1> [or <CODE2>] should've been deleted >--- > misc/cronjobs/cleanup_database.pl | 26 +++++++++++++++++++------- > 1 file changed, 19 insertions(+), 7 deletions(-) > >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 771846adfc3..8a7df4609a5 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -73,6 +73,9 @@ Usage: $0 > Defaults to 30 days if no days specified. > -m --mail DAYS purge items from the mail queue that are older than DAYS days. > Defaults to 30 days if no days specified. >+ --keep-lc LC[,LC]* only used in conjunction with -m/--mail. >+ Keeps certain emails in the message_queue based on a >+ comma-separated list of LETTER_CODES > --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. >@@ -141,6 +144,7 @@ my $sess_days; > my $verbose; > my $zebraqueue_days; > my $mail; >+my $letter_codes; > my $purge_merged; > my $pImport; > my $pLogs; >@@ -189,6 +193,7 @@ GetOptions( > 'sessdays:i' => \$sess_days, > 'v|verbose' => \$verbose, > 'm|mail:i' => \$mail, >+ 'keep-lc:s' => \$letter_codes, > 'zebraqueue:i' => \$zebraqueue_days, > 'merged' => \$purge_merged, > 'import:i' => \$pImport, >@@ -361,14 +366,21 @@ if ($zebraqueue_days) { > if ($mail) { > my $count = 0; > print "Mail queue purge triggered for $mail days.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE FROM message_queue >- WHERE time_queued < date_sub(curdate(), INTERVAL ? DAY) >- } >- ); >+ 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) >+ }; >+ my @bind_params = ($mail); >+ if ($letter_codes) { >+ $letter_codes =~ s/ //g; >+ my @codes = map { "$_" } split( ',', $letter_codes ); >+ $query .= " AND letter_code NOT IN ( " . ( join ",", ("?") x @codes ) . " )"; >+ push @bind_params, @codes; >+ } >+ $sth = $dbh->prepare($query); > if ($confirm) { >- $sth->execute($mail) or die $dbh->errstr; >+ $sth->execute(@bind_params) or die $dbh->errstr; > $count = $sth->rows; > } > if ($verbose) { >-- >2.34.1
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 21214
:
77756
|
77762
|
112992
|
112993
|
112994
|
113002
|
113008
|
113009
|
148622
|
148623
|
148624
|
148625
|
158679
|
158680
|
158681
|
162064
| 189527