JBAS-1417 New authority linker --modified-since
authorBill Erickson <berickxx@gmail.com>
Wed, 1 Jun 2016 18:04:19 +0000 (14:04 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
--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 <berickxx@gmail.com>
KCLS/linking/link-new-auth-records.pl
KCLS/utility-scripts/CRONTAB

index 9a0f4a0..fb8c1fa 100755 (executable)
@@ -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 <<HELP;
+
+        Update or create bib-to-auth and auth-to-auth links for authority
+        records that were created or modified within the last X days.
+        
+        Usage:
+        
+            $0 --modified-since 1 --link-auths --link-bibs
+        
+        Options:
+            
+            --new-since <days>
+                Process authority records created within the last <days> days
+                If --modified-since is also applied, the union of both record
+                sets are processed (via OR query).
+
+            --modified-since <days>
+                Process authority records modified within the last <days> 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(<<SQL);
-    SELECT id FROM authority.record_entry 
-    WHERE DATE(create_date) >= 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});
 }
index af001e3..5b4c936 100644 (file)
@@ -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