Browse Source

Bug 30666: Holds reminder cronjob ( uses DataTime::subtract wrong

In, 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/ --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 <>

Signed-off-by: Marcel de Rooy <>
Signed-off-by: Fridolin Somers <>
Kyle Hall 3 weeks ago
committed by Fridolin Somers
  1. 4


@ -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