[open-ils-commits] r824 - conifer/branches/rel_1_6_0/tools/daily-scripts (dbs)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Mar 5 15:34:15 EST 2010
Author: dbs
Date: 2010-03-05 15:34:10 -0500 (Fri, 05 Mar 2010)
New Revision: 824
Added:
conifer/branches/rel_1_6_0/tools/daily-scripts/delete_ill_books.pl
Log:
We run this daily to avoid a build-up of ephemeral ILL books
Added: conifer/branches/rel_1_6_0/tools/daily-scripts/delete_ill_books.pl
===================================================================
--- conifer/branches/rel_1_6_0/tools/daily-scripts/delete_ill_books.pl (rev 0)
+++ conifer/branches/rel_1_6_0/tools/daily-scripts/delete_ill_books.pl 2010-03-05 20:34:10 UTC (rev 824)
@@ -0,0 +1,99 @@
+#!/usr/bin/perl -w
+use strict;
+
+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) = ('/openils/conf/opensrf_core.xml');
+
+GetOptions(
+ "bootstrap=s" => \$config,
+);
+
+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});
+
+delete_racer_callnumbers();
+
+$dbh->disconnect;
+
+sub delete_racer_callnumbers {
+ my $select_stmt = <<SELECT;
+ SELECT acn.id
+ FROM asset.call_number acn
+ INNER JOIN asset.copy ac ON ac.call_number = acn.id
+ INNER JOIN action.circulation acirc ON ac.id = acirc.target_copy
+ AND acn.record IN (
+ SELECT bre.id
+ FROM biblio.record_entry bre
+ WHERE bre.id IN (
+ 2237519,
+ 2239801,
+ 2239798,
+ 2239797,
+ 2239799,
+ 2239800,
+ 2247576
+ )
+ AND bre.deleted IS FALSE
+ ) AND acirc.checkin_time IS NOT NULL
+ AND acirc.id NOT IN (
+ SELECT id
+ FROM money.open_billable_xact_summary
+ ) AND acn.deleted IS FALSE
+
+SELECT
+
+ my $delete_stmt = <<DELETE;
+ DELETE FROM asset.call_number acn
+ USING asset.copy ac
+ INNER JOIN action.circulation acirc ON ac.id = acirc.target_copy
+ WHERE acn.id = ac.call_number
+ AND acn.record IN (
+ SELECT bre.id
+ FROM biblio.record_entry bre
+ WHERE bre.id IN (
+ 2237519,
+ 2239801,
+ 2239798,
+ 2239797,
+ 2239799,
+ 2239800,
+ 2247576
+ )
+ AND bre.deleted IS FALSE
+ ) AND acirc.checkin_time IS NOT NULL
+ AND acirc.id NOT IN (
+ SELECT id
+ FROM money.open_billable_xact_summary
+ ) AND acn.deleted IS FALSE
+DELETE
+
+ my $results = $dbh->selectcol_arrayref($select_stmt);
+ print localtime() . " - found " . scalar(@$results) . " RACER book call numbers to delete:\n";
+ if (scalar(@$results)) {
+ foreach (@$results) {
+ print "\t$_\n";
+ }
+ my $stmt = $dbh->prepare($delete_stmt);
+ my $updates = $stmt->execute();
+ }
+}
+
More information about the open-ils-commits
mailing list