Changes to bulkmarcimport.pl

Adds three new switches:

-idmap <filename> - 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 <galen.charlton@liblime.com>
Signed-off-by: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
This commit is contained in:
J. David Bavousett 2008-12-26 15:56:55 -06:00 committed by Henri-Damien LAURENT
parent d63cec5608
commit ddea584788
1 changed files with 28 additions and 0 deletions

View File

@ -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";