From 68d5066fb1f682c44f5dc588827c8cb03848969c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 22 Dec 2022 21:02:56 +0000 Subject: [PATCH] Bug 32518: Add reason option to cancel_unfilled_holds cronjob This adds a reaosn parameter and passes it into the cancellation if supplied To test: 1 - Place a hold for a patron in your system 2 - Run script with --days 0 -v 3 - verify that it would cancel the reserves (and that you are okay with cancelling the ones it found) 4 - Make sure you have a notice in the holds module with code 'HOLD_CANCELLATION' 5 - Set content of the notice like: [% IF hold.cancellation_reason=='too_old' %] Canceled old [% END %] 6 - Run script with --days 0 -v --reason too_bad -c 7 - Confirm hold cancelled, no notice sent to patron 8 - Place another hold 9 - Run script with --days 0 -v --reason too_old -c 10 - Confirm hold cancelled, notice sent to patron --- misc/cronjobs/holds/cancel_unfilled_holds.pl | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/holds/cancel_unfilled_holds.pl b/misc/cronjobs/holds/cancel_unfilled_holds.pl index 82e2b18516..a4e99b5f66 100755 --- a/misc/cronjobs/holds/cancel_unfilled_holds.pl +++ b/misc/cronjobs/holds/cancel_unfilled_holds.pl @@ -37,7 +37,7 @@ number of days. =head1 SYNOPSIS - cancel_unfilled_holds.pl [--days][--library][--holidays][--confirm][--verbose] + cancel_unfilled_holds.pl [--days][--library][--holidays][--confirm][--verbose][--reason] =head1 OPTIONS @@ -69,6 +69,10 @@ would have done if it were not running in test mode. More verbose output. +=item B<--reason> + +Optionally adds a reason for cancellation (which will trigger a notice to be sent to the patron) + =back =cut @@ -79,6 +83,7 @@ my @branchcodes; my $use_calendar = 0; my $verbose = 0; my $confirm = 0; +my $reason; my $command_line_options = join(" ",@ARGV); @@ -89,6 +94,7 @@ GetOptions( 'holidays' => \$use_calendar, 'v|verbose' => \$verbose, 'confirm' => \$confirm, + 'reason=s' => \$reason ) or pod2usage(1); pod2usage(1) if $help; @@ -111,6 +117,9 @@ $verbose and warn "Looking for unfilled holds placed $days or more days ago\n"; @branchcodes = Koha::Libraries->search->get_column('branchcode') if !@branchcodes; $verbose and warn "Running for branch(es): " . join( "|", @branchcodes ) . "\n"; +my $cancellation_params = {}; +$cancellation_params->{cancellation_reason} = $reason if $reason; + foreach my $branch (@branchcodes) { my $holds = @@ -135,7 +144,7 @@ foreach my $branch (@branchcodes) { . $hold->borrowernumber . " on biblio: " . $hold->biblionumber . "\n"; - $hold->cancel if $confirm; + $hold->cancel( $cancellation_params ) if $confirm; } } -- 2.30.2