From 9cf053f05c4996c75760f39fe812b5b851aca4a3 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Wed, 14 Nov 2012 11:27:53 -0500 Subject: [PATCH] Add calculate_expire_time helper function to Holds.pm. This new function calculates an expire_time for a hold based on the hold expiration interval setting for a passed in org_unit. If the setting is found the interval is added to "now" and returned as an ISO8601 string. undef is returned if the setting is not found for the org_unit or its ancestors. Signed-off-by: Jason Stephenson Signed-off-by: Ben Shum --- .../perlmods/lib/OpenILS/Application/Circ/Holds.pm | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm index 1a647c9642..617f4de543 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Holds.pm @@ -317,11 +317,7 @@ sub create_hold { # set the configured expire time unless($hold->expire_time) { - my $interval = $U->ou_ancestor_setting_value($recipient->home_ou, OILS_SETTING_HOLD_EXPIRE); - if($interval) { - my $date = DateTime->now->add(seconds => OpenSRF::Utils::interval_to_seconds($interval)); - $hold->expire_time($U->epoch2ISO8601($date->epoch)); - } + $hold->expire_time(calculate_expire_time($recipient->home_ou)); } $hold->requestor($e->requestor->id); @@ -683,11 +679,7 @@ sub uncancel_hold { $hold->request_lib, 'circ.holds.uncancel.reset_request_time', $e)) { $hold->request_time('now'); - my $interval = $U->ou_ancestor_setting_value($hold->request_lib, OILS_SETTING_HOLD_EXPIRE); - if($interval) { - my $date = DateTime->now->add(seconds => OpenSRF::Utils::interval_to_seconds($interval)); - $hold->expire_time($U->epoch2ISO8601($date->epoch)); - } + $hold->expire_time(calculate_expire_time($hold->request_lib)); } $hold->clear_cancel_time; @@ -3981,9 +3973,19 @@ sub rec_hold_count { return new_editor()->json_query($query)->[0]->{count}; } - - - - +# A helper function to calculate a hold's expiration time at a given +# org_unit. Takes the org_unit as an argument and returns either the +# hold expire time as an ISO8601 string or undef if there is no hold +# expiration interval set for the subject ou. +sub calculate_expire_time +{ + my $ou = shift; + my $interval = $U->ou_ancestor_setting_value($ou, OILS_SETTING_HOLD_EXPIRE); + if($interval) { + my $date = DateTime->now->add(seconds => OpenSRF::Utils::interval_to_seconds($interval)); + return $U->epoch2ISO8601($date->epoch); + } + return undef; +} 1; -- 2.11.0