JBAS-2152 Backstage bib export from ID's file
authorBill Erickson <berickxx@gmail.com>
Tue, 27 Nov 2018 15:31:27 +0000 (10:31 -0500)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Adds an --id-file option to the Backstage bib export script.  Useful for
re-exporting problem records to Backstage.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/authority-control/backstage/export-bibs.pl

index 0799a9c..b5d759a 100755 (executable)
@@ -25,6 +25,7 @@ my $KU = 'OpenILS::Utils::KCLSScriptUtil';
 my $start_date;
 my $end_date;
 my $ids_only;
+my $id_file;
 my $count_only;
 my $out_file;
 my $help;
@@ -35,6 +36,7 @@ GetOptions(
     'ids-only'      => \$ids_only,
     'count-only'    => \$count_only,
     'out-file=s'    => \$out_file,
+    'id-file=s'    => \$id_file,
     'help'          => \$help
 ) || help();
 
@@ -64,23 +66,43 @@ Options
     --count-only
         Only print the number of bibs that would be exported to STDOUT.
 
+    --id-file </path/to/file>
+        Export bibs based on IDs found in this file.  This bypasses the
+        normal date-filtered query.  IDs listed one per line.
+
 HELP
     exit;
 }
 
 help() if $help;
 
-$KU->announce('ERR', "--start-date and --end-date required", 1)
-    unless $start_date && $end_date;
+if (!$id_file) {
+
+    $KU->announce('ERR', "--start-date and --end-date required", 1)
+        unless $start_date && $end_date;
 
-$KU->announce('ERR', "Invalid date format", 1) unless
-    $start_date =~ /^\d{4}-\d{2}-\d{2}$/ &&
-    $end_date =~ /^\d{4}-\d{2}-\d{2}$/;
+    $KU->announce('ERR', "Invalid date format", 1) unless
+        $start_date =~ /^\d{4}-\d{2}-\d{2}$/ &&
+        $end_date =~ /^\d{4}-\d{2}-\d{2}$/;
+}
 
 $KU->announce('ERR', "--out-file <filename> required", 1)
     unless $out_file || $count_only;
 
+# Returns a SQL query which returns a set of bib record IDs
 sub bib_query {
+
+    if ($id_file) {
+        open(ID_FILE, $id_file) 
+            or die "Cannot open --id-file '$id_file': $!\n";
+
+        my $ids = join(',', map { chomp $_; $_ } <ID_FILE>);
+
+        close(ID_FILE);
+
+        return "SELECT id FROM biblio.record_entry WHERE id IN ($ids)";
+    }
+
     my $sql = <<SQL;
 
 -- viable_records include filters applied to all records.