From: Bill Erickson Date: Mon, 22 Aug 2016 17:52:04 +0000 (-0400) Subject: JBAS-1437 link-new-auths new options, ID printing X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=10fd3d86997f4249d8914e255c4fae4754886f2b;p=working%2FEvergreen.git JBAS-1437 link-new-auths new options, ID printing --start-auth-id --max-auth-count Also, print-x-ids now prints IDs one per line without any logging header. Signed-off-by: Bill Erickson --- diff --git a/KCLS/linking/link-new-auth-records.pl b/KCLS/linking/link-new-auth-records.pl index fb8c1fabda..c48939e30a 100755 --- a/KCLS/linking/link-new-auth-records.pl +++ b/KCLS/linking/link-new-auth-records.pl @@ -19,8 +19,9 @@ my $counter = 0; # options my $help; -my $new_since; my $modified_since; +my $max_auth_count; +my $start_auth_id; my $print_auth_ids; my $print_bib_ids; my $link_auths; @@ -32,8 +33,9 @@ my $db_user = $ENV{PGDATABASE} || 'evergreen'; my $db_pass = $ENV{PGPASSWORD}; my $opt_result = GetOptions( - 'new-since=i' => \$new_since, 'modified-since=i' => \$modified_since, + 'max-auth-count=i' => \$max_auth_count, + 'start-auth-id=i' => \$start_auth_id, 'print-bib-ids' => \$print_bib_ids, 'print-auth-ids' => \$print_auth_ids, 'link-bibs' => \$link_bibs, @@ -62,16 +64,20 @@ sub help { $0 --modified-since 1 --link-auths --link-bibs Options: - - --new-since - 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). + Process authority records created or modified within the + last days. + + --max-auth-count + Process authority records in total. Use with + --start-auth-id to process batches of records across + multiple instances of the script. + + --start-auth-id + Process authority records whose ID is equal to or greater + than . Use with --max-auth-count to process batches + of records accross multiple runs of the script. --print-auth-ids Print authority record IDs to process to STDOUT @@ -109,18 +115,18 @@ my $dbh = DBI->connect($dsn, $db_user, $db_pass) $dbh->do('SET statement_timeout = 0'); # ---------------------------------------------------------------------- -# Find the new authority record IDs -my $where = 'WHERE '; - -$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; +# Load the authority record IDs +my $where2 = $start_auth_id ? "AND id >= $start_auth_id" : ''; +my $limit = $max_auth_count ? "LIMIT $max_auth_count" : ''; + +my $sth = $dbh->prepare(<= DATE(NOW() - '$modified_since day'::INTERVAL) + $where2 + ORDER BY id + $limit +SQL -my $sth = $dbh->prepare("SELECT id FROM authority.record_entry $where"); $sth->execute; while (my $ref = $sth->fetchrow_hashref()) { @@ -129,10 +135,14 @@ while (my $ref = $sth->fetchrow_hashref()) { $sth->finish; my $auth_rec_count = scalar(@auth_ids); -announce("Auth IDs: @auth_ids") if $print_auth_ids; +print join("\n", @auth_ids) if $print_auth_ids; + +# Let the caller know what the last record processed will be, +# so the next iteration of the script can start there. +announce("Final auth ID will be: " . $auth_ids[-1]) if $max_auth_count; if (!@auth_ids) { - announce("No authority records created in the last $new_since days"); + announce("No authority records edited in the last $modified_since days"); exit 0; } @@ -142,6 +152,7 @@ if (!@auth_ids) { if ($link_auths) { # Pass all new authority records to the auth-to-auth linker for my $rec_id (@auth_ids) { + system( './authority_authority_linker.pl', '--db-host', $db_host, @@ -238,5 +249,5 @@ if ($link_bibs) { } } -announce("Bib IDs: @bib_ids") if $print_bib_ids; +print join("\n", @bib_ids) if $print_bib_ids;