From 61fc1ecb23681a7ea7c50e5ba7984ee0f67376e3 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Fri, 19 Dec 2014 16:29:04 -0500 Subject: [PATCH] Option to exclude specific records by id --exclude-record-id-file= Signed-off-by: Jason Etheridge --- Open-ILS/src/support-scripts/marc_export.in | 52 ++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/Open-ILS/src/support-scripts/marc_export.in b/Open-ILS/src/support-scripts/marc_export.in index cb09985eff..b8bd45fa13 100755 --- a/Open-ILS/src/support-scripts/marc_export.in +++ b/Open-ILS/src/support-scripts/marc_export.in @@ -86,6 +86,7 @@ sub new { 'exclude-item-id-file=s', 'exclude-item-barcode-file=s', 'exclude-item-circmod-file=s', + 'exclude-record-id-file=s', 'mfhd', 'all', 'replace_001', @@ -118,18 +119,19 @@ is retrieved. This may not be very efficient for databases with large gaps in their ID sequences. Usage: $0 [options] - --help or -h This screen. - --config or -c Configuration file [@sysconfdir@/opensrf_core.xml] - --format or -f Output format (USMARC, UNIMARC, XML, BRE, ARE) [USMARC] - --encoding or -e Output encoding (UTF-8, ISO-8859-?, MARC8) [MARC8] - --xml-idl or -x Location of the IDL XML - --timeout Remains for backward compatibility. No longer used. - --type or -t Record type (BIBLIO, AUTHORITY) [BIBLIO] - --all or -a Export all records; ignores input list - --replace_001 Replace the 001 field value with the record ID - --store Use the given storage backend to connect to the database. - Choices are (reporter, cstore, storage) [reporter] - --since Export records modified since a certain date and time. + --help or -h This screen. + --config or -c Configuration file [@sysconfdir@/opensrf_core.xml] + --format or -f Output format (USMARC, UNIMARC, XML, BRE, ARE) [USMARC] + --encoding or -e Output encoding (UTF-8, ISO-8859-?, MARC8) [MARC8] + --xml-idl or -x Location of the IDL XML + --timeout Remains for backward compatibility. No longer used. + --type or -t Record type (BIBLIO, AUTHORITY) [BIBLIO] + --all or -a Export all records; ignores input list + --replace_001 Replace the 001 field value with the record ID + --store Use the given storage backend to connect to the database. + Choices are (reporter, cstore, storage) [reporter] + --since Export records modified since a certain date and time. + --exclude-record-id-file Specify a file containing list of record ids to exclude Additional options for type = 'BIBLIO': --items or -i Include items (holdings) in the output @@ -203,6 +205,20 @@ HELP if ($opts{format} eq 'BRE' && $opts{items}) { die "Format BRE is not compatible with exporting holdings." } + $opts{'exclude-record-ids'} = {}; + if ($opts{'exclude-record-id-file'}) { + if (-e $opts{'exclude-record-id-file'}) { + open FILE, $opts{'exclude-record-id-file'}; + while (my $record_id = ) { + chomp $record_id; + $opts{'exclude-record-ids'}->{$record_id} = 1; + } + close FILE; + } else { + die "Could not find file for exclude-record-id-file: " . $opts{'exclude-record-id-file'}; + } + } + if ($opts{'exclude-itemless-bibs'} && ! $opts{items}) { die "If excluding itemless bibs, must export holdings."; } @@ -468,6 +484,10 @@ sub next { # until we run out. These sres "go with" the previous bib record. if ($Marque::config->option_value('mfhd') && $self->{mfhds} && @{$self->{mfhds}}) { $r = shift(@{$self->{mfhds}}); + if (defined $Marque::config->option_value('exclude-record-ids')->{ $r->id() }) { + import MARC::File::XML; # Reset SAX Parser. + return $self->next(); # skip this record + } eval { $marc = MARC::Record->new_from_xml($r->marc(), $Marque::config->option_value('encoding'), @@ -483,6 +503,10 @@ sub next { my $data = $self->{sth}->fetchrow_hashref; if ($data) { $r = $self->{breClass}->from_bare_hash($data); + if (defined $Marque::config->option_value('exclude-record-ids')->{ $r->id() }) { + import MARC::File::XML; # Reset SAX Parser. + return $self->next(); # skip this record + } if ($Marque::config->option_value('format') eq 'BRE') { $output = OpenSRF::Utils::JSON->perl2JSON($r); } else { @@ -784,6 +808,10 @@ sub next { if ($data) { my $format = $Marque::config->option_value('format'); my $are = $self->{fmClass}->from_bare_hash($data); + if (defined $Marque::config->option_value('exclude-record-ids')->{ $are->id() }) { + import MARC::File::XML; # Reset SAX Parser. + return $self->next(); # skip this record + } if ($format eq 'ARE') { $output = OpenSRF::Utils::JSON->perl2JSON($are); } else { -- 2.11.0