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