|
Lines 764-776
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 $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); |
767 |
my $item_match; |
|
|
768 |
my $duplicate_barcode = exists( $item->{'barcode'} ); |
| 768 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
769 |
my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); |
| 769 |
|
770 |
|
|
|
771 |
# We assume that when replacing items we do not want to move them - the onus is on the importer to |
| 772 |
# ensure the correct items/records are being updated |
| 770 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
773 |
my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); |
| 771 |
if ( $action eq "replace" && $duplicate_itemnumber ) { |
774 |
if ( |
|
|
775 |
$action eq "replace" && |
| 776 |
$duplicate_itemnumber && |
| 777 |
( $item_match = Koha::Items->find( $item->{itemnumber} )) |
| 778 |
) { |
| 772 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
779 |
# Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying |
| 773 |
ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber}, { skip_record_index => 1 } ); |
780 |
ModItemFromMarc( $item_marc, $item_match->biblionumber, $item->{itemnumber}, { skip_record_index => 1 } ); |
| 774 |
$updsth->bind_param( 1, 'imported' ); |
781 |
$updsth->bind_param( 1, 'imported' ); |
| 775 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
782 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
| 776 |
$updsth->bind_param( 3, undef ); |
783 |
$updsth->bind_param( 3, undef ); |
|
Lines 778-786
sub _batchCommitItems {
Link Here
|
| 778 |
$updsth->execute(); |
785 |
$updsth->execute(); |
| 779 |
$updsth->finish(); |
786 |
$updsth->finish(); |
| 780 |
$num_items_replaced++; |
787 |
$num_items_replaced++; |
| 781 |
} elsif ( $action eq "replace" && $duplicate_barcode ) { |
788 |
} elsif ( |
| 782 |
my $itemnumber = $duplicate_barcode->itemnumber; |
789 |
$action eq "replace" && |
| 783 |
ModItemFromMarc( $item_marc, $biblionumber, $itemnumber, { skip_record_index => 1 } ); |
790 |
$duplicate_barcode && |
|
|
791 |
( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) ) |
| 792 |
) { |
| 793 |
ModItemFromMarc( $item_marc, $item_match->biblionumber, $item_match->itemnumber, { skip_record_index => 1 } ); |
| 784 |
$updsth->bind_param( 1, 'imported' ); |
794 |
$updsth->bind_param( 1, 'imported' ); |
| 785 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
795 |
$updsth->bind_param( 2, $item->{itemnumber} ); |
| 786 |
$updsth->bind_param( 3, undef ); |
796 |
$updsth->bind_param( 3, undef ); |
|
Lines 788-794
sub _batchCommitItems {
Link Here
|
| 788 |
$updsth->execute(); |
798 |
$updsth->execute(); |
| 789 |
$updsth->finish(); |
799 |
$updsth->finish(); |
| 790 |
$num_items_replaced++; |
800 |
$num_items_replaced++; |
| 791 |
} elsif ($duplicate_barcode) { |
801 |
} elsif ( |
|
|
802 |
# We aren't replacing, but the incoming file ahs a barcode, we need to check if it exists |
| 803 |
$duplicate_barcode && |
| 804 |
( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) ) |
| 805 |
) { |
| 792 |
$updsth->bind_param( 1, 'error' ); |
806 |
$updsth->bind_param( 1, 'error' ); |
| 793 |
$updsth->bind_param( 2, undef ); |
807 |
$updsth->bind_param( 2, undef ); |
| 794 |
$updsth->bind_param( 3, 'duplicate item barcode' ); |
808 |
$updsth->bind_param( 3, 'duplicate item barcode' ); |
| 795 |
- |
|
|