Lines 514-520
sub BatchFindDuplicates {
Link Here
|
514 |
|
514 |
|
515 |
=head2 BatchCommitRecords |
515 |
=head2 BatchCommitRecords |
516 |
|
516 |
|
517 |
my ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored) = |
517 |
my ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored) = |
518 |
BatchCommitRecords($batch_id, $framework, |
518 |
BatchCommitRecords($batch_id, $framework, |
519 |
$progress_interval, $progress_callback); |
519 |
$progress_interval, $progress_callback); |
520 |
|
520 |
|
Lines 539-544
sub BatchCommitRecords {
Link Here
|
539 |
my $num_added = 0; |
539 |
my $num_added = 0; |
540 |
my $num_updated = 0; |
540 |
my $num_updated = 0; |
541 |
my $num_items_added = 0; |
541 |
my $num_items_added = 0; |
|
|
542 |
my $num_items_replaced = 0; |
542 |
my $num_items_errored = 0; |
543 |
my $num_items_errored = 0; |
543 |
my $num_ignored = 0; |
544 |
my $num_ignored = 0; |
544 |
# commit (i.e., save, all records in the batch) |
545 |
# commit (i.e., save, all records in the batch) |
Lines 598-606
sub BatchCommitRecords {
Link Here
|
598 |
my $biblioitemnumber; |
599 |
my $biblioitemnumber; |
599 |
($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework); |
600 |
($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework); |
600 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
601 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
601 |
if ($item_result eq 'create_new') { |
602 |
if ($item_result eq 'create_new' || $item_result eq 'replace') { |
602 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
603 |
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); |
603 |
$num_items_added += $bib_items_added; |
604 |
$num_items_added += $bib_items_added; |
|
|
605 |
$num_items_replaced += $bib_items_replaced; |
604 |
$num_items_errored += $bib_items_errored; |
606 |
$num_items_errored += $bib_items_errored; |
605 |
} |
607 |
} |
606 |
} else { |
608 |
} else { |
Lines 631-639
sub BatchCommitRecords {
Link Here
|
631 |
ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); |
633 |
ModBiblio($marc_record, $recordid, $oldbiblio->{'frameworkcode'}); |
632 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
634 |
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; |
633 |
|
635 |
|
634 |
if ($item_result eq 'create_new') { |
636 |
if ($item_result eq 'create_new' || $item_result eq 'replace') { |
635 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
637 |
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); |
636 |
$num_items_added += $bib_items_added; |
638 |
$num_items_added += $bib_items_added; |
|
|
639 |
$num_items_replaced += $bib_items_replaced; |
637 |
$num_items_errored += $bib_items_errored; |
640 |
$num_items_errored += $bib_items_errored; |
638 |
} |
641 |
} |
639 |
} else { |
642 |
} else { |
Lines 654-661
sub BatchCommitRecords {
Link Here
|
654 |
$num_ignored++; |
657 |
$num_ignored++; |
655 |
$recordid = $record_match; |
658 |
$recordid = $record_match; |
656 |
if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') { |
659 |
if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') { |
657 |
my ($bib_items_added, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid); |
660 |
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result); |
658 |
$num_items_added += $bib_items_added; |
661 |
$num_items_added += $bib_items_added; |
|
|
662 |
$num_items_replaced += $bib_items_replaced; |
659 |
$num_items_errored += $bib_items_errored; |
663 |
$num_items_errored += $bib_items_errored; |
660 |
# still need to record the matched biblionumber so that the |
664 |
# still need to record the matched biblionumber so that the |
661 |
# items can be reverted |
665 |
# items can be reverted |
Lines 668-674
sub BatchCommitRecords {
Link Here
|
668 |
} |
672 |
} |
669 |
$sth->finish(); |
673 |
$sth->finish(); |
670 |
SetImportBatchStatus($batch_id, 'imported'); |
674 |
SetImportBatchStatus($batch_id, 'imported'); |
671 |
return ($num_added, $num_updated, $num_items_added, $num_items_errored, $num_ignored); |
675 |
return ($num_added, $num_updated, $num_items_added, $num_items_replaced, $num_items_errored, $num_ignored); |
672 |
} |
676 |
} |
673 |
|
677 |
|
674 |
=head2 BatchCommitItems |
678 |
=head2 BatchCommitItems |
Lines 679-690
sub BatchCommitRecords {
Link Here
|
679 |
=cut |
683 |
=cut |
680 |
|
684 |
|
681 |
sub BatchCommitItems { |
685 |
sub BatchCommitItems { |
682 |
my ($import_record_id, $biblionumber) = @_; |
686 |
my ($import_record_id, $biblionumber, $action) = @_; |
683 |
|
687 |
|
684 |
my $dbh = C4::Context->dbh; |
688 |
my $dbh = C4::Context->dbh; |
685 |
|
689 |
|
686 |
my $num_items_added = 0; |
690 |
my ($num_items_added, $num_items_errored, $num_items_replaced) = 0; |
687 |
my $num_items_errored = 0; |
|
|
688 |
my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding |
691 |
my $sth = $dbh->prepare("SELECT import_items_id, import_items.marcxml, encoding |
689 |
FROM import_items |
692 |
FROM import_items |
690 |
JOIN import_records USING (import_record_id) |
693 |
JOIN import_records USING (import_record_id) |
Lines 694-704
sub BatchCommitItems {
Link Here
|
694 |
$sth->execute(); |
697 |
$sth->execute(); |
695 |
while (my $row = $sth->fetchrow_hashref()) { |
698 |
while (my $row = $sth->fetchrow_hashref()) { |
696 |
my $item_marc = MARC::Record->new_from_xml(StripNonXmlChars($row->{'marcxml'}), 'UTF-8', $row->{'encoding'}); |
699 |
my $item_marc = MARC::Record->new_from_xml(StripNonXmlChars($row->{'marcxml'}), 'UTF-8', $row->{'encoding'}); |
|
|
700 |
#delete date_due subfield as to not accidentally delete item checkout due dates |
701 |
my ($MARCfield,$MARCsubfield) = GetMarcFromKohaField('items.onloan', GetFrameworkCode($biblionumber)); |
702 |
$item_marc->field($MARCfield)->delete_subfield(code => $MARCsubfield); |
697 |
# FIXME - duplicate barcode check needs to become part of AddItemFromMarc() |
703 |
# FIXME - duplicate barcode check needs to become part of AddItemFromMarc() |
698 |
my $item = TransformMarcToKoha($dbh, $item_marc); |
704 |
my $item = TransformMarcToKoha($dbh, $item_marc); |
699 |
my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'}); |
705 |
my $duplicate_barcode = exists($item->{'barcode'}) && GetItemnumberFromBarcode($item->{'barcode'}); |
700 |
if ($duplicate_barcode) { |
706 |
my $duplicate_itemnumber = exists($item->{'itemnumber'}); |
701 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, import_error = ? WHERE import_items_id = ?"); |
707 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); |
|
|
708 |
if($action eq "replace" && $duplicate_itemnumber){ |
709 |
ModItemFromMarc($item_marc, $biblionumber, $item->{itemnumber}); |
710 |
$updsth->bind_param(1, 'imported'); |
711 |
$updsth->bind_param(2, $item->{itemnumber}); |
712 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
713 |
$updsth->execute(); |
714 |
$updsth->finish(); |
715 |
$num_items_replaced++; |
716 |
} |
717 |
elsif ($duplicate_barcode) { |
702 |
$updsth->bind_param(1, 'error'); |
718 |
$updsth->bind_param(1, 'error'); |
703 |
$updsth->bind_param(2, 'duplicate item barcode'); |
719 |
$updsth->bind_param(2, 'duplicate item barcode'); |
704 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
720 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
Lines 706-712
sub BatchCommitItems {
Link Here
|
706 |
$num_items_errored++; |
722 |
$num_items_errored++; |
707 |
} else { |
723 |
} else { |
708 |
my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($item_marc, $biblionumber); |
724 |
my ($item_biblionumber, $biblioitemnumber, $itemnumber) = AddItemFromMarc($item_marc, $biblionumber); |
709 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); |
|
|
710 |
$updsth->bind_param(1, 'imported'); |
725 |
$updsth->bind_param(1, 'imported'); |
711 |
$updsth->bind_param(2, $itemnumber); |
726 |
$updsth->bind_param(2, $itemnumber); |
712 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
727 |
$updsth->bind_param(3, $row->{'import_items_id'}); |
Lines 716-722
sub BatchCommitItems {
Link Here
|
716 |
} |
731 |
} |
717 |
} |
732 |
} |
718 |
$sth->finish(); |
733 |
$sth->finish(); |
719 |
return ($num_items_added, $num_items_errored); |
734 |
return ($num_items_added, $num_items_replaced, $num_items_errored); |
720 |
} |
735 |
} |
721 |
|
736 |
|
722 |
=head2 BatchRevertRecords |
737 |
=head2 BatchRevertRecords |
Lines 1467-1473
sub _get_commit_action {
Link Here
|
1467 |
} elsif ($overlay_action eq 'ignore') { |
1482 |
} elsif ($overlay_action eq 'ignore') { |
1468 |
$bib_result = 'ignore'; |
1483 |
$bib_result = 'ignore'; |
1469 |
} |
1484 |
} |
1470 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_matches') ? 'create_new' : 'ignore'; |
1485 |
if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){ |
|
|
1486 |
$item_result = 'create_new'; |
1487 |
} |
1488 |
elsif($item_action eq 'replace'){ |
1489 |
$item_result = 'replace'; |
1490 |
} |
1491 |
else { |
1492 |
$item_result = 'ignore'; |
1493 |
} |
1471 |
} else { |
1494 |
} else { |
1472 |
$bib_result = $nomatch_action; |
1495 |
$bib_result = $nomatch_action; |
1473 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new') ? 'create_new' : 'ignore'; |
1496 |
$item_result = ($item_action eq 'always_add' or $item_action eq 'add_only_for_new') ? 'create_new' : 'ignore'; |