From 8549426cdaa8070ecc384287f2843cae1b909237 Mon Sep 17 00:00:00 2001 From: dbs Date: Fri, 1 Oct 2010 05:24:38 +0000 Subject: [PATCH] Teach marc_export script how to export MFHD serial records Passing the --mfhd flag will export any non-deleted MFHD records in serial.record_entry associated with each bib ID. So, for a hypothetical set of bib IDs 1, 2, 3, where 2 has no associated MFHD records and 3 has 2 MFHD records associated with it, the output will be structured as follows: Bib MARC for bib ID 1 MFHD MARC for bib ID 1 Bib MARC for bib ID 2 Bib MARC for bib ID 3 MFHD MARC for bib ID 3 MFHD MARC for bib ID 2 git-svn-id: svn://svn.open-ils.org/ILS/trunk@18113 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/support-scripts/marc_export | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/support-scripts/marc_export b/Open-ILS/src/support-scripts/marc_export index 3740e7fc34..f5164bab7b 100755 --- a/Open-ILS/src/support-scripts/marc_export +++ b/Open-ILS/src/support-scripts/marc_export @@ -10,6 +10,7 @@ use OpenSRF::Utils::JSON; use OpenSRF::Utils::SettingsClient; use OpenILS::Application::AppUtils; use OpenILS::Utils::Fieldmapper; +use OpenILS::Utils::CStoreEditor; use MARC::Record; use MARC::File::XML; @@ -21,11 +22,12 @@ use Getopt::Long; my @formats = qw/USMARC UNIMARC XML BRE/; -my ($config,$format,$encoding,$location,$dollarsign,$idl,$help,$holdings,$timeout) = ('/openils/conf/opensrf_core.xml','USMARC','MARC8','','$',0,undef,undef,0); +my ($config,$format,$encoding,$location,$dollarsign,$idl,$help,$holdings,$timeout,$export_mfhd) = ('/openils/conf/opensrf_core.xml','USMARC','MARC8','','$',0,undef,undef,0,undef); GetOptions( 'help' => \$help, 'items' => \$holdings, + 'mfhd' => \$export_mfhd, 'location=s' => \$location, 'money=s' => \$dollarsign, 'config=s' => \$config, @@ -40,9 +42,11 @@ print <<"HELP"; Usage: $0 [options] --help or -h This screen. --config or -c Configuration file [/openils/conf/opensrf_core.xml] - --format or -f Output format (USMARC, UNIMARC, XML) [USMARC] + --format or -f Output format (USMARC, UNIMARC, XML, BRE) [USMARC] --encoding or -e Output Encoding (UTF-8, ISO-8859-?, MARC8) [MARC8] --items or -i Include items (holdings) in the output + --mfhd Export serial MFHD records for associated bib records + Not compatible with --format=BRE --xml-idl or -x Location of the IDL XML --location or -l MARC Location Code for holdings from http://www.loc.gov/marc/organizations/orgshome.html @@ -91,6 +95,8 @@ if (!$idl) { Fieldmapper->import(IDL => $idl); my $ses = OpenSRF::AppSession->create('open-ils.cstore'); +OpenILS::Utils::CStoreEditor::init(); +my $editor = OpenILS::Utils::CStoreEditor->new(); print <
@@ -222,6 +228,29 @@ while ( my $i = <> ) { import MARC::File::XML; # reset SAX parser so that one bad record doesn't kill the entire export }; + if ($export_mfhd) { + my $mfhds = $editor->search_serial_record_entry({record => $i, deleted => 'f'}); + foreach my $mfhd (@$mfhds) { + try { + my $r = MARC::Record->new_from_xml( $mfhd->marc, $encoding, $format ); + + if (uc($format) eq 'XML') { + my $xml = $r->as_xml_record; + $xml =~ s/^<\?.+?\?>$//mo; + print $xml; + } elsif (uc($format) eq 'UNIMARC') { + print $r->as_usmarc; + } elsif (uc($format) eq 'USMARC') { + print $r->as_usmarc; + } + } otherwise { + my $e = shift; + warn "\n$e\n"; + import MARC::File::XML; # reset SAX parser so that one bad record doesn't kill the entire export + }; + } + } + stats() if (! ($count{bib} % 50 )); } -- 2.11.0