1 package OpenILS::Utils::PermitHold;
2 use strict; use warnings;
5 use OpenSRF::Utils::SettingsClient;
6 use OpenILS::Utils::ScriptRunner;
7 use OpenILS::Application::AppUtils;
8 use OpenSRF::Utils::Logger qw(:logger);
9 my $U = "OpenILS::Application::AppUtils";
11 my $script; # - the permit script
12 my $script_libs; # - extra script libs
14 # mental note: open-ils.storage.biblio.record_entry.ranged_tree
17 # params within a hash are: copy, patron,
18 # requestor, request_lib, title, title_descriptor
19 sub permit_copy_hold {
22 my $k = 'environment';
23 my $runner = OpenILS::Utils::ScriptRunner->new;
25 $runner->insert( "$k.patron", $$params{patron}, 1);
26 $runner->insert( "$k.title", $$params{title}, 1);
27 $runner->insert( "$k.copy", $$params{copy}, 1);
28 $runner->insert( "$k.requestor", $$params{requestor}, 1);
29 $runner->insert( "$k.requestLib", $$params{request_lib}, 1);
30 $runner->insert( "$k.pickupLib", $$params{pickup_lib}, 1);
31 $runner->insert( "$k.titleDescriptor", $$params{title_descriptor},1);
33 # we get the script result from the event
34 $runner->insert( "result.event", 'SUCCESS' );
35 $runner->insert( "result.events", [] );
37 $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
39 load_scripts($runner);
40 $runner->run or throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
41 my $evtname = $runner->retrieve('result.event');
44 # --------------------------------------------------------------
45 # Extract and uniquify the event list
46 # --------------------------------------------------------------
47 my $events = $runner->retrieve('result.events');
48 $events = [ split(/,/, $events) ];
49 $logger->activity("circ_permit_hold for user ".$params->{patron}->id." returned events: @$events");
52 push( @allevents, OpenILS::Event->new($_)) for @$events;
53 my %hash = map { ($_->{ilsevent} => $_) } @allevents;
54 @allevents = values %hash;
56 return \@allevents if $$params{show_event_list};
57 return 1 unless @allevents;
66 my $conf = OpenSRF::Utils::SettingsClient->new;
67 my @pfx = ( "apps", "open-ils.circ","app_settings" );
68 my $libs = $conf->config_value(@pfx, 'script_path');
69 $script = $conf->config_value(@pfx, 'scripts', 'circ_permit_hold');
70 $script_libs = (ref($libs)) ? $libs : [$libs];
73 $runner->add_path($_) for(@$script_libs);
74 $runner->load($script);