From e584b9adcb6fafb96ce77fcd84b68f6f697478f4 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Mon, 8 Jul 2024 11:30:16 +0000 Subject: [PATCH] Bug 32696: Recalls can inadvertently extend the due date If an item is due sooner than the recall due date interval then placing a recall on it can inadvertently extend the book's due date, possibly causing the recalling patron to receive the item later than they would otherwise. Test plan: ========= 1. Turn on recalls with UseRecalls. 2. In circulation rules, set the recall due date interval to 7 days or any other arbitrary period. 3. Check out an item to one patron & set the due date to be before the recall due date interval will have elapsed (e.g. the next day) 4. As a second patron, place a recall on the item in question. 5. See that the item's due date is extended to the current date plus the recalls due date interval. 6. Apply the patch, restart_all; 7. Repeat steps 3. and 4. See that the due date has not been extended. BTW, the calculation of $due_interval has been changed, because with the current code and empty 'Recall due date interval' $due_interval is undefined, despite the intention of the author of the code. (after calling get_effective_rule $recall_due_date_interval is defined, but $recall_due_date_interval->rule_value is undefined; the patron gets a message: '... return the item within days, by ...' - no days count). Sponsored-by: Ignatianum University in Cracow Signed-off-by: Roman Dolny Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer --- Koha/Recalls.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Koha/Recalls.pm b/Koha/Recalls.pm index 9f6d14e364..332f1deb79 100644 --- a/Koha/Recalls.pm +++ b/Koha/Recalls.pm @@ -18,6 +18,7 @@ package Koha::Recalls; # along with Koha; if not, see . use Modern::Perl; +use DateTime; use Koha::Database; use Koha::Recall; @@ -140,16 +141,19 @@ sub add_recall { branchcode => $branchcode, rule_name => 'recall_due_date_interval', }); - my $due_interval = defined $recall_due_date_interval ? $recall_due_date_interval->rule_value : 5; - my $timestamp = dt_from_string( $recall->timestamp ); - my $checkout_timestamp = dt_from_string( $checkout->date_due ); - my $due_date = $timestamp->set( + my $due_interval = 5; + $due_interval = $recall_due_date_interval->rule_value + if defined $recall_due_date_interval && $recall_due_date_interval->rule_value; + my $timestamp = dt_from_string( $recall->timestamp ); + my $checkout_due_date = dt_from_string( $checkout->date_due ); + my $recall_due_date = $timestamp->set( { - hour => $checkout_timestamp->hour, minute => $checkout_timestamp->minute, - second => $checkout_timestamp->second + hour => $checkout_due_date->hour, minute => $checkout_due_date->minute, + second => $checkout_due_date->second } )->add( days => $due_interval ); - $checkout->update( { date_due => $due_date } ); + $checkout->update( { date_due => $recall_due_date } ) + if DateTime->compare( $recall_due_date, $checkout_due_date ) == -1; # get itemnumber of most relevant checkout if a biblio-level recall unless ( $recall->item_level ) { $itemnumber = $checkout->itemnumber; } @@ -200,7 +204,7 @@ sub add_recall { # add action log C4::Log::logaction( 'RECALLS', 'CREATE', $recall->id, "Recall requested by borrower #" . $recall->patron_id, $interface ) if ( C4::Context->preference('RecallsLog') ); - return ( $recall, $due_interval, $due_date ); + return ( $recall, $due_interval, $recall_due_date ); } # unable to add recall -- 2.39.5