From f897ec9b00331eb1674431c27f8f70d8a457f24b Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 30 Oct 2014 11:59:28 +0100 Subject: [PATCH] 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 --- misc/cronjobs/cleanup_database.pl | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 57a5401..c80b7b9 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -69,6 +69,7 @@ Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu days. Defaults to 14 days if no days specified. --restrictions DAYS purge patrons restrictions expired since more than DAYS days. Defaults to 30 days if no days specified. + --all-restrictions purge all expired patrons restrictions. USAGE exit $_[0]; } @@ -76,7 +77,7 @@ USAGE my ( $help, $sessions, $sess_days, $verbose, $zebraqueue_days, $mail, $purge_merged, $pImport, $pLogs, $pSearchhistory, - $pZ3950, $pListShareInvites, $pDebarments, + $pZ3950, $pListShareInvites, $pDebarments, $allDebarments, ); GetOptions( @@ -93,6 +94,7 @@ GetOptions( 'searchhistory:i' => \$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.9.1