Lines 33-40
use Pod::Usage;
Link Here
|
33 |
binmode(STDOUT, ":utf8"); |
33 |
binmode(STDOUT, ":utf8"); |
34 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
34 |
my ( $input_marc_file, $number, $offset) = ('',0,0); |
35 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
35 |
my ($version, $delete, $test_parameter, $skip_marc8_conversion, $char_encoding, $verbose, $commit, $fk_off,$format,$biblios,$authorities,$keepids,$match, $isbn_check, $logfile); |
36 |
my ($sourcetag,$sourcesubfield,$idmapfl); |
|
|
37 |
my $cleanisbn = 1; |
36 |
my $cleanisbn = 1; |
|
|
37 |
my ($sourcetag,$sourcesubfield,$idmapfl, $dedup_barcode); |
38 |
|
38 |
|
39 |
$|=1; |
39 |
$|=1; |
40 |
|
40 |
|
Lines 61-66
GetOptions(
Link Here
|
61 |
'y:s' => \$sourcesubfield, |
61 |
'y:s' => \$sourcesubfield, |
62 |
'idmap:s' => \$idmapfl, |
62 |
'idmap:s' => \$idmapfl, |
63 |
'cleanisbn!' => \$cleanisbn, |
63 |
'cleanisbn!' => \$cleanisbn, |
|
|
64 |
'dedupbarcode' => \$dedup_barcode, |
64 |
); |
65 |
); |
65 |
$biblios=!$authorities||$biblios; |
66 |
$biblios=!$authorities||$biblios; |
66 |
|
67 |
|
Lines 318-338
RECORD: while ( ) {
Link Here
|
318 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
319 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
319 |
} |
320 |
} |
320 |
eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; |
321 |
eval { ( $itemnumbers_ref, $errors_ref ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; |
321 |
if ( $@ ) { |
322 |
my $error_adding = $@; |
322 |
warn "ERROR: Adding items to bib $biblionumber failed: $@\n"; |
323 |
# Work on a clone so that if there are real errors, we can maybe |
|
|
324 |
# fix them up later. |
325 |
my $clone_record = $record->clone(); |
326 |
C4::Biblio::_strip_item_fields($clone_record, ''); |
327 |
# This sets the marc fields if there was an error, and also calls |
328 |
# defer_marc_save. |
329 |
ModBiblioMarc( $clone_record, $biblionumber, '' ); |
330 |
if ( $error_adding ) { |
331 |
warn "ERROR: Adding items to bib $biblionumber failed: $error_adding"; |
323 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); |
332 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); |
324 |
# if we failed because of an exception, assume that |
333 |
# if we failed because of an exception, assume that |
325 |
# the MARC columns in biblioitems were not set. |
334 |
# the MARC columns in biblioitems were not set. |
326 |
C4::Biblio::_strip_item_fields($record, ''); |
|
|
327 |
ModBiblioMarc( $record, $biblionumber, '' ); |
328 |
next RECORD; |
335 |
next RECORD; |
329 |
} |
336 |
} |
330 |
else{ |
337 |
else{ |
331 |
C4::Biblio::_strip_item_fields($record, ''); |
|
|
332 |
ModBiblioMarc( $record, $biblionumber, '' ); # need to call because of defer_marc_save |
333 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
338 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
334 |
} |
339 |
} |
335 |
if ($#{ $errors_ref } > -1) { |
340 |
if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) { |
|
|
341 |
# Find the record called 'barcode' |
342 |
my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode', ''); |
343 |
# Now remove any items that didn't have a duplicate_barcode error, |
344 |
# erase the barcodes on items that did, and re-add those items. |
345 |
my %dupes; |
346 |
foreach my $i (0 .. $#{$errors_ref}) { |
347 |
my $ref = $errors_ref->[$i]; |
348 |
if ($ref && ($ref->{error_code} eq 'duplicate_barcode')) { |
349 |
$dupes{$ref->{item_sequence}} = 1; |
350 |
# Delete the error message because we're going to |
351 |
# retry this one. |
352 |
delete $errors_ref->[$i]; |
353 |
} |
354 |
} |
355 |
my $seq = 0; |
356 |
foreach my $field ($record->field($tag)) { |
357 |
$seq++; |
358 |
if ($dupes{$seq}) { |
359 |
# Here we remove the barcode |
360 |
$field->delete_subfield(code => $sub); |
361 |
} else { |
362 |
# otherwise we delete the field because we don't want |
363 |
# two of them |
364 |
$record->delete_fields($field); |
365 |
} |
366 |
} |
367 |
# Now re-add the record as before, adding errors to the prev list |
368 |
my $more_errors; |
369 |
eval { ( $itemnumbers_ref, $more_errors ) = AddItemBatchFromMarc( $record, $biblionumber, $biblioitemnumber, '' ); }; |
370 |
if ( $@ ) { |
371 |
warn "ERROR: Adding items to bib $biblionumber failed: $@\n"; |
372 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insertitem",status=>"ERROR"}) if ($logfile); |
373 |
# if we failed because of an exception, assume that |
374 |
# the MARC columns in biblioitems were not set. |
375 |
ModBiblioMarc( $record, $biblionumber, '' ); |
376 |
next RECORD; |
377 |
} else { |
378 |
printlog({id=>$id||$originalid||$biblionumber, op=>"insert",status=>"ok"}) if ($logfile); |
379 |
} |
380 |
push @$errors_ref, @{ $more_errors }; |
381 |
} |
382 |
if ($#{ $errors_ref } > -1) { |
336 |
report_item_errors($biblionumber, $errors_ref); |
383 |
report_item_errors($biblionumber, $errors_ref); |
337 |
} |
384 |
} |
338 |
} |
385 |
} |
Lines 403-408
sub report_item_errors {
Link Here
|
403 |
my $errors_ref = shift; |
450 |
my $errors_ref = shift; |
404 |
|
451 |
|
405 |
foreach my $error (@{ $errors_ref }) { |
452 |
foreach my $error (@{ $errors_ref }) { |
|
|
453 |
next if !$error; |
406 |
my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): "; |
454 |
my $msg = "Item not added (bib $biblionumber, item tag #$error->{'item_sequence'}, barcode $error->{'item_barcode'}): "; |
407 |
my $error_code = $error->{'error_code'}; |
455 |
my $error_code = $error->{'error_code'}; |
408 |
$error_code =~ s/_/ /g; |
456 |
$error_code =~ s/_/ /g; |
Lines 539-544
Store ids in 009 (usefull for authorities, where 001 contains the authid for
Link Here
|
539 |
Koha, that can contain a very valuable info for authorities coming from LOC or |
587 |
Koha, that can contain a very valuable info for authorities coming from LOC or |
540 |
BNF. useless for biblios probably) |
588 |
BNF. useless for biblios probably) |
541 |
|
589 |
|
|
|
590 |
=item B<-dedupbarcode> |
591 |
|
592 |
If set, whenever a duplicate barcode is detected, it is removed and the attempt |
593 |
to add the record is retried, thereby giving the record a blank barcode. This |
594 |
is useful when something has set barcodes to be a biblio ID, or similar |
595 |
(usually other software.) |
596 |
|
542 |
=back |
597 |
=back |
543 |
|
598 |
|
544 |
=cut |
599 |
=cut |
545 |
- |
|
|