]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/support-scripts/offline-blocked-list.pl
gave the offline patron blocked list generator a way to fetch blocked patrons using...
[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 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 = 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     my $config = shift || die "Please specify a config file\n";
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