]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/long-overdue-status-update.pl
Use a locally hosted yaz package to avoid strange firewalls
[Evergreen.git] / Open-ILS / src / support-scripts / long-overdue-status-update.pl
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use lib 'LIBDIR/perl5/';
6
7 use OpenSRF::System;
8 use OpenSRF::Application;
9 use OpenSRF::EX qw/:try/;
10 use OpenSRF::AppSession;
11 use OpenSRF::Utils::SettingsClient;
12 use OpenILS::Application::AppUtils;
13 use OpenILS::Utils::Fieldmapper;
14 use Digest::MD5 qw/md5_hex/;
15
16 use Getopt::Long;
17
18 my ($od_length, $user, $password, $config) =
19         ('180 days', 'admin', 'open-ils', 'SYSCONFDIR/opensrf_core.xml');
20
21 GetOptions(
22         'overdue=s'     => \$od_length,
23         'user=s'        => \$user,
24         'password=s'    => \$password,
25         'config=s'      => \$config,
26 );
27
28 OpenSRF::System->bootstrap_client( config_file => $config );
29 Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
30
31 my $auth = login($user,$password);
32
33 my $ses = OpenSRF::AppSession->create('open-ils.cstore');
34 my $req = $ses->request(
35         'open-ils.cstore',
36         'open-ils.cstore.json_query',
37         { select => { circ =>  [ qw/id/ ] }, from => circ => where => { due_date => { ">" => { transform => "age", value => "340 days" } } } }
38 );
39
40 while ( my $res = $req->recv( timeout => 120 ) ) {
41         print $res->content->target_copy . "\n";
42 }
43
44 sub login {        
45         my( $username, $password, $type ) = @_;
46
47         $type |= "staff"; 
48
49         my $seed = OpenILS::Application::AppUtils->simplereq(
50                 'open-ils.auth',
51                 'open-ils.auth.authenticate.init',
52                 $username
53         );
54
55         die("No auth seed. Couldn't talk to the auth server") unless $seed;
56
57         my $response = OpenILS::Application::AppUtils->simplereq(
58                 'open-ils.auth',
59                 'open-ils.auth.authenticate.complete',
60                 {       username => $username,
61                         password => md5_hex($seed . md5_hex($password)),
62                         type => $type });
63
64         die("No auth response returned on login.") unless $response;
65
66         my $authtime = $response->{payload}->{authtime};
67         my $authtoken = $response->{payload}->{authtoken};
68
69         die("Login failed for user $username!") unless $authtoken;
70
71         return $authtoken;
72 }       
73
74