From 623aa508cd268fc1a8aad844bcefca246857695c Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 21 Sep 2006 04:18:36 +0000 Subject: [PATCH] applied mikes 3month implies 6month patch to hold permit, added log line git-svn-id: svn://svn.open-ils.org/ILS/trunk@6171 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm | 47 ++++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm b/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm index 4446c908b3..13b6a886a1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm @@ -130,32 +130,43 @@ sub check_age_protect { # age protect does not apply return undef if $prox <= $copy->age_protect->prox; - # How many seconds old does the copy have to be to escape age protection - my $interval = OpenSRF::Utils::interval_to_seconds($copy->age_protect->age); - my $start_date = time - $interval; + my $protection_list = $U->storagereq( + 'open-ils.storage.direct.config.rules.age_hold_protect.search_where.atomic', + { age => { '>=' => $copy->age_protect->age }, + prox => { '>=' => $copy->age_protect->prox }, + }, + { order_by => 'age' } + ); # Now, now many seconds old is this copy - my $dparser = DateTime::Format::ISO8601->new; - my $create_date = $dparser->parse_datetime( - OpenSRF::Utils::clense_ISO8601($copy->create_date)); - my $age = $create_date->epoch; - - $logger->info("age_protect interval=$interval, create_date=$create_date, age=$age, start_date=$start_date"); - - if( $start_date < $age ) { - # if start date is older (less than) than the age of the item, - # the item falls within the age protect range - $logger->info("age_protect prevents copy from having a hold placed on it: ".$copy->id); - return OpenILS::Event->new('ITEM_AGE_PROTECTED', copy => $copy->id ); - } + my $create_date = DateTime::Format::ISO8601 + ->new + ->parse_datetime( OpenSRF::Utils::clense_ISO8601($copy->create_date) ) + ->epoch; - return undef; -} + my $age = time - $create_date; + for my $protection ( @$protection_list ) { + $logger->info("analyzing age protect ".$protection->name); + # age protect does not apply if within the proximity + last if $prox <= $protection->prox; + # How many seconds old does the copy have to be to escape age protection + my $interval = OpenSRF::Utils::interval_to_seconds($protection->age); + $logger->info("age_protect interval=$interval, create_date=$create_date, age=$age"); + if( $interval > $age ) { + # if age of the item is less than the protection interval, + # the item falls within the age protect range + $logger->info("age_protect prevents copy from having a hold placed on it: ".$copy->id); + return OpenILS::Event->new('ITEM_AGE_PROTECTED', copy => $copy->id ); + } + } + + return undef; +} 23; -- 2.11.0