[open-ils-commits] r11251 - in branches/rel_1_4/Open-ILS/src: perlmods/OpenILS/Application/Storage/Publisher support-scripts
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Nov 18 10:18:19 EST 2008
Author: miker
Date: 2008-11-18 10:18:18 -0500 (Tue, 18 Nov 2008)
New Revision: 11251
Modified:
branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
branches/rel_1_4/Open-ILS/src/support-scripts/fine_generator.pl
branches/rel_1_4/Open-ILS/src/support-scripts/long-overdue-status-update.pl
Log:
backporting long-overdue from trunk
Modified: branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
===================================================================
--- branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm 2008-11-17 23:30:05 UTC (rev 11250)
+++ branches/rel_1_4/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm 2008-11-18 15:18:18 UTC (rev 11251)
@@ -164,11 +164,50 @@
__PACKAGE__->register_method(
api_name => 'open-ils.storage.action.circulation.reshelving.complete',
api_level => 1,
- stream => 1,
argc => 1,
method => 'complete_reshelving',
);
+sub mark_longoverdue {
+ my $self = shift;
+ my $client = shift;
+ my $window = shift;
+
+ local $OpenILS::Application::Storage::WRITE = 1;
+
+ throw OpenSRF::EX::InvalidArg ("I need an interval of more than 0 seconds!")
+ unless (interval_to_seconds( $window ));
+
+ my $setting = actor::org_unit_setting->table;
+ my $circ = action::circulation->table;
+
+ my $sql = <<" SQL";
+ UPDATE $circ
+ SET stop_fines = 'LONGOVERDUE',
+ stop_fines_time = now()
+ WHERE id IN (
+ SELECT id
+ FROM $circ circ
+ LEFT JOIN $setting setting
+ ON (circ.circ_lib = setting.org_unit AND setting.name = 'circ.long_overdue.interval')
+ WHERE circ.checkin_time IS NULL AND (stop_fines IS NULL OR stop_fines NOT IN ('LOST','LONGOVERDUE'))
+ AND AGE(circ.due_date) > CAST( COALESCE( BTRIM( FIRST(setting.value),'"' ), ? ) AS INTERVAL)
+ )
+ SQL
+
+ my $sth = action::circulation->db_Main->prepare_cached($sql);
+ $sth->execute($window);
+
+ return $sth->rows;
+
+}
+__PACKAGE__->register_method(
+ api_name => 'open-ils.storage.action.circulation.long_overdue',
+ api_level => 1,
+ argc => 1,
+ method => 'mark_longoverdue',
+);
+
sub auto_thaw_frozen_holds {
my $self = shift;
my $client = shift;
Modified: branches/rel_1_4/Open-ILS/src/support-scripts/fine_generator.pl
===================================================================
--- branches/rel_1_4/Open-ILS/src/support-scripts/fine_generator.pl 2008-11-17 23:30:05 UTC (rev 11250)
+++ branches/rel_1_4/Open-ILS/src/support-scripts/fine_generator.pl 2008-11-18 15:18:18 UTC (rev 11251)
@@ -1,8 +1,7 @@
#!/usr/bin/perl
# ---------------------------------------------------------------------
-# Generic databse object dumper.
-# ./object_dumper.pl <bootstrap_config> <type>, <type>, ...
-# ./object_dumper.pl /openils/conf/opensrf_core.xml permission.grp_tree
+# Fine generator with default grace period param.
+# ./object_dumper.pl <bootstrap_config> <lockfile> <grace (default 0)>
# ---------------------------------------------------------------------
use strict;
Modified: branches/rel_1_4/Open-ILS/src/support-scripts/long-overdue-status-update.pl
===================================================================
--- branches/rel_1_4/Open-ILS/src/support-scripts/long-overdue-status-update.pl 2008-11-17 23:30:05 UTC (rev 11250)
+++ branches/rel_1_4/Open-ILS/src/support-scripts/long-overdue-status-update.pl 2008-11-18 15:18:18 UTC (rev 11251)
@@ -1,74 +1,45 @@
#!/usr/bin/perl
-use strict;
-use warnings;
+# ---------------------------------------------------------------------
+# Long Overdue script with default period param.
+# ./long-overdue-status-update.pl <bootstrap_config> <lockfile> <age (default '180 days')>
+# ---------------------------------------------------------------------
-use lib 'LIBDIR/perl5/';
-
+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 $config = shift || die "bootstrap config required\n";
+my $lockfile = shift || "/tmp/long_overdue-LOCK";
+my $age = shift;
-my ($od_length, $user, $password, $config) =
- ('180 days', 'admin', 'open-ils', 'SYSCONFDIR/opensrf_core.xml');
+$age = '180 days' if (!defined($age) or $age == 0);
+
+if (-e $lockfile) {
+ open(F,$lockfile);
+ my $pid = <F>;
+ close F;
-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";
+ open(F,'/bin/ps axo pid|');
+ while ( my $p = <F>) {
+ 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 ) = @_;
+open(F, ">$lockfile");
+print F $$;
+close F;
- $type |= "staff";
+OpenSRF::System->bootstrap_client( config_file => $config );
- my $seed = OpenILS::Application::AppUtils->simplereq(
- 'open-ils.auth',
- 'open-ils.auth.authenticate.init',
- $username
- );
+my $r = OpenSRF::AppSession
+ ->create( 'open-ils.storage' )
+ ->request( 'open-ils.storage.action.circulation.long_overdue' => $age );
- die("No auth seed. Couldn't talk to the auth server") unless $seed;
+while (!$r->complete) { $r->recv };
- 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;
-
- return $authtoken;
-}
-
-
+unlink $lockfile;
More information about the open-ils-commits
mailing list