@@ -, +, @@ - 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" - run "misc/cronjobs/cleanup_database.pl -v --restrictions 13" - run "misc/cronjobs/cleanup_database.pl -v --restrictions 6" - run without argument "misc/cronjobs/cleanup_database.pl" - run without days "misc/cronjobs/cleanup_database.pl -v --restrictions" --- misc/cronjobs/cleanup_database.pl | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) --- a/misc/cronjobs/cleanup_database.pl +++ a/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; +} --