[open-ils-commits] r552 - conifer/trunk/tools (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jun 30 16:14:23 EDT 2009


Author: dbs
Date: 2009-06-30 16:14:19 -0400 (Tue, 30 Jun 2009)
New Revision: 552

Added:
   conifer/trunk/tools/end_of_the_day.pl
Log:
For a select set of circulating items, set the due time to 23:59:59 instead of Evergreen's current limitation of now + some interval.

In this case, we are setting the due time of 2-day loaner laptops for OSUL to the end of the day on which they are due.


Added: conifer/trunk/tools/end_of_the_day.pl
===================================================================
--- conifer/trunk/tools/end_of_the_day.pl	                        (rev 0)
+++ conifer/trunk/tools/end_of_the_day.pl	2009-06-30 20:14:19 UTC (rev 552)
@@ -0,0 +1,70 @@
+#!/usr/bin/perl -w
+
+use DBI;
+use Getopt::Long;
+use OpenSRF::EX qw/:try/;
+use OpenSRF::Utils qw/:daemon/;
+use OpenSRF::System;
+use OpenSRF::AppSession;
+use OpenSRF::Utils::SettingsClient;
+use File::Find;
+
+my ($config, $set_due_time) = ('/openils/conf/opensrf_core.xml', 0);
+
+GetOptions(
+	"bootstrap=s"	=> \$config,
+	"set_due_time"	=> \$set_due_time,
+);
+
+OpenSRF::System->bootstrap_client( config_file => $config );
+
+my $sc = OpenSRF::Utils::SettingsClient->new;
+my $db_driver = $sc->config_value( apps => 'open-ils.storage' => app_settings => databases => 'driver' );
+my $db_host = $sc->config_value( apps => 'open-ils.storage' => app_settings => databases => database => 'host' );
+my $db_port = $sc->config_value( apps => 'open-ils.storage' => app_settings => databases => database => 'port' );
+my $db_name = $sc->config_value( apps => 'open-ils.storage' => app_settings => databases => database => 'db' );
+my $db_user = $sc->config_value( apps => 'open-ils.storage' => app_settings => databases => database => 'user' );
+my $db_pw = $sc->config_value( apps => 'open-ils.storage' => app_settings => databases => database => 'pw' );
+
+my $dsn = "dbi:" . $db_driver . ":dbname=" . $db_name .';host=' . $db_host . ';port=' . $db_port;
+
+my $dbh = DBI->connect($dsn,$db_user,$db_pw, {pg_enable_utf8 => 1, RaiseError => 1});
+
+end_of_day($set_due_time);
+
+$dbh->disconnect;
+
+sub end_of_day {
+	my $set_due_time = shift;
+
+	my $select_stmt = <<STMT;
+		SELECT id
+		FROM action.circulation
+		WHERE checkin_time IS NULL
+		AND due_date::TIME WITH TIME ZONE != '23:59:59-04'
+                AND duration_rule = '48_hours_2_renew'
+		AND circ_lib = 103
+STMT
+
+	my $update_stmt = <<UPDATE;
+		UPDATE action.circulation
+		SET due_date = CAST(due_date::DATE || ' ' || '23:59:59-04' AS TIMESTAMP WITH TIME ZONE) 
+		WHERE checkin_time IS NULL
+		AND due_date::TIME WITH TIME ZONE != '23:59:59-04'
+		AND duration_rule = '48_hours_2_renew'
+		AND circ_lib = 103
+UPDATE
+
+
+	my @results = $dbh->selectrow_array($select_stmt);
+	print localtime() . " - found " . scalar(@results) . " circulation transactions to update:\n";
+	foreach (@results) {
+		print "\t$_\n";
+	}
+	if ($set_due_time) {
+		my $stmt = $dbh->prepare($update_stmt);
+		my $updates = $stmt->execute();
+		print "Updated $updates circulation transactions.\n";
+	}
+}
+



More information about the open-ils-commits mailing list