]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/offline-blocked-list.pl
shifting the config file name twice (from ARGV) was not intended
[working/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 = '/openils/bin/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
20     sub runmethod {
21         my $method = shift;
22         my $flag = shift;
23         my $command = "echo \"open-ils.storage $method\" | $oils_reqr -f $config -c $context";
24         warn "-> $command\n";
25
26         my ($child_stdout, $child_stdin);
27         my $pid = open2($child_stdout, $child_stdin, $command);
28         my $x = 0;
29         for my $barcode (<$child_stdout>) {
30             next if $barcode =~ /^oils/o; # hack to chop out the oils_requestor prompt
31             chomp $barcode;
32             $barcode = OpenSRF::Utils::JSON->JSON2perl($barcode);
33             print "$barcode $flag\n" if $barcode;
34         }
35         close($child_stdout);
36         close($child_stdin);
37         waitpid($pid, 0); # don't leave any zombies (see ipc::open2)
38     }
39
40     runmethod('open-ils.storage.actor.user.lost_barcodes', 'L');
41     runmethod('open-ils.storage.actor.user.barred_barcodes', 'B');
42     runmethod('open-ils.storage.actor.user.penalized_barcodes', 'D');
43     # too many, makes the file too large for download
44     #runmethod('open-ils.storage.actor.user.expired_barcodes', 'E');  
45
46 } else {
47
48
49     # ------------------------------------------------------------
50     # Uses the traditional opensrf Perl API approach
51     # ------------------------------------------------------------
52
53     use OpenSRF::EX qw(:try);
54     use OpenSRF::System;
55     use OpenSRF::AppSession;
56
57     OpenSRF::System->bootstrap_client( config_file => $config );
58
59     my $ses = OpenSRF::AppSession->connect( 'open-ils.storage' );
60
61     my $lost = $ses->request( 'open-ils.storage.actor.user.lost_barcodes' );
62     while (my $resp = $lost->recv ) {
63         print $resp->content . " L\n";
64     }
65     $lost->finish;
66
67     if(0) { # XXX just too many... arg
68         my $expired = $ses->request( 'open-ils.storage.actor.user.expired_barcodes' );
69         while (my $resp = $expired->recv ) {
70             print $resp->content . " E\n";
71         }
72         $expired->finish;
73     }
74
75     my $barred = $ses->request( 'open-ils.storage.actor.user.barred_barcodes' );
76     while (my $resp = $barred->recv ) {
77         print $resp->content . " B\n";
78     }
79     $barred->finish;
80
81     my $penalized = $ses->request( 'open-ils.storage.actor.user.penalized_barcodes' );
82     while (my $resp = $penalized->recv ) {
83         print $resp->content . " D\n";
84     }
85     $penalized->finish;
86
87     $ses->disconnect;
88     $ses->finish;
89
90 }
91