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