From 72f71b035ca6f50e4dea3838e8c9b1e047d93833 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 14 Aug 2014 14:56:26 +0200 Subject: [PATCH] Bug 12760 - add restrictions purge to cleanup_database.pl This patch adds to the database cleanup script an option to purge expired patron restrictions (debarments in code). Test plan : - Select a borrower - Create a restriction with expiration date in the futur - Create a restriction expired since 7 days - Create a restriction expired since 14 days - run "misc/cronjobs/cleanup_database.pl -v --restrictions 14" => no restriction is removed for this borrower - run "misc/cronjobs/cleanup_database.pl -v --restrictions 13" => restriction expired since 14 days is removed - run "misc/cronjobs/cleanup_database.pl -v --restrictions 6" => restriction expired since 7 days is removed - run without argument "misc/cronjobs/cleanup_database.pl" => You see help text for restrictions option - run without days "misc/cronjobs/cleanup_database.pl -v --restrictions" => You get a purge on 30 days Signed-off-by: Chris Cormack --- misc/cronjobs/cleanup_database.pl | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index fa27e9b..49c0157 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -26,6 +26,7 @@ use constant DEFAULT_IMPORT_PURGEDAYS => 60; use constant DEFAULT_LOGS_PURGEDAYS => 180; use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30; use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14; +use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; BEGIN { # find Koha's Perl modules @@ -43,7 +44,7 @@ use Getopt::Long; sub usage { print STDERR < \$pLogs, 'searchhistory:i' => \$pSearchhistory, 'list-invites:i' => \$pListShareInvites, + 'restrictions:i' => \$pDebarments, ) || usage(1); $sessions=1 if $sess_days && $sess_days>0; @@ -102,6 +106,7 @@ $zebraqueue_days= DEFAULT_ZEBRAQ_PURGEDAYS if defined($zebraqueue_days) && $zebr $mail= DEFAULT_MAIL_PURGEDAYS if defined($mail) && $mail==0; $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; if ($help) { usage(0); @@ -115,7 +120,8 @@ unless ( $sessions || $pLogs || $pSearchhistory || $pZ3950 - || $pListShareInvites ) + || $pListShareInvites + || $pDebarments ) { print "You did not specify any cleanup work for the script to do.\n\n"; usage(1); @@ -224,6 +230,12 @@ if ($pListShareInvites) { print "Done with purging unaccepted list share invites.\n" if $verbose; } +if($pDebarments) { + print "Expired patrons restrictions purge triggered for $pDebarments days.\n" if $verbose; + $count = PurgeDebarments(); + print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose; +} + exit(0); sub RemoveOldSessions { @@ -279,3 +291,17 @@ sub PurgeZ3950 { }); $sth->execute() or die $dbh->errstr; } + +sub PurgeDebarments { + require Koha::Borrower::Debarments; + $count = 0; + $sth = $dbh->prepare(q{ + SELECT borrower_debarment_id FROM borrower_debarments WHERE expiration < date_sub(curdate(), INTERVAL ? DAY) + }); + $sth->execute($pDebarments) or die $dbh->errstr; + while ( my ($borrower_debarment_id) = $sth->fetchrow_array ) { + Koha::Borrower::Debarments::DelDebarment($borrower_debarment_id); + $count++; + } + return $count; +} -- 1.9.1