]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Utils/PermitHold.pm
doing some manual memory cleanup for circ references
[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 OpenILS::Application::Circ::ScriptBuilder;
9 use OpenSRF::Utils::Logger qw(:logger);
10 my $U   = "OpenILS::Application::AppUtils";
11
12 my $script;                     # - the permit script
13 my $script_libs;        # - extra script libs
14
15 # mental note:  open-ils.storage.biblio.record_entry.ranged_tree
16
17
18 # params within a hash are: copy, patron, 
19 # requestor, request_lib, title, title_descriptor
20 sub permit_copy_hold {
21         my $params      = shift;
22
23         my $runner = OpenILS::Application::Circ::ScriptBuilder->build(
24                 {
25                         patron          => $$params{patron},
26                         copy                    => $$params{copy},
27                         requestor       => $$params{requestor},
28                         titleDescriptor => $$params{title_descriptor},
29                         _direct => {
30                                 requestLib      => $$params{request_lib},
31                                 pickupLib       => $$params{pickup_lib},
32                         }
33                 }
34         );
35
36         $logger->debug("Running permit_copy_hold on copy " . $$params{copy}->id);
37
38         load_scripts($runner);
39         my $result = $runner->run or throw OpenSRF::EX::ERROR ("Hold Copy Permit Script Died: $@");
40
41         $runner->context->destroy;
42
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");
48
49         my @allevents;
50         push( @allevents, OpenILS::Event->new($_)) for @$events;
51         my %hash = map { ($_->{ilsevent} => $_) } @allevents;
52         @allevents = values %hash;
53
54         return \@allevents if $$params{show_event_list};
55         return 1 unless @allevents;
56         return 0;
57 }
58
59
60 sub load_scripts {
61         my $runner = shift;
62
63         if(!$script) {
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];
69         }
70
71         $runner->add_path($_) for(@$script_libs);
72         $runner->load($script);
73 }
74
75
76
77 23;