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;