From 4423384b3b7f49abe06800733fb9cc6a1f4487be Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 17 Nov 2008 19:35:47 +0000 Subject: [PATCH] use server-side method for updating circs to LONGOVERDUE git-svn-id: svn://svn.open-ils.org/ILS/trunk@11247 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../support-scripts/long-overdue-status-update.pl | 99 ++++++++-------------- 1 file changed, 35 insertions(+), 64 deletions(-) diff --git a/Open-ILS/src/support-scripts/long-overdue-status-update.pl b/Open-ILS/src/support-scripts/long-overdue-status-update.pl index 19f86b52bc..b48c1ea953 100755 --- a/Open-ILS/src/support-scripts/long-overdue-status-update.pl +++ b/Open-ILS/src/support-scripts/long-overdue-status-update.pl @@ -1,74 +1,45 @@ #!/usr/bin/perl -use strict; -use warnings; - -use lib 'LIBDIR/perl5/'; +# --------------------------------------------------------------------- +# Long Overdue script with default period param. +# ./long-overdue-status-update.pl +# --------------------------------------------------------------------- +use strict; +use warnings; +use OpenSRF::Utils::JSON; use OpenSRF::System; -use OpenSRF::Application; -use OpenSRF::EX qw/:try/; -use OpenSRF::AppSession; -use OpenSRF::Utils::SettingsClient; -use OpenILS::Application::AppUtils; -use OpenILS::Utils::Fieldmapper; -use Digest::MD5 qw/md5_hex/; - -use Getopt::Long; - -my ($od_length, $user, $password, $config) = - ('180 days', 'admin', 'open-ils', 'SYSCONFDIR/opensrf_core.xml'); - -GetOptions( - 'overdue=s' => \$od_length, - 'user=s' => \$user, - 'password=s' => \$password, - 'config=s' => \$config, -); - -OpenSRF::System->bootstrap_client( config_file => $config ); -Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); - -my $auth = login($user,$password); -my $ses = OpenSRF::AppSession->create('open-ils.cstore'); -my $req = $ses->request( - 'open-ils.cstore', - 'open-ils.cstore.json_query', - { select => { circ => [ qw/id/ ] }, from => circ => where => { due_date => { ">" => { transform => "age", value => "340 days" } } } } -); - -while ( my $res = $req->recv( timeout => 120 ) ) { - print $res->content->target_copy . "\n"; +my $config = shift || die "bootstrap config required\n"; +my $lockfile = shift || "/tmp/long_overdue-LOCK"; +my $age = shift; + +$age = '180 days' if (!defined($age) or $age == 0); + +if (-e $lockfile) { + open(F,$lockfile); + my $pid = ; + close F; + + open(F,'/bin/ps axo pid|'); + while ( my $p = ) { + chomp($p); + if ($p =~ s/\s*(\d+)$/$1/o && $p == $pid) { + die "I seem to be running already at pid $pid. If not, try again\n"; + } + } + close F; } -sub login { - my( $username, $password, $type ) = @_; - - $type |= "staff"; - - my $seed = OpenILS::Application::AppUtils->simplereq( - 'open-ils.auth', - 'open-ils.auth.authenticate.init', - $username - ); - - die("No auth seed. Couldn't talk to the auth server") unless $seed; +open(F, ">$lockfile"); +print F $$; +close F; - my $response = OpenILS::Application::AppUtils->simplereq( - 'open-ils.auth', - 'open-ils.auth.authenticate.complete', - { username => $username, - password => md5_hex($seed . md5_hex($password)), - type => $type }); - - die("No auth response returned on login.") unless $response; - - my $authtime = $response->{payload}->{authtime}; - my $authtoken = $response->{payload}->{authtoken}; - - die("Login failed for user $username!") unless $authtoken; +OpenSRF::System->bootstrap_client( config_file => $config ); - return $authtoken; -} +my $r = OpenSRF::AppSession + ->create( 'open-ils.storage' ) + ->request( 'open-ils.storage.action.circulation.long_overdue' => $age ); +while (!$r->complete) { $r->recv }; +unlink $lockfile; -- 2.11.0