Bug 30666: Holds reminder cronjob (holds_reminder.pl) uses DataTime::subtract wrong
authorKyle M Hall <kyle@bywatersolutions.com>
Tue, 3 May 2022 10:29:49 +0000 (06:29 -0400)
committerFridolin Somers <fridolin.somers@biblibre.com>
Sat, 14 May 2022 01:41:55 +0000 (15:41 -1000)
commit84f7b7a7a38dff121f5f8b7d891632108edb218d
treea9bfeeb09b554f462e1810b8fa313c9a09525450
parenta7e7939748ef9c3f8df8aefb20f5ca9169d4575d
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 <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
misc/cronjobs/holds/holds_reminder.pl