]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm
refactored copy targeter to use new JS copy tester; adjusted object relationships...
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Utils / PermitHold.pm
1 package OpenILS::Utils::PermitHold;
2 use strict; use warnings;
3 use Data::Dumper;
4 use OpenSRF::Utils;
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";
10
11 my $script;                     # - the permit script
12 my $script_libs;        # - extra script libs
13
14 # mental note:  open-ils.storage.biblio.record_entry.ranged_tree
15
16
17 # params within a hash are: copy, patron, 
18 # requestor, request_lib, title, title_descriptor
19 sub permit_copy_hold {
20
21         my $params      = shift;
22         my $k                   = 'environment';
23         my $runner      = OpenILS::Utils::ScriptRunner->new;
24
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.titleDescriptor",  $$params{title_descriptor},1);
31
32         # we get the script result from the event 
33         $runner->insert( "result.event",        'SUCCESS' );
34
35         load_scripts($runner);
36         $runner->run or throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
37         my $evtname = $runner->retrieve('result.event');
38
39         return 1 if $evtname eq 'SUCCESS';
40         return 0;
41 }
42
43
44 sub load_scripts {
45         my $runner = shift;
46
47         if(!$script) {
48                 my $conf = OpenSRF::Utils::SettingsClient->new;
49                 my @pfx = ( "apps", "open-ils.circ","app_settings" );
50                 my $libs        = $conf->config_value(@pfx, 'script_path');
51                 $script = $conf->config_value(@pfx, 'scripts', 'circ_permit_hold');
52                 $script_libs = (ref($libs)) ? $libs : [$libs];
53         }
54
55         $runner->add_path($_) for(@$script_libs);
56         $runner->load($script);
57 }
58
59
60
61 23;