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 <larry@bywatersolutions.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
7a94c50fa6
commit
1682815580
|
|
@ -43,7 +43,7 @@ use Getopt::Long;
|
|||
|
||||
sub usage {
|
||||
print STDERR <<USAGE;
|
||||
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS]
|
||||
Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions]
|
||||
|
||||
-h --help prints this help message, and exits, ignoring all
|
||||
other options
|
||||
|
|
@ -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++;
|
||||
|
|
|
|||
Loading…
Reference in New Issue