@@ -, +, @@ cancel_expired_holds --- C4/Reserves.pm | 2 + misc/cronjobs/holds/cancel_expired_holds.pl | 52 +++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -901,6 +901,7 @@ Cancels all reserves with an expiration date from before today. =cut sub CancelExpiredReserves { + my $cancellation_reason = shift; my $today = dt_from_string(); my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays'); my $expireWaiting = C4::Context->preference('ExpireReservesMaxPickUpDelay'); @@ -918,6 +919,7 @@ sub CancelExpiredReserves { next if !$cancel_on_holidays && $calendar->is_holiday( $today ); my $cancel_params = {}; + $cancel_params->{cancellation_reason} = $cancellation_reason if defined($cancellation_reason); if ( $hold->found eq 'W' ) { $cancel_params->{charge_cancel_fee} = 1; } --- a/misc/cronjobs/holds/cancel_expired_holds.pl +++ a/misc/cronjobs/holds/cancel_expired_holds.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl # Copyright 2009-2010 Kyle Hall +# Copyright 2020 PTFS Europe # # This file is part of Koha. # @@ -17,7 +18,29 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . +=head1 NAME + +cancel_expired_holds.pl - cron script to cancel holds as they expire + +=head1 SYNOPSIS + + ./cancel_expired_holds.pl + ./cancel_expired_holds.pl --reason="EXPIRED" + +or, in crontab: + + 0 1 * * * cancel_expired_holds.pl + 0 1 * * * cancel_expired_holds.pl --reason="EXPIRED" + +=head1 DESCRIPTION + +This script calls C4::Reserves::CancelExpiredReserves which will find and cancel all expired reseves in the system. + +=cut + use Modern::Perl; +use Getopt::Long; +use Pod::Usage; BEGIN { # find Koha's Perl modules @@ -26,12 +49,35 @@ BEGIN { eval { require "$FindBin::Bin/../kohalib.pl" }; } -# cancel all expired hold requests - use Koha::Script -cron; use C4::Reserves; use C4::Log; +=head1 OPTIONS + +=over 8 + +=item B<--help> + +Print a brief help message and exits. + +=item B<--reason> + +Optionally adds a reason for cancellation (which will trigger a notice to be sent to the patron) + +=back + +=cut + +my $help = 0; +my $reason; + +GetOptions( + 'help|?' => \$help, + 'reason=s' => \$reason +) or pod2usage(1); +pod2usage(1) if $help; + cronlogaction(); -CancelExpiredReserves(); +CancelExpiredReserves($reason); --