From 53c43811ee98cfe470ed8af4c3793628610e9dd5 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 1 Jun 2016 14:04:19 -0400 Subject: [PATCH] JBAS-1417 New authority linker --modified-since --modified-since implicitly includes --new-since because edit_date=create_date on new authority records. However, if both are specified, the script OR's the queries. If --modified-since and --new-since are used to gether, it creates an OR of the 2 clauses. Added a help() function. Added CRONTAB entry. Signed-off-by: Bill Erickson --- KCLS/linking/link-new-auth-records.pl | 67 ++++++++++++++++++++++++++++++++--- KCLS/utility-scripts/CRONTAB | 2 +- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/KCLS/linking/link-new-auth-records.pl b/KCLS/linking/link-new-auth-records.pl index 9a0f4a0f5c..fb8c1fabda 100755 --- a/KCLS/linking/link-new-auth-records.pl +++ b/KCLS/linking/link-new-auth-records.pl @@ -20,6 +20,7 @@ my $counter = 0; # options my $help; my $new_since; +my $modified_since; my $print_auth_ids; my $print_bib_ids; my $link_auths; @@ -32,6 +33,7 @@ my $db_pass = $ENV{PGPASSWORD}; my $opt_result = GetOptions( 'new-since=i' => \$new_since, + 'modified-since=i' => \$modified_since, 'print-bib-ids' => \$print_bib_ids, 'print-auth-ids' => \$print_auth_ids, 'link-bibs' => \$link_bibs, @@ -49,7 +51,56 @@ sub announce { print DateTime->now(time_zone => 'local')->strftime('%F %T')." $msg\n"; } -pod2usage(0) if !$opt_result || $help; +sub help { + print < + Process authority records created within the last days + If --modified-since is also applied, the union of both record + sets are processed (via OR query). + + --modified-since + Process authority records modified within the last days + If --new-since is also applied, the union of both record + sets are processed (via OR query). + + --print-auth-ids + Print authority record IDs to process to STDOUT + + --print-bib-ids + Print bib record IDs to process to STDOUT + + --link-auths + Run idenditifed authority records through authority_authority_linker.pl + + --link-bibs + Run idenditifed bib records through authority_control_fields.pl + + --progress + Log linking progess to STDOUT + + --db-host + --db-user + --db-pass + --db-port + + Database connection params. PG environment variables are + also inspected for values. When all else fails, try to + connect to database evergreen\@localhost +HELP + exit 0; +} + +help() if $help || !$opt_result; my $dsn = "dbi:Pg:database=evergreen;host=$db_host;port=$db_port"; my $dbh = DBI->connect($dsn, $db_user, $db_pass) @@ -59,13 +110,19 @@ $dbh->do('SET statement_timeout = 0'); # ---------------------------------------------------------------------- # Find the new authority record IDs +my $where = 'WHERE '; -my $sth = $dbh->prepare(<= DATE(NOW() - '$new_since day'::INTERVAL) -SQL +$where .= "DATE(create_date) >= DATE(NOW() - '$new_since day'::INTERVAL)" + if $new_since; +$where .= ' OR ' if $new_since && $modified_since; + +$where .= "DATE(edit_date) >= DATE(NOW() - '$modified_since day'::INTERVAL)" + if $modified_since; + +my $sth = $dbh->prepare("SELECT id FROM authority.record_entry $where"); $sth->execute; + while (my $ref = $sth->fetchrow_hashref()) { push(@auth_ids, $ref->{id}); } diff --git a/KCLS/utility-scripts/CRONTAB b/KCLS/utility-scripts/CRONTAB index af001e3cc2..5b4c936075 100644 --- a/KCLS/utility-scripts/CRONTAB +++ b/KCLS/utility-scripts/CRONTAB @@ -105,7 +105,7 @@ PGHOST = localhost # 30 23 * * 0 . ~/.bashrc && cd /openils/var/web && /openils/bin/sitemap_generator --lib-hostname evgtesting.kcls.org --lib-shortname KCLS --prefix standalone/sitemaps/ # Link newly created authority records -# 0 2 * * * . ~/.bashrc && cd /home/opensrf/Evergreen/KCLS/linking && ./link-new-auth-records.pl --new-since 1 --link-auths --link-bibs --progress +# 0 2 * * * . ~/.bashrc && cd /home/opensrf/Evergreen/KCLS/linking && ./link-new-auth-records.pl --modified-since 1 --link-auths --link-bibs --progress # # (Re-)Link newly created or modified bib records # 0 3 * * * . ~/.bashrc && cd /home/opensrf/Evergreen/KCLS/linking && ./authority_control_fields.pl --refresh --modified-since 1 -- 2.11.0