From 17055273a9805d3400c79615e6828378ce6a5584 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 27 Nov 2018 10:31:27 -0500 Subject: [PATCH] JBAS-2152 Backstage bib export from ID's file Adds an --id-file option to the Backstage bib export script. Useful for re-exporting problem records to Backstage. Signed-off-by: Bill Erickson --- KCLS/authority-control/backstage/export-bibs.pl | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/KCLS/authority-control/backstage/export-bibs.pl b/KCLS/authority-control/backstage/export-bibs.pl index 0799a9c856..b5d759a149 100755 --- a/KCLS/authority-control/backstage/export-bibs.pl +++ b/KCLS/authority-control/backstage/export-bibs.pl @@ -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 + 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 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 $_; $_ } ); + + close(ID_FILE); + + return "SELECT id FROM biblio.record_entry WHERE id IN ($ids)"; + } + my $sql = <