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 OpenILS::Application::Circ::ScriptBuilder;
9 use OpenSRF::Utils::Logger qw(:logger);
10 my $U = "OpenILS::Application::AppUtils";
12 my $script; # - the permit script
13 my $script_libs; # - extra script libs
15 # mental note: open-ils.storage.biblio.record_entry.ranged_tree
18 # params within a hash are: copy, patron,
19 # requestor, request_lib, title, title_descriptor
20 sub permit_copy_hold {
23 my $runner = OpenILS::Application::Circ::ScriptBuilder->build(
25 patron_id => $$params{patron_id},
26 patron => $$params{patron},
27 copy => $$params{copy},
28 requestor => $$params{requestor},
29 title => $$params{title},
30 volume => $$params{volume},
31 flesh_age_protect => 1,
33 requestLib => $$params{request_lib},
34 pickupLib => $$params{pickup_lib},
39 $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
41 load_scripts($runner);
42 my $result = $runner->run or
43 throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
47 # --------------------------------------------------------------
48 # Extract and uniquify the event list
49 # --------------------------------------------------------------
50 my $events = $result->{events};
51 my $pid = ($params->{patron}) ? $params->{patron}->id : $params->{patron_id};
52 $logger->debug("circ_permit_hold for user $pid returned events: [@$events]");
55 push( @allevents, OpenILS::Event->new($_)) for @$events;
56 my %hash = map { ($_->{ilsevent} => $_) } @allevents;
57 @allevents = values %hash;
59 return \@allevents if $$params{show_event_list};
60 return 1 unless @allevents;
69 my $conf = OpenSRF::Utils::SettingsClient->new;
70 my @pfx = ( "apps", "open-ils.circ","app_settings" );
71 my $libs = $conf->config_value(@pfx, 'script_path');
72 $script = $conf->config_value(@pfx, 'scripts', 'circ_permit_hold');
73 $script_libs = (ref($libs)) ? $libs : [$libs];
76 $runner->add_path($_) for(@$script_libs);
77 $runner->load($script);