From 6b7381979d6bb2d7636325078f57705d06700c09 Mon Sep 17 00:00:00 2001 From: Steven Callender Date: Thu, 19 Apr 2012 09:47:46 -0400 Subject: [PATCH] Added a days_back parameter to authority_control_fields.pl in order to process bibs edited X amount of days ago. The days_back parameter can be used to easily run the script through cron nightly and have it process all newly created or newly added bib records. Ideally it would be ran once a day at nighttime prior to midnight using the --days_back 0 option. Signed-off-by: Steven Callender Signed-off-by: Lebbeous Fogle-Weekley --- .../authority_control_fields.pl.in | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Open-ILS/src/support-scripts/authority_control_fields.pl.in b/Open-ILS/src/support-scripts/authority_control_fields.pl.in index 60c9d17c73..83f7db2bb3 100755 --- a/Open-ILS/src/support-scripts/authority_control_fields.pl.in +++ b/Open-ILS/src/support-scripts/authority_control_fields.pl.in @@ -33,6 +33,7 @@ use Pod::Usage qw/ pod2usage /; MARC::Charset->assume_unicode(1); my ($start_id, $end_id); +my ($days_back); my $bootstrap = '@sysconfdir@/opensrf_core.xml'; my @records; @@ -44,12 +45,18 @@ my $result = GetOptions( 'all', 'help', 'start_id=i' => \$start_id, 'end_id=i' => \$end_id, + 'days_back=i' => \$days_back, ); if (!$result or $options{help}) { pod2usage(0); } +if ($start_id && $days_back) { + print "Can't use both start ID and days back!\n"; + exit; +} + OpenSRF::System->bootstrap_client(config_file => $bootstrap); Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); @@ -72,6 +79,39 @@ if ($options{all}) { if ($start_id and $end_id) { @records = ($start_id .. $end_id); } + +if (defined $days_back) { +@records=(); + +# Grab DB information from local settings +my $sc = OpenSRF::Utils::SettingsClient->new; +my $db_driver = $sc->config_value( reporter => setup => database => 'driver' ); +my $db_host = $sc->config_value( reporter => setup => database => 'host' ); +my $db_port = $sc->config_value( reporter => setup => database => 'port' ); +my $db_name = $sc->config_value( reporter => setup => database => 'db' ); +if (!$db_name) { + $db_name = $sc->config_value( reporter => setup => database => 'name' ); + print STDERR "WARN: is a deprecated setting for database name. For future compatibility, you should use instead." if $db_name; +} +my $db_user = $sc->config_value( reporter => setup => database => 'user' ); +my $db_pw = $sc->config_value( reporter => setup => database => 'pw' ); + +die "Unable to retrieve database connection information from the settings server" unless ($db_driver && $db_host && $db_port && $db_name && $db_user); + +my $dsn = "dbi:" . $db_driver . ":dbname=" . $db_name .';host=' . $db_host . ';port=' . $db_port; +my $dbh = DBI->connect($dsn,$db_user,$db_pw, {AutoCommit => 1, pg_enable_utf8 => 1, RaiseError => 1}) or die "database connection error"; + +# SQL Used to gather a list of ID's +my $idstatement = $dbh->prepare("SELECT DISTINCT(id) AS id FROM biblio.record_entry where (date(create_date) = date(now()) or date(edit_date) = date((NOW() - '$days_back day'::interval)))"); + +# Load the list of ID's into the records array +$idstatement->execute(); + while (my $ref = $idstatement->fetchrow_hashref()) { + my $id_ref = $ref->{"id"}; # the column name in our sql query is "id" + push(@records, $id_ref); + } +} + # print Dumper($undeleted, \@records); # Hash of controlled fields & subfields in bibliographic records, and their -- 2.43.2