hold permit now conscious of script-builder failure events
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 17 Aug 2006 14:49:08 +0000 (14:49 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 17 Aug 2006 14:49:08 +0000 (14:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5556 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/extras/ils_events.xml
Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm

index 91ad2c2..68e86fd 100644 (file)
        <event code='1223' textcode='PATRON_NO_PHONE'>
                <desc xml:lang="en-US">The user does not have a valid phone number assigned</desc>
        </event>
+       <event code='1224' textcode='PATRON_ACCOUNT_EXPIRED'>
+               <desc xml:lang="en-US">The patron's account has expired</desc>
+       </event>
 
 
 
index 5113b97..f818e6f 100644 (file)
@@ -39,38 +39,50 @@ sub permit_copy_hold {
 
        my $runner = OpenILS::Application::Circ::ScriptBuilder->build($ctx);
 
-       # check the various holdable flags
-       push( @allevents, OpenILS::Event->new('ITEM_NOT_HOLDABLE') )
-               unless $U->is_true($ctx->{copy}->holdable);
-
-       push( @allevents, OpenILS::Event->new('ITEM_NOT_HOLDABLE') )
-               unless $U->is_true($ctx->{copy}->location->holdable);
-
-       push( @allevents, OpenILS::Event->new('ITEM_NOT_HOLDABLE') )
-               unless $U->is_true($ctx->{copy}->status->holdable);
-
-       my $evt = check_age_protect($ctx->{patron}, $ctx->{copy});
-       push( @allevents, $evt ) if $evt;
-
-       $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
-
-       load_scripts($runner);
-       my $result = $runner->run or 
-               throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
-
-       $runner->cleanup;
-
-       # --------------------------------------------------------------
-       # Extract and uniquify the event list
-       # --------------------------------------------------------------
-       my $events = $result->{events};
-       my $pid = ($params->{patron}) ? $params->{patron}->id : $params->{patron_id};
-       $logger->debug("circ_permit_hold for user $pid returned events: [@$events]");
+       if( $ctx->{_events} ) {
+               push( @allevents, $_) for @{$ctx->{_events}};
+
+               # --------------------------------------------------------------
+               # If scriptbuilder returned any events, then the script context
+               # is undefined and should not be used
+               # --------------------------------------------------------------
+
+       } else {
+
+               # check the various holdable flags
+               push( @allevents, OpenILS::Event->new('ITEM_NOT_HOLDABLE') )
+                       unless $U->is_true($ctx->{copy}->holdable);
+       
+               push( @allevents, OpenILS::Event->new('ITEM_NOT_HOLDABLE') )
+                       unless $U->is_true($ctx->{copy}->location->holdable);
+       
+               push( @allevents, OpenILS::Event->new('ITEM_NOT_HOLDABLE') )
+                       unless $U->is_true($ctx->{copy}->status->holdable);
+       
+               my $evt = check_age_protect($ctx->{patron}, $ctx->{copy});
+               push( @allevents, $evt ) if $evt;
+       
+               $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
+       
+               load_scripts($runner);
+               my $result = $runner->run or 
+                       throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
+
+               # --------------------------------------------------------------
+               # Extract and uniquify the event list
+               # --------------------------------------------------------------
+               my $events = $result->{events};
+               my $pid = ($params->{patron}) ? $params->{patron}->id : $params->{patron_id};
+               $logger->debug("circ_permit_hold for user $pid returned events: [@$events]");
+       
+               push( @allevents, OpenILS::Event->new($_)) for @$events;
+       }
 
-       push( @allevents, OpenILS::Event->new($_)) for @$events;
        my %hash = map { ($_->{ilsevent} => $_) } @allevents;
        @allevents = values %hash;
 
+       $runner->cleanup;
+
        return \@allevents if $$params{show_event_list};
        return 1 unless @allevents;
        return 0;