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 => $$params{patron},
26 copy => $$params{copy},
27 requestor => $$params{requestor},
28 titleDescriptor => $$params{title_descriptor},
30 requestLib => $$params{request_lib},
31 pickupLib => $$params{pickup_lib},
36 $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
38 load_scripts($runner);
39 my $result = $runner->run or
40 throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
44 # --------------------------------------------------------------
45 # Extract and uniquify the event list
46 # --------------------------------------------------------------
47 my $events = $result->{events};
48 $logger->debug("circ_permit_hold for user ".$params->{patron}->id." returned events: @$events");
51 push( @allevents, OpenILS::Event->new($_)) for @$events;
52 my %hash = map { ($_->{ilsevent} => $_) } @allevents;
53 @allevents = values %hash;
55 return \@allevents if $$params{show_event_list};
56 return 1 unless @allevents;
65 my $conf = OpenSRF::Utils::SettingsClient->new;
66 my @pfx = ( "apps", "open-ils.circ","app_settings" );
67 my $libs = $conf->config_value(@pfx, 'script_path');
68 $script = $conf->config_value(@pfx, 'scripts', 'circ_permit_hold');
69 $script_libs = (ref($libs)) ? $libs : [$libs];
72 $runner->add_path($_) for(@$script_libs);
73 $runner->load($script);