use OpenSRF::Utils::SettingsClient;
use OpenILS::Application::AppUtils;
use OpenILS::Utils::Fieldmapper;
+use OpenILS::Utils::CStoreEditor;
use MARC::Record;
use MARC::File::XML;
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,
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
Fieldmapper->import(IDL => $idl);
my $ses = OpenSRF::AppSession->create('open-ils.cstore');
+OpenILS::Utils::CStoreEditor::init();
+my $editor = OpenILS::Utils::CStoreEditor->new();
print <<HEADER if ($format eq 'XML');
<?xml version="1.0" encoding="$encoding"?>
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 ));
}