Lines 764-803
sub _batchCommitItems {
Link Here
|
764 |
|
764 |
|
765 |
my $item = TransformMarcToKoha({ record => $item_marc, kohafields => ['items.barcode','items.itemnumber'] }); |
765 |
my $item = TransformMarcToKoha({ record => $item_marc, kohafields => ['items.barcode','items.itemnumber'] }); |
766 |
|
766 |
|
767 |
my $item_match; |
|
|
768 |
my $duplicate_barcode = exists( $item->{'barcode'} ); |
767 |
my $duplicate_barcode = exists( $item->{'barcode'} ); |
769 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
768 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
770 |
|
769 |
|
771 |
# We assume that when replaicing tiems we do not want to move them - the onus is on the importer to |
770 |
# We assume that when replaicing tiems we do not want to move them - the onus is on the importer to |
772 |
# ensure the correct items/records are being updated |
771 |
# ensure the correct items/records are being updated |
773 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
772 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
|
|
773 |
my $matched_itemnumber_item = Koha::Items->find( $item->{itemnumber} ); |
774 |
my $matched_barcode_item = Koha::Items->find({ barcode => $item->{barcode} }); |
774 |
if ( |
775 |
if ( |
775 |
$action eq "replace" && |
776 |
rindex( $action, 'replace', 0 ) && |
776 |
$duplicate_itemnumber && |
777 |
$duplicate_itemnumber && |
777 |
( $item_match = Koha::Items->find( $item->{itemnumber} )) |
778 |
$matched_itemnumber_item |
778 |
) { |
779 |
) { |
779 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
780 |
if ( $action eq 'replace_if_bib_match' && $matched_itemnumber_item->biblionumber != $biblionumber ) { |
780 |
ModItemFromMarc( $item_marc, $item_match->biblionumber, $item->{itemnumber}, { skip_record_index => 1 } ); |
781 |
$updsth->bind_param( 1, 'error' ); |
781 |
$updsth->bind_param( 1, 'imported' ); |
782 |
$updsth->bind_param( 2, undef ); |
782 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
783 |
$updsth->bind_param( 3, 'matched itemnumber on different record' ); |
783 |
$updsth->bind_param( 3, undef ); |
784 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
784 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
785 |
$updsth->execute(); |
785 |
$updsth->execute(); |
786 |
$num_items_errored++; |
786 |
$updsth->finish(); |
787 |
} else { |
787 |
$num_items_replaced++; |
788 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
|
|
789 |
ModItemFromMarc( $item_marc, $matched_itemnumber_item->biblionumber, $item->{itemnumber}, { skip_record_index => 1 } ); |
790 |
$updsth->bind_param( 1, 'imported' ); |
791 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
792 |
$updsth->bind_param( 3, undef ); |
793 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
794 |
$updsth->execute(); |
795 |
$updsth->finish(); |
796 |
$num_items_replaced++; |
797 |
} |
788 |
} elsif ( |
798 |
} elsif ( |
789 |
$action eq "replace" && |
799 |
$action eq "replace" && |
790 |
$duplicate_barcode && |
800 |
$duplicate_barcode && |
791 |
( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) ) |
801 |
$matched_barcode_item |
792 |
) { |
802 |
) { |
793 |
ModItemFromMarc( $item_marc, $item_match->biblionumber, $item_match->itemnumber, { skip_record_index => 1 } ); |
803 |
if ( $action eq 'replace_if_bib_match' && $matched_barcode_item->biblionumber != $biblionumber ) { |
794 |
$updsth->bind_param( 1, 'imported' ); |
804 |
$updsth->bind_param( 1, 'error' ); |
795 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
805 |
$updsth->bind_param( 2, undef ); |
796 |
$updsth->bind_param( 3, undef ); |
806 |
$updsth->bind_param( 3, 'matched barcode on different record' ); |
797 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
807 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
798 |
$updsth->execute(); |
808 |
$updsth->execute(); |
799 |
$updsth->finish(); |
809 |
$num_items_errored++; |
800 |
$num_items_replaced++; |
810 |
} else { |
|
|
811 |
ModItemFromMarc( $item_marc, $matched_barcode_item->biblionumber, $matched_barcode_item->itemnumber, { skip_record_index => 1 } ); |
812 |
$updsth->bind_param( 1, 'imported' ); |
813 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
814 |
$updsth->bind_param( 3, undef ); |
815 |
$updsth->bind_param( 4, $row->{'import_items_id'} ); |
816 |
$updsth->execute(); |
817 |
$updsth->finish(); |
818 |
$num_items_replaced++; |
819 |
} |
801 |
} elsif ($duplicate_barcode) { |
820 |
} elsif ($duplicate_barcode) { |
802 |
$updsth->bind_param( 1, 'error' ); |
821 |
$updsth->bind_param( 1, 'error' ); |
803 |
$updsth->bind_param( 2, undef ); |
822 |
$updsth->bind_param( 2, undef ); |
Lines 1748-1758
sub _get_commit_action {
Link Here
|
1748 |
|
1767 |
|
1749 |
$bib_result = $overlay_action; |
1768 |
$bib_result = $overlay_action; |
1750 |
|
1769 |
|
1751 |
if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){ |
1770 |
if ( $item_action eq 'always_add' |
|
|
1771 |
or $item_action eq 'add_only_for_matches' ) |
1772 |
{ |
1752 |
$item_result = 'create_new'; |
1773 |
$item_result = 'create_new'; |
1753 |
} elsif($item_action eq 'replace'){ |
1774 |
} |
|
|
1775 |
elsif ( $item_action eq 'replace' ) { |
1754 |
$item_result = 'replace'; |
1776 |
$item_result = 'replace'; |
1755 |
} else { |
1777 |
} |
|
|
1778 |
elsif ( $item_action eq 'replace_if_bib_match' ) { |
1779 |
$item_result = 'replace_if_bib_match'; |
1780 |
} |
1781 |
else { |
1756 |
$item_result = 'ignore'; |
1782 |
$item_result = 'ignore'; |
1757 |
} |
1783 |
} |
1758 |
|
1784 |
|