# options
my $help;
my $new_since;
+my $modified_since;
my $print_auth_ids;
my $print_bib_ids;
my $link_auths;
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,
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)
# ----------------------------------------------------------------------
# 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});
}