From a7d1ab00418bde1a6bcb00cc212bb29d5f9b8607 Mon Sep 17 00:00:00 2001 From: "J. David Bavousett" Date: Fri, 26 Dec 2008 15:56:55 -0600 Subject: [PATCH] Changes to bulkmarcimport.pl Adds three new switches: -idmap - optional output file of map of source record ID numbers to Koha biblionumber -x - if idmap is supplied, MARC tag to get source record ID from -y - if idmap is supplied, MARC subfield to get source record ID from Signed-off-by: Galen Charlton --- misc/migration_tools/bulkmarcimport.pl | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index b4b84bbf35..5fc8e4c807 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -31,6 +31,7 @@ binmode(STDOUT, ":utf8"); my ( $input_marc_file, $number, $offset) = ('',0,0); my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format); +my ($sourcetag,$sourcesubfield,$idmapfl); $|=1; @@ -47,6 +48,9 @@ GetOptions( 'v:s' => \$verbose, 'fk' => \$fk_off, 'm:s' => \$format, + 'x:s' => \$sourcetag, + 'y:s' => \$sourcesubfield, + 'idmap:s' => \$idmapfl, ); if ($version || ($input_marc_file eq '')) { @@ -69,6 +73,9 @@ Parameters: d delete EVERYTHING related to biblio in koha-DB before import. Tables: biblio, biblioitems, titems m format, MARCXML or ISO2709 (defaults to ISO2709) + x source bib tag for reporting the source bib number + y source subfield for reporting the source bib number + idmap file for the koha bib and source id IMPORTANT: don't use this script before you've entered and checked your MARC parameters tables twice (or more!). Otherwise, the import won't work @@ -83,6 +90,15 @@ EOF exit; } +if (defined $idmapfl) { + open(IDMAP,">$idmapfl") or die "cannot open $idmapfl \n"; +} + +if ((not defined $sourcesubfield) && (not defined $sourcetag)){ + $sourcetag="910"; + $sourcesubfield="a"; +} + my $dbh = C4::Context->dbh; # save the CataloguingLog property : we don't want to log a bulkmarcimport. It will slow the import & @@ -172,6 +188,18 @@ RECORD: while ( ) { warn "ERROR: Adding biblio $biblionumber failed: $@\n"; next RECORD; } + if (defined $idmapfl) { + if ($sourcetag < "010"){ + if ($record->field($sourcetag)){ + my $source = $record->field($sourcetag)->data(); + printf(IDMAP "%s|%s\n",$source,$biblionumber); + } + } else { + my $source=$record->subfield($sourcetag,$sourcesubfield); + printf(IDMAP "%s|%s\n",$source,$biblionumber); + } + } + eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; if ( $@ ) { warn "ERROR: Adding items to bib $biblionumber failed: $@\n"; -- 2.39.5