JBAS-1437 Auth-2-auth linker --file option
authorBill Erickson <berickxx@gmail.com>
Mon, 26 Sep 2016 14:18:42 +0000 (10:18 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Supports a --file option pointing to file of authority record IDs, one
ID per line.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/linking/authority_authority_linker.pl

index a7f3ffc..bf0f8ec 100755 (executable)
@@ -47,6 +47,7 @@ my ($start_id, $end_id);
 my $bootstrap = '/openils/conf/opensrf_core.xml';
 my @records;
 my $verbose;
+my $input_file ='';
 my $db_host = $ENV{PGHOST} || 'localhost';
 my $db_port = $ENV{PGPORT} || '5432';
 my $db_user = $ENV{PGDATABASE} || 'evergreen';
@@ -61,8 +62,9 @@ my $result = GetOptions(
     'record=i' => \@records,
     'all', 'help',
     'start_id=i' => \$start_id,
-    'end_id=i' => \$end_id,
-    'verbose' => \$verbose,
+    'end_id=i'  => \$end_id,
+    'file=s'    => \$input_file,
+    'verbose'   => \$verbose,
     "db-host=s" => \$db_host,
     "db-user=s" => \$db_user,
     "db-pass=s" => \$db_pass,
@@ -119,6 +121,24 @@ if (@records) {
 } elsif ($start_id and $end_id) {
     $query = sprintf($query, "WHERE sh2.record BETWEEN ? AND ?");
     @bind_params = ($start_id, $end_id);
+
+} elsif ($input_file) {
+    # Load authority record IDs from a file.
+    announce("Reading authority record IDs from $input_file");
+
+    open FILE, "<", $input_file or die "Can't open file $input_file\n";
+    while(<FILE>) {
+        chomp;
+        push(@records, $_) if $_;
+    }
+    close FILE;
+
+    announce("Read ".scalar(@records)." from $input_file");
+
+    # No bind_params needed.
+    my $recstr = join(',', @records);
+    $query = sprintf($query, "WHERE sh2.record IN ($recstr)");
+
 } else {
     pod2usage(0);
 }