Lines 716-728
sub BatchCommitItems {
Link Here
|
716 |
|
716 |
|
717 |
my $item = TransformMarcToKoha( $item_marc ); |
717 |
my $item = TransformMarcToKoha( $item_marc ); |
718 |
|
718 |
|
719 |
my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); |
719 |
my $item_match; |
|
|
720 |
my $duplicate_barcode = exists( $item->{'barcode'} ); |
720 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
721 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
721 |
|
722 |
|
|
|
723 |
# We assume that when replacing items we do not want to move them - the onus is on the importer to |
724 |
# ensure the correct items/records are being updated |
722 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
725 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
723 |
if ( $action eq "replace" && $duplicate_itemnumber ) { |
726 |
if ( |
|
|
727 |
$action eq "replace" && |
728 |
$duplicate_itemnumber && |
729 |
( $item_match = Koha::Items->find( $item->{itemnumber} )) |
730 |
) { |
724 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
731 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
725 |
ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} ); |
732 |
ModItemFromMarc( $item_marc, $item_match->biblionumber, $item->{itemnumber}); |
726 |
$updsth->bind_param( 1, 'imported' ); |
733 |
$updsth->bind_param( 1, 'imported' ); |
727 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
734 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
728 |
$updsth->bind_param( 3, undef ); |
735 |
$updsth->bind_param( 3, undef ); |
Lines 730-738
sub BatchCommitItems {
Link Here
|
730 |
$updsth->execute(); |
737 |
$updsth->execute(); |
731 |
$updsth->finish(); |
738 |
$updsth->finish(); |
732 |
$num_items_replaced++; |
739 |
$num_items_replaced++; |
733 |
} elsif ( $action eq "replace" && $duplicate_barcode ) { |
740 |
} elsif ( |
734 |
my $itemnumber = $duplicate_barcode->itemnumber; |
741 |
$action eq "replace" && |
735 |
ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); |
742 |
$duplicate_barcode && |
|
|
743 |
( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) ) |
744 |
) { |
745 |
ModItemFromMarc( $item_marc, $item_match->biblionumber, $item_match->itemnumber ); |
736 |
$updsth->bind_param( 1, 'imported' ); |
746 |
$updsth->bind_param( 1, 'imported' ); |
737 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
747 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
738 |
$updsth->bind_param( 3, undef ); |
748 |
$updsth->bind_param( 3, undef ); |
Lines 740-746
sub BatchCommitItems {
Link Here
|
740 |
$updsth->execute(); |
750 |
$updsth->execute(); |
741 |
$updsth->finish(); |
751 |
$updsth->finish(); |
742 |
$num_items_replaced++; |
752 |
$num_items_replaced++; |
743 |
} elsif ($duplicate_barcode) { |
753 |
} elsif ( |
|
|
754 |
# We aren't replacing, but the incoming file has a barcode, we need to check if it exists |
755 |
$duplicate_barcode && |
756 |
( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) ) |
757 |
) { |
744 |
$updsth->bind_param( 1, 'error' ); |
758 |
$updsth->bind_param( 1, 'error' ); |
745 |
$updsth->bind_param( 2, undef ); |
759 |
$updsth->bind_param( 2, undef ); |
746 |
$updsth->bind_param( 3, 'duplicate item barcode' ); |
760 |
$updsth->bind_param( 3, 'duplicate item barcode' ); |