Lines 499-505
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
499 |
} |
499 |
} |
500 |
} |
500 |
} |
501 |
else { |
501 |
else { |
502 |
my ($biblioitemnumber, $itemnumbers_ref, $errors_ref, $record_id); |
502 |
my ($biblioitemnumber, $itemnumbers, $errors, $record_id); |
503 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
503 |
# check for duplicate, based on ISBN (skip it if we already have found a duplicate with match parameter |
504 |
if (!$matched_record_id && $isbn_check && $isbn) { |
504 |
if (!$matched_record_id && $isbn_check && $isbn) { |
505 |
$sth_isbn->execute($isbn); |
505 |
$sth_isbn->execute($isbn); |
Lines 548-554
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
548 |
} |
548 |
} |
549 |
} |
549 |
} |
550 |
elsif ($insert) { |
550 |
elsif ($insert) { |
551 |
eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework, { defer_marc_save => 1 }) }; |
551 |
eval { ($record_id, $biblioitemnumber) = AddBiblio($record, $framework) }; |
552 |
if ($@) { |
552 |
if ($@) { |
553 |
warn "ERROR: Insert biblio $originalid failed: $@\n"; |
553 |
warn "ERROR: Insert biblio $originalid failed: $@\n"; |
554 |
printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile); |
554 |
printlog( { id => $originalid, op => "insert", status => "ERROR" } ) if ($logfile); |
Lines 566-582
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
566 |
my $record_has_added_items = 0; |
566 |
my $record_has_added_items = 0; |
567 |
if ($record_id) { |
567 |
if ($record_id) { |
568 |
$yamlhash->{$originalid} = $record_id if $yamlfile; |
568 |
$yamlhash->{$originalid} = $record_id if $yamlfile; |
569 |
eval { ($itemnumbers_ref, $errors_ref) = AddItemBatchFromMarc($record, $record_id, $biblioitemnumber, $framework); }; |
569 |
eval { ($itemnumbers, $errors) = AddItemBatchFromMarc($record, $record_id, $biblioitemnumber, $framework); }; |
570 |
$record_has_added_items = @{$itemnumbers_ref}; |
|
|
571 |
|
572 |
my $error_adding = $@; |
570 |
my $error_adding = $@; |
573 |
# Work on a clone so that if there are real errors, we can maybe |
571 |
$record_has_added_items = @{$itemnumbers}; |
574 |
# fix them up later. |
|
|
575 |
my $clone_record = $record->clone(); |
576 |
C4::Biblio::_strip_item_fields($clone_record, $framework); |
577 |
# This sets the marc fields if there was an error, and also calls |
578 |
# defer_marc_save. |
579 |
ModBiblioMarc($clone_record, $record_id, $modify_biblio_marc_options); |
580 |
if ($error_adding) { |
572 |
if ($error_adding) { |
581 |
warn "ERROR: Adding items to bib $record_id failed: $error_adding"; |
573 |
warn "ERROR: Adding items to bib $record_id failed: $error_adding"; |
582 |
printlog({ id => $record_id, op => "insert items", status => "ERROR"}) if ($logfile); |
574 |
printlog({ id => $record_id, op => "insert items", status => "ERROR"}) if ($logfile); |
Lines 587-605
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
587 |
else { |
579 |
else { |
588 |
printlog({ id => $record_id, op => "insert items", status => "ok" }) if ($logfile); |
580 |
printlog({ id => $record_id, op => "insert items", status => "ok" }) if ($logfile); |
589 |
} |
581 |
} |
590 |
if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @$errors_ref) { |
582 |
if ($dedup_barcode && grep { exists $_->{error_code} && $_->{error_code} eq 'duplicate_barcode' } @{$errors}) { |
591 |
# Find the record called 'barcode' |
583 |
# Find the record called 'barcode' |
592 |
my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode'); |
584 |
my ($tag, $sub) = C4::Biblio::GetMarcFromKohaField('items.barcode'); |
593 |
# Now remove any items that didn't have a duplicate_barcode error, |
585 |
# Now remove any items that didn't have a duplicate_barcode error, |
594 |
# erase the barcodes on items that did, and re-add those items. |
586 |
# erase the barcodes on items that did, and re-add those items. |
595 |
my %dupes; |
587 |
my %dupes; |
596 |
foreach my $i (0 .. $#{$errors_ref}) { |
588 |
foreach my $i (0 .. $#{$errors}) { |
597 |
my $ref = $errors_ref->[$i]; |
589 |
my $error = $errors->[$i]; |
598 |
if ($ref && ($ref->{error_code} eq 'duplicate_barcode')) { |
590 |
if ($error && ($error->{error_code} eq 'duplicate_barcode')) { |
599 |
$dupes{$ref->{item_sequence}} = 1; |
591 |
$dupes{$error->{item_sequence}} = 1; |
600 |
# Delete the error message because we're going to |
592 |
# Delete the error message because we're going to |
601 |
# retry this one. |
593 |
# retry this one. |
602 |
delete $errors_ref->[$i]; |
594 |
delete $errors->[$i]; |
603 |
} |
595 |
} |
604 |
} |
596 |
} |
605 |
my $seq = 0; |
597 |
my $seq = 0; |
Lines 617-642
RECORD: foreach my $record (@{$marc_records}) {
Link Here
|
617 |
} |
609 |
} |
618 |
# Now re-add the record as before, adding errors to the prev list |
610 |
# Now re-add the record as before, adding errors to the prev list |
619 |
my $more_errors; |
611 |
my $more_errors; |
620 |
eval { ($itemnumbers_ref, $more_errors) = AddItemBatchFromMarc($record, $record_id, $biblioitemnumber, ''); }; |
612 |
eval { ($itemnumbers, $more_errors) = AddItemBatchFromMarc($record, $record_id, $biblioitemnumber, ''); }; |
621 |
$record_has_added_items ||= @{$itemnumbers_ref}; |
613 |
$error_adding = $@; |
622 |
if ($@) { |
614 |
$record_has_added_items ||= @{$itemnumbers}; |
623 |
warn "ERROR: Adding items to bib $record_id failed: $@\n"; |
615 |
if ($error_adding) { |
|
|
616 |
warn "ERROR: Adding items to bib $record_id failed: $error_adding\n"; |
624 |
printlog({ id => $record_id, op => "insert items", status => "ERROR" }) if ($logfile); |
617 |
printlog({ id => $record_id, op => "insert items", status => "ERROR" }) if ($logfile); |
625 |
# if we failed because of an exception, assume that |
618 |
# if we failed because of an exception, assume that |
626 |
# the MARC columns in biblioitems were not set. |
619 |
# the MARC columns in biblioitems were not set. |
627 |
|
|
|
628 |
# @FIXME: Why do we save here without stripping items? Besides, |
629 |
# save with stripped items has already been performed |
630 |
ModBiblioMarc($record, $record_id, $modify_biblio_marc_options); |
631 |
next RECORD; |
620 |
next RECORD; |
632 |
} |
621 |
} |
633 |
else { |
622 |
else { |
634 |
printlog({ id => $record_id, op => "insert", status => "ok" }) if ($logfile); |
623 |
printlog({ id => $record_id, op => "insert", status => "ok" }) if ($logfile); |
635 |
} |
624 |
} |
636 |
push @$errors_ref, @{$more_errors}; |
625 |
push @{$errors}, @{$more_errors}; |
637 |
} |
626 |
} |
638 |
if (@{$errors_ref}) { |
627 |
if (@{$errors}) { |
639 |
report_item_errors($record_id, $errors_ref); |
628 |
report_item_errors($record_id, $errors); |
640 |
} |
629 |
} |
641 |
C4::Biblio::_strip_item_fields($record, $framework); |
630 |
C4::Biblio::_strip_item_fields($record, $framework); |
642 |
if ($record_has_added_items || $matched_record_id) { |
631 |
if ($record_has_added_items || $matched_record_id) { |
643 |
- |
|
|