X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=misc%2Fstage_biblios_file.pl;h=3f180821042813db35a705956b7c1b86c6dd7848;hb=50466277f7f2d2054f48522507e34b5d5892294a;hp=a692748640b3da8f6de050c9d45dc3eb4530cacb;hpb=991cdc31bcae3c037236c513c74dd3dfdee725a0;p=koha.git diff --git a/misc/stage_biblios_file.pl b/misc/stage_biblios_file.pl index a692748640..3f18082104 100755 --- a/misc/stage_biblios_file.pl +++ b/misc/stage_biblios_file.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl use strict; +#use warnings; FIXME - Bug 2505 BEGIN { # find Koha's Perl modules # test carefully before changing this @@ -21,11 +22,13 @@ my $add_items = 0; my $input_file = ""; my $batch_comment = ""; my $want_help = 0; +my $no_replace ; my $result = GetOptions( 'file:s' => \$input_file, - 'match-bibs' => \$match_bibs, + 'match-bibs:s' => \$match_bibs, 'add-items' => \$add_items, + 'no-replace' => \$no_replace, 'comment:s' => \$batch_comment, 'h|help' => \$want_help ); @@ -54,6 +57,10 @@ sub process_batch { $/ = "\035"; my $num_input_records = 0; while () { + s/^\s+//; + s/\s+$//; + next unless $_; # skip if record has only whitespace, as might occur + # if file includes newlines between each MARC record $marc_records .= $_; # FIXME - this sort of string concatenation # is probably rather inefficient $num_input_records++; @@ -70,10 +77,19 @@ sub process_batch { my $num_with_matches = 0; if ($match_bibs) { - my $matcher = C4::Matcher->new('biblio'); - $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, ''); - $matcher->add_simple_required_check('245', 'a', -1, 0, '', + my $matcher = C4::Matcher->fetch($match_bibs) ; + if (! defined $matcher) { + $matcher = C4::Matcher->new('biblio'); + $matcher->add_simple_matchpoint('isbn', 1000, '020', 'a', -1, 0, ''); + $matcher->add_simple_required_check('245', 'a', -1, 0, '', '245', 'a', -1, 0, ''); + } else { + SetImportBatchMatcher($batch_id, $match_bibs); + } + # set default record overlay behavior + SetImportBatchOverlayAction($batch_id, ($no_replace) ? 'ignore' : 'replace'); + SetImportBatchNoMatchAction($batch_id, 'create_new'); + SetImportBatchItemAction($batch_id, 'always_add'); print "... looking for matches with records already in database\n"; $num_with_matches = BatchFindBibDuplicates($batch_id, $matcher, 10, 100, \&print_progress_and_commit); print "... finished looking for matches\n"; @@ -125,12 +141,16 @@ records into the main Koha database. Parameters: --file name of input MARC bib file - --match-bibs use this option to match bibs + --match-bibs use this option to match bibs in the file with bibs already in the database for future overlay. + If isn't defined, a default + MARC21 ISBN & title match rule will be applied. --add-items use this option to specify that item data is embedded in the MARC bibs and should be parsed. + --no-replace overlay action for bib record: default is to + replace extant bib with the imported record. --comment optional comment to describe the record batch; if the comment has spaces in it, surround the