applied mikes 3month implies 6month patch to hold permit, added log line
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 21 Sep 2006 04:18:36 +0000 (04:18 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 21 Sep 2006 04:18:36 +0000 (04:18 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6171 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm

index 4446c90..13b6a88 100644 (file)
@@ -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;