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 throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
41 $runner->context->destroy;
43 # --------------------------------------------------------------
44 # Extract and uniquify the event list
45 # --------------------------------------------------------------
46 my $events = $result->{events};
47 $logger->debug("circ_permit_hold for user ".$params->{patron}->id." returned events: @$events");
50 push( @allevents, OpenILS::Event->new($_)) for @$events;
51 my %hash = map { ($_->{ilsevent} => $_) } @allevents;
52 @allevents = values %hash;
54 return \@allevents if $$params{show_event_list};
55 return 1 unless @allevents;
64 my $conf = OpenSRF::Utils::SettingsClient->new;
65 my @pfx = ( "apps", "open-ils.circ","app_settings" );
66 my $libs = $conf->config_value(@pfx, 'script_path');
67 $script = $conf->config_value(@pfx, 'scripts', 'circ_permit_hold');
68 $script_libs = (ref($libs)) ? $libs : [$libs];
71 $runner->add_path($_) for(@$script_libs);
72 $runner->load($script);