Bug 29704: Add a triggered option to holds_reminder.pl

This patch adds an option to only trigger notices matching the number of
days waiting specified

You will need to define HOLD_REMINDER notices for the specific branch of the
patron and ensure the patron has hold reminder notices in their messaging preferences

TO test:
1 - Place a hold for a patron and check in to confirm
2 - Set the waiting date back a few days:
    update reserves set waitingdate = DATE_SUB(CURDATE(), INTERVAL 5 DAY);
3 - Run the cron and see that patron would be notified if running for 4 days weaiting
    perl misc/cronjobs/holds/holds_reminder.pl -v --days 4
4 - Apply patch
5 - perl misc/cronjobs/holds/holds_reminder.pl -v --days 4 --triggered
6 - Note patron would not be notified
7 - perl misc/cronjobs/holds/holds_reminder.pl -v --days 5 --triggered
8 - Note patron is notified when days waiting matches exactly

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit b392547ab6)

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2021-12-17 15:49:17 +00:00 committed by Andrew Fuerste-Henry
parent 3015598a54
commit fe4314f529
1 changed files with 12 additions and 1 deletions

View File

@ -57,6 +57,7 @@ holds_reminder.pl
-v verbose
-c --confirm confirm, if not set no email will be sent
-days <days> days waiting to deal with
-t --triggered include only holds <days> days waiting, and not longer
-lettercode <lettercode> predefined notice to use, default is HOLD_REMINDER
-library <branchname> only deal with holds from this library (repeatable : several libraries can be given)
-holidays use the calendar to not count holidays as waiting days
@ -93,6 +94,13 @@ Optional parameter, number of days an items has been 'waiting' on hold
to send a message for. If not included a notice will be sent to all
patrons with waiting holds.
=item B<-triggered>
Optional parameter, only sned notices for holds exactly <days> waiting.
If not included a notice will be sent to all patrons with waiting holds
equal to OR greater than <days>. This option is useful if the cron is
being run daily to avoid spamming the patrons.
=item B<-lettercode>
Optional parameter, choose a notice to use. Default is 'HOLD_REMINDER'.
@ -167,6 +175,7 @@ my $man = 0;
my $verbose = 0;
my $confirm = 0;
my $days ;
my $triggered = 0;
my $lettercode;
my @branchcodes; # Branch(es) passed as parameter
my $use_calendar = 0;
@ -180,6 +189,7 @@ GetOptions(
'v' => \$verbose,
'c|confirm' => \$confirm,
'days=s' => \$days,
'triggered' => \$triggered,
'lettercode=s' => \$lettercode,
'library=s' => \@branchcodes,
'date=s' => \$date_input,
@ -242,8 +252,9 @@ foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP
# Find all the holds waiting since this date for the current branch
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
my $waiting_since = $dtf->format_date( $waiting_date );
my $comparator = $triggered ? '=' : '<=';
my $reserves = Koha::Holds->search({
waitingdate => {'<=' => $waiting_since },
waitingdate => {$comparator => $waiting_since },
'me.branchcode' => $branchcode,
},{ prefetch => 'patron' });