]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/offline-blocked-list.pl
safer MR mapping
[Evergreen.git] / Open-ILS / src / support-scripts / offline-blocked-list.pl
1 #!/usr/bin/perl
2 use strict; use warnings;
3
4 my $config = shift || die "Please specify a config file\n";
5 my $context = shift || 'opensrf';
6
7 my $oils_reqr = 'BINDIR/oils_requestor'; # XXX command line param
8
9 if(1) { # XXX command line param
10
11     # ------------------------------------------------------------
12     # This sends the method calls to storage via oils_requestor,
13     # which is able to process the results much faster
14     # Make this the default for now.
15     # ------------------------------------------------------------
16
17     use OpenSRF::Utils::JSON;
18     use IPC::Open2 qw/open2/;
19     use Net::Domain qw/hostfqdn/;
20
21     sub runmethod {
22         my $method = shift;
23         my $flag = shift;
24         my $hostname = hostfqdn();
25         my $command = "echo \"open-ils.storage $method\" | $oils_reqr -f $config -c $context -h $hostname";
26         warn "-> $command\n";
27
28         my ($child_stdout, $child_stdin);
29         my $pid = open2($child_stdout, $child_stdin, $command);
30         my $x = 0;
31         for my $barcode (<$child_stdout>) {
32             next if $barcode =~ /^oils/o; # hack to chop out the oils_requestor prompt
33             chomp $barcode;
34             $barcode = OpenSRF::Utils::JSON->JSON2perl($barcode);
35             print "$barcode $flag\n" if $barcode;
36         }
37         close($child_stdout);
38         close($child_stdin);
39         waitpid($pid, 0); # don't leave any zombies (see ipc::open2)
40     }
41
42     runmethod('open-ils.storage.actor.user.lost_barcodes', 'L');
43     runmethod('open-ils.storage.actor.user.barred_barcodes', 'B');
44     runmethod('open-ils.storage.actor.user.penalized_barcodes', 'D');
45     # too many, makes the file too large for download
46     #runmethod('open-ils.storage.actor.user.expired_barcodes', 'E');  
47
48 } else {
49
50
51     # ------------------------------------------------------------
52     # Uses the traditional opensrf Perl API approach
53     # ------------------------------------------------------------
54
55     use OpenSRF::EX qw(:try);
56     use OpenSRF::System;
57     use OpenSRF::AppSession;
58
59     OpenSRF::System->bootstrap_client( config_file => $config );
60
61     my $ses = OpenSRF::AppSession->connect( 'open-ils.storage' );
62
63     my $lost = $ses->request( 'open-ils.storage.actor.user.lost_barcodes' );
64     while (my $resp = $lost->recv ) {
65         print $resp->content . " L\n";
66     }
67     $lost->finish;
68
69     if(0) { # XXX just too many... arg
70         my $expired = $ses->request( 'open-ils.storage.actor.user.expired_barcodes' );
71         while (my $resp = $expired->recv ) {
72             print $resp->content . " E\n";
73         }
74         $expired->finish;
75     }
76
77     my $barred = $ses->request( 'open-ils.storage.actor.user.barred_barcodes' );
78     while (my $resp = $barred->recv ) {
79         print $resp->content . " B\n";
80     }
81     $barred->finish;
82
83     my $penalized = $ses->request( 'open-ils.storage.actor.user.penalized_barcodes' );
84     while (my $resp = $penalized->recv ) {
85         print $resp->content . " D\n";
86     }
87     $penalized->finish;
88
89     $ses->disconnect;
90     $ses->finish;
91
92 }
93