From eb6f589045043e42f5f15c5b7834dd77ed772117 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 30 Oct 2014 11:59:28 +0100 Subject: [PATCH] [SIGNED OFF] Bug 13166 - add all restrictions purge to cleanup_database.pl Bug 12760 adds the ability to purge expired restrictions older than some days. But if you want to purge all expired restrictions, using "--restrictions 0" does not work, it's like "--restrictions" so it uses default purge days. This patch adds a new option "--all-restrictions" to purge all expired restrictions. Test plan : - Select a borrower - Create a restriction with expiration date in the futur - Create a restriction expired since 1 day - Create a restriction expired since 10 days - run without argument "misc/cronjobs/cleanup_database.pl" => You see help text for --all-restrictions option - run "misc/cronjobs/cleanup_database.pl -v --restrictions --all-restrictions" => You get the message : You can not specify both --restrictions and --all-restrictions - run "misc/cronjobs/cleanup_database.pl -v --restrictions 30" => no restriction is removed - run "misc/cronjobs/cleanup_database.pl -v --restrictions 9" => restriction expired since 10 days is removed - run "misc/cronjobs/cleanup_database.pl -v --all-restrictions" => restriction expired since 1 day is removed Signed-off-by: Larry Baerveldt --- misc/cronjobs/cleanup_database.pl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 57a5401..2dc3f2e 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -43,7 +43,7 @@ use Getopt::Long; sub usage { print STDERR < \$pSearchhistory, 'list-invites:i' => \$pListShareInvites, 'restrictions:i' => \$pDebarments, + 'all-restrictions' => \$allDebarments, ) || usage(1); # Use default values @@ -118,12 +120,18 @@ unless ( $sessions || $pSearchhistory || $pZ3950 || $pListShareInvites - || $pDebarments ) + || $pDebarments + || $allDebarments ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); } +if ($pDebarments && $allDebarments) { + print "You can not specify both --restrictions and --all-restrictions.\n\n"; + usage(1); +} + my $dbh = C4::Context->dbh(); my $sth; my $sth2; @@ -234,10 +242,16 @@ if ($pListShareInvites) { if ($pDebarments) { print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose; - $count = PurgeDebarments(); + $count = PurgeDebarments($pDebarments); print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose; } +if($allDebarments) { + print "All expired patrons restrictions purge triggered.\n" if $verbose; + $count = PurgeDebarments(0); + print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { @@ -309,6 +323,7 @@ sub PurgeZ3950 { sub PurgeDebarments { require Koha::Borrower::Debarments; + my $days = shift; $count = 0; $sth = $dbh->prepare( q{ @@ -317,7 +332,7 @@ sub PurgeDebarments { WHERE expiration < date_sub(curdate(), INTERVAL ? DAY) } ); - $sth->execute($pDebarments) or die $dbh->errstr; + $sth->execute($days) or die $dbh->errstr; while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) { Koha::Borrower::Debarments::DelDebarment($borrower_debarment_id); $count++; -- 1.7.10.4