more checkout code
[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         $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
36
37         load_scripts($runner);
38         $runner->run or throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
39         my $evtname = $runner->retrieve('result.event');
40
41         return 1 if $evtname eq 'SUCCESS';
42         return 0;
43 }
44
45
46 sub load_scripts {
47         my $runner = shift;
48
49         if(!$script) {
50                 my $conf = OpenSRF::Utils::SettingsClient->new;
51                 my @pfx = ( "apps", "open-ils.circ","app_settings" );
52                 my $libs        = $conf->config_value(@pfx, 'script_path');
53                 $script = $conf->config_value(@pfx, 'scripts', 'circ_permit_hold');
54                 $script_libs = (ref($libs)) ? $libs : [$libs];
55         }
56
57         $runner->add_path($_) for(@$script_libs);
58         $runner->load($script);
59 }
60
61
62
63 23;