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

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jul 16 16:37:14 EDT 2009


Author: dbs
Date: 2009-07-16 16:37:10 -0400 (Thu, 16 Jul 2009)
New Revision: 585

Added:
   conifer/trunk/tools/delete_ill_books.pl
Log:
We circulate ILL books temporarily as part of the Conifer system by attaching their call number
and barcode to a set of generic bib records. 

Over time, the mass of call numbers attached to those bib records gets too big to retrieve in
the staff client holdings maintenance dialogue.

This script prunes the call numbers that have successfully circulated and for which no
outstanding fines remain.


Added: conifer/trunk/tools/delete_ill_books.pl
===================================================================
--- conifer/trunk/tools/delete_ill_books.pl	                        (rev 0)
+++ conifer/trunk/tools/delete_ill_books.pl	2009-07-16 20:37:10 UTC (rev 585)
@@ -0,0 +1,97 @@
+#!/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'
+                        )
+			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'
+                        )
+			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