We run this daily to avoid a build-up of ephemeral ILL books
authordbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 5 Mar 2010 20:34:10 +0000 (20:34 +0000)
committerdbs <dbs@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 5 Mar 2010 20:34:10 +0000 (20:34 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/branches/rel_1_6_0@824 6d9bc8c9-1ec2-4278-b937-99fde70a366f

tools/daily-scripts/delete_ill_books.pl [new file with mode: 0644]

diff --git a/tools/daily-scripts/delete_ill_books.pl b/tools/daily-scripts/delete_ill_books.pl
new file mode 100644 (file)
index 0000000..f230433
--- /dev/null
@@ -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();
+       }
+}
+