MARC::Charset->ignore_errors(1);
-my ($idfield, $count, $user, $password, $config, $marctype, $idsubfield, @files, @trash_fields, $quiet) =
+my ($idfield, $count, $user, $password, $config, $marctype, $idsubfield, @files, @trash_fields, $quiet, $libmap) =
('001', 1, 'admin', 'open-ils', '/openils/conf/opensrf_core.xml', 'USMARC');
GetOptions(
'config=s' => \$config,
'marctype=s' => \$marctype,
'file=s' => \@files,
+ 'libmap=s' => \$libmap,
'quiet' => \$quiet,
);
my @ses;
my @req;
my %processing_cache;
+my $lib_id_map;
+if ($libmap) {
+ $lib_id_map = map_libraries_to_ID($libmap);
+}
OpenSRF::System->bootstrap_client( config_file => $config );
Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
$bib->edit_date('now');
$bib->last_xact_id('IMPORT-'.$starttime);
+ if ($libmap) {
+ my $lib_id = get_library_id($rec);
+ if ($lib_id) {
+ $bib->owning_lib($lib_id);
+ }
+ }
+
print OpenSRF::Utils::JSON->perl2JSON($bib)."\n";
$count++;
return $authtoken;
}
+=head2
+
+map_libraries_to_ID
+
+Parses a file to return a hash of library names to integers representing
+the actor.org_unit.id value of the library. This enables us to generate
+an ingest file that does not subsequently need to manually manipulated.
+
+The library name must correspond to the 'b' subfield of the 852 field.
+Well, it does not have to, but you will have to modify this script
+accordingly.
+
+The format of the map file should be the name of the library, followed
+by a tab, followed by the desired numeric ID of the library. For example:
+
+BR1 4
+BR2 5
+
+=cut
+
+sub map_libraries_to_ID {
+ my $map_filename = shift;
+
+ my %lib_id_map;
+
+ open(MAP_FH, '<', $map_filename) or die "Could not load [$map_filename] $!";
+ while (<MAP_FH>) {
+ my ($lib, $id) = $_ =~ /^(.*?)\t(.*?)$/;
+ $lib_id_map{$lib} = $id;
+ }
+
+ return \%lib_id_map;
+}
+
+sub get_library_id {
+ my $record = shift;
+
+ my $lib_name = $record->field('852')->subfield('b');
+ my $lib_id = $lib_id_map->{$lib_name};
+
+ return $lib_id;
+}
=====How to load the test MFHD records=====
- First load the MARC21 records:
- - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2bre.pl --marctype XML --start 1 --idfield 901 --idsubfield a serials_marc21.xml | perl ../../src/extras/import/direct_ingest.pl | perl ../../src/extras/import/pg_loader.pl -or bre -or mrd -or mfr -or mtfe -or mafe -or msfe -or mkfe -or msefe -a mrd -a mfr -a mtfe -a mafe -a msfe -a mkfe -a msefe | psql -U evergreen -h localhost
+ - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2bre.pl --marctype XML --start 1 --idfield 901 --idsubfield a serials_marc21.xml | perl ../../src/extras/import/pg_loader.pl -or bre -or mrd -or mfr -or mtfe -or mafe -or msfe -or mkfe -or msefe -a mrd -a mfr -a mtfe -a mafe -a msfe -a mkfe -a msefe | psql -U evergreen -h localhost
- Then generate the metarecord map:
- pgsql -f ../../src/extras/import/quick_metarecord_map.sql
- - Then process and load the MFHD records - ingest is not used:
- - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2sre.pl --marctype XML --password open-ils serials_mfhd.xml | perl ../../src/extras/import/pg_loader.pl -or sre > mfhd21.sql
- - Open the file in a text editor and change the final "\N" on each line
- to the numeric ID of the org_unit that owns the MFHD record. Yes, this
- is a gross hack that effectively limits you to loading MFHD records in
- per-org_unit batches; enhancements to marc2sre.pl are welcomed.
+ - Then process and load the MFHD records - ingest is not used. Adjust the
+ contents of serials_lib.map to match your library-to-actor.org_unit.id
+ mappings:
+ - PERL5LIB=/openils/lib/perl5/ perl ../../src/extras/import/marc2sre.pl --marctype XML --libmap serials_lib.map --password open-ils serials_mfhd.xml | perl ../../src/extras/import/pg_loader.pl -or sre > mfhd21.sql
- psql -f mfhd21.sql