--- /dev/null
+-- Ensure that we have a stat cat entry for language preference for OSUL users
+-- NOTE: We should cut over to usr_settings at some point
+INSERT INTO actor.stat_cat_entry_usr_map (stat_cat_entry, stat_cat, target_usr)
+ SELECT 'English', 2, au.id
+ FROM actor.usr au
+ WHERE au.id NOT IN (
+ SELECT target_usr
+ FROM actor.stat_cat_entry_usr_map
+ ) AND home_ou = 103
+;
--- /dev/null
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+# Evergreen sets due dates that are past the user's expiry date
+
+# Let's fix that after the fact, for now, by setting the due dates to the user's expiry date
+
+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;
+
+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 aoc.due_date, au.expire_date
+ FROM action.open_circulation aoc
+ INNER JOIN actor.usr au ON au.id = aoc.usr
+ WHERE aoc.due_date > au.expire_date
+ AND au.expire_date > NOW()
+ AND au.expire_date < NOW() + '2 years'::interval
+ AND au.home_ou IN (103, 110, 126)
+ ORDER BY au.expire_date
+STMT
+
+ my $update_stmt = <<UPDATE;
+ UPDATE action.circulation ac SET due_date = au.expire_date
+ FROM actor.usr au
+ WHERE au.id = ac.usr
+ AND ac.due_date > au.expire_date
+ AND au.expire_date > NOW()
+ AND au.expire_date < NOW() + '2 years'::interval
+ AND au.home_ou IN (103, 110, 126)
+ AND ac.checkin_time IS NULL
+UPDATE
+
+
+ my $results = $dbh->selectall_arrayref($select_stmt);
+ print localtime() . " - found " . scalar(@$results) . " circulation transactions to update where due_date > expire_date\n";
+ if ($set_due_time) {
+ my $stmt = $dbh->prepare($update_stmt);
+ my $updates = $stmt->execute();
+ print "Updated $updates circulation transactions.\n";
+ }
+}
+
--- /dev/null
+#!/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();
+ }
+}
+
--- /dev/null
+#!/usr/bin/perl -w
+
+# Sets the due time of items with a given loan period for a given library to 23:59:59
+
+# This is a temporary workaround for Evergreen's assumption that the
+# fine generating script will only run once a day, to avoid dinging a patron
+# with an overdue charge at 48 hours + 5 minutes rather than at the end of the
+# day that 48 hours falls on.
+
+# We also found that editing the due date for a given item sets the corresponding
+# due time to 00:00 - which isn't great, as that means that it is due the minute
+# the day starts. So, for now, we'll set all daily / weekly loans or those loans
+# that are due exactly at midnight to being due at 23:59:59 - the very last second
+# of the day on which it is due. This probably meets our patrons' expectations a bit
+# better.
+
+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;
+
+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 != '23:59:59'
+ AND duration_rule LIKE ('%days%')
+ OR duration_rule LIKE ('%weeks%')
+ OR duration_rule = '48_hours_2_renew'
+ ) OR (
+ due_date::TIME = '00:00:00'
+ )
+ ) AND circ_lib IN (
+ SELECT id
+ FROM actor.org_unit
+ WHERE parent_ou = 105
+ )
+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 != '23:59:59'
+ AND duration_rule LIKE ('%days%')
+ OR duration_rule LIKE ('%weeks%')
+ OR duration_rule = '48_hours_2_renew'
+ ) OR (
+ due_date::TIME = '00:00:00'
+ )
+ ) AND circ_lib IN (
+ SELECT id
+ FROM actor.org_unit
+ WHERE parent_ou = 105
+ )
+UPDATE
+
+
+ my $results = $dbh->selectcol_arrayref($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";
+ }
+}
--- /dev/null
+#!/usr/bin/perl -w
+use strict;
+use warnings;
+
+# Reingest biblio.record_entry records that didn't get ingested due to the simple_rec_sync bug
+# Ingested records are expected to have an entry in the keyword index
+# Might want to build a variation on this that reingests edited records on a nightly basis
+
+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;
+
+my ($config, $reingest) = ('/openils/conf/opensrf_core.xml', 0);
+
+GetOptions(
+ "bootstrap=s" => \$config,
+ "reingest" => \$reingest,
+);
+
+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});
+
+reingest_empty_records($reingest);
+
+$dbh->disconnect;
+
+sub reingest_empty_records {
+ my $select_stmt = <<STMT;
+ SELECT bre.id
+ FROM biblio.record_entry bre
+ WHERE deleted IS FALSE
+ AND bre.id > 0
+ EXCEPT
+ SELECT mrd.source
+ FROM metabib.keyword_field_entry mrd
+STMT
+
+ my $results = $dbh->selectcol_arrayref($select_stmt);
+ print localtime() . " - found " . scalar(@$results) . " records to reingest\n";
+ foreach (@$results) {
+ print "\t$_\n";
+ }
+ if ($reingest) {
+
+ foreach (@$results) {
+ my $r = OpenSRF::AppSession
+ ->create( 'open-ils.ingest' )
+ ->request( 'open-ils.ingest.full.biblio.record' => $_ );
+
+ while (!$r->complete) { $r->recv };
+
+ # Sleep for 10 seconds between each request to prevent blocking
+ sleep(10);
+ }
+ }
+}
+
--- /dev/null
+#/usr/bin/perl
+use strict;
+use OpenSRF::AppSession;
+use OpenSRF::System;
+
+OpenSRF::System->bootstrap_client(config_file => '/openils/conf/opensrf_core.xml');
+
+my @services = qw{
+ opensrf.settings
+ opensrf.math
+ opensrf.dbmath
+ open-ils.acq
+ open-ils.cat
+ open-ils.supercat
+ open-ils.search
+ open-ils.circ
+ open-ils.actor
+ open-ils.auth
+ open-ils.storage
+ open-ils.penalty
+ open-ils.cstore
+ open-ils.collections
+ open-ils.ingest
+ open-ils.reporter
+ open-ils.reporter-store
+ open-ils.permacrud
+ open-ils.pcrud
+ open-ils.trigger
+ open-ils.fielder
+ open-ils.vandelay
+ open-ils.resolver
+};
+
+foreach my $service (@services) {
+ check_service($service);
+}
+
+sub check_service {
+ my $service = shift;
+ my $session = OpenSRF::AppSession->create($service);
+ my $request = $session->request("opensrf.system.echo", "All is well");
+ if ($request && $request->gather() eq "All is well") {
+ print "$service: All is well\n";
+ } else {
+ print "$service: FAIL\n";
+ }
+}
+
--- /dev/null
+-- Cheap way of making titles and the like that contain "&"
+-- return results for well-meaning queries that use "and"
+BEGIN;
+UPDATE metabib.author_field_entry
+ SET value = value || ' and'
+ WHERE value LIKE '%&%' AND value NOT LIKE '% and %';
+UPDATE metabib.keyword_field_entry
+ SET value = value || ' and'
+ WHERE value LIKE '%&%' AND value NOT LIKE '% and %';
+UPDATE metabib.subject_field_entry
+ SET value = value || ' and'
+ WHERE value LIKE '%&%' AND value NOT LIKE '% and %';
+UPDATE metabib.title_field_entry
+ SET value = value || ' and'
+ WHERE value LIKE '%&%' AND value NOT LIKE '% and %';
+COMMIT;