From 6d0a9b47f8b4c35b915c73a9b2b1a1c10cd4f174 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 3 May 2022 06:29:49 -0400 Subject: [PATCH] Bug 30666: Holds reminder cronjob (holds_reminder.pl) uses DataTime::subtract wrong In holds_reminder.pl, the script loops over all available branchcodes. For each iteration of the loop, if not using the calendar, the script subtracts the days parameter from the current date to get the waiting date threshold. The problem is that this method alters the DateTime object in $date_to_run, so for each iteration of the loop, the waiting date becomes farther and farther in the past, when it should always be the same! The solution is to either clone the "date to run" for each call to subtract, or to move it out of the loop since it doesn't need to be recalculated each time. Test Plan: 1) Become the koha user using koha-shell 2) Run DBIC_TRACE=1 misc/cronjobs/holds/holds_reminder.pl --days 7 3) Note in the queries that for each loop, the waiting date is different 4) Apply this patch 5) Run the command in step 2 again 6) Note the queries all now have the same waiting date threshold! Signed-off-by: David Nind --- misc/cronjobs/holds/holds_reminder.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/cronjobs/holds/holds_reminder.pl b/misc/cronjobs/holds/holds_reminder.pl index f580cd7374..b99259f43d 100755 --- a/misc/cronjobs/holds/holds_reminder.pl +++ b/misc/cronjobs/holds/holds_reminder.pl @@ -223,6 +223,8 @@ else { $date_to_run = dt_from_string(); } +my $waiting_date_static = $date_to_run->clone->subtract( days => $days ); + # Loop through each branch foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP # Check that this branch has the letter code specified or skip this branch @@ -248,7 +250,7 @@ foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP my $duration = DateTime::Duration->new( days => -$days ); $waiting_date = $calendar->addDays($date_to_run,$duration); #Add negative of days } else { - $waiting_date = $date_to_run->subtract( days => $days ); + $waiting_date = $waiting_date_static; } # Find all the holds waiting since this date for the current branch -- 2.30.2