Bugzilla – Attachment 120221 Details for
Bug 15563
Add option to regularly delete patroncard and label batches to cleanup_database.pl cronjob
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15563: (follow-up) Combine methods, add count, obey confirm
Bug-15563-follow-up-Combine-methods-add-count-obey.patch (text/plain), 3.95 KB, created by
Jonathan Druart
on 2021-04-27 13:09:07 UTC
(
hide
)
Description:
Bug 15563: (follow-up) Combine methods, add count, obey confirm
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2021-04-27 13:09:07 UTC
Size:
3.95 KB
patch
obsolete
>From 7736c8622794eff71146878b51f4051d638908cd Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 23 Apr 2021 12:36:54 +0000 >Subject: [PATCH] Bug 15563: (follow-up) Combine methods, add count, obey > confirm > >This patch moves the SQL to a subroutine and uses the Label delete method to >remove the batches > >We now return a count and do not delete if --confirm flag is not passed > >Repeate previous test plan, confirm works as expected > >JD amended patch: perltidy >--- > misc/cronjobs/cleanup_database.pl | 67 ++++++++++++++++++------------- > 1 file changed, 39 insertions(+), 28 deletions(-) > >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 85967e78077..18971114960 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -625,38 +625,22 @@ if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransact > > if ($labels) { > print "Purging item label batches last added to more than $labels days ago.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE from creator_batches >- WHERE batch_id in >- (SELECT batch_id >- FROM (SELECT batch_id >- FROM creator_batches >- WHERE creator='labels' >- GROUP BY batch_id >- HAVING max(timestamp) < date_sub(curdate(),interval ? day)) a) >- } >- ); >- $sth->execute($labels) or die $dbh->errstr; >- print "Done with purging item label batches last added to more than $labels days ago.\n" if $verbose; >+ my $count = PurgeCreatorBatches($labels, 'labels', $confirm); >+ if ($verbose) { >+ say $confirm >+ ? sprintf "Done with purging %d item label batches last added to more than %d days ago.\n", $count, $labels >+ : sprintf "%d item label batches would have been purged.", $count; >+ } > } > > if ($cards) { > print "Purging card creator batches last added to more than $cards days ago.\n" if $verbose; >- $sth = $dbh->prepare( >- q{ >- DELETE from creator_batches >- WHERE batch_id in >- (SELECT batch_id >- FROM (SELECT batch_id >- FROM creator_batches >- WHERE creator='patroncards' >- GROUP BY batch_id >- HAVING max(timestamp) < date_sub(curdate(),interval ? day)) a); >- } >- ); >- $sth->execute($cards) or die $dbh->errstr; >- print "Done with purging card creator batches last added to more than $cards days ago.\n" if $verbose; >+ my $count = PurgeCreatorBatches($labels, 'patroncards', $confirm); >+ if ($verbose) { >+ say $confirm >+ ? sprintf "Done with purging %d card creator batches last added to more than %d days ago.\n", $count, $labels >+ : sprintf "%d card creator batches would have been purged.", $count; >+ } > } > > exit(0); >@@ -747,6 +731,33 @@ sub PurgeDebarments { > return $count; > } > >+sub PurgeCreatorBatches { >+ require C4::Labels::Batch; >+ my ( $days, $creator, $doit ) = @_; >+ my $count = 0; >+ $sth = $dbh->prepare( >+ q{ >+ SELECT batch_id, branch_code FROM creator_batches >+ WHERE batch_id in >+ (SELECT batch_id >+ FROM (SELECT batch_id >+ FROM creator_batches >+ WHERE creator=? >+ GROUP BY batch_id >+ HAVING max(timestamp) <= date_sub(curdate(),interval ? day)) a) >+ } >+ ); >+ $sth->execute( $creator, $days ) or die $dbh->errstr; >+ while ( my ( $batch_id, $branch_code ) = $sth->fetchrow_array ) { >+ C4::Labels::Batch::delete( >+ batch_id => $batch_id, >+ branch_code => $branch_code >+ ) if $doit; >+ $count++; >+ } >+ return $count; >+} >+ > sub DeleteExpiredSelfRegs { > my $cnt= C4::Members::DeleteExpiredOpacRegistrations(); > print "Removed $cnt expired self-registered borrowers\n" if $verbose; >-- >2.20.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 15563
:
102934
|
102948
|
103003
|
103004
|
103011
|
103012
|
103492
|
103493
|
107115
|
107639
|
118076
|
118078
|
118081
|
118082
|
118345
|
118762
|
118763
|
118764
|
120082
| 120221