View | Details | Raw Unified | Return to bug 32804
Collapse All | Expand All

(-)a/C4/ImportBatch.pm (-7 / +16 lines)
Lines 750-762 sub _batchCommitItems { Link Here
750
750
751
        my $item = TransformMarcToKoha({ record => $item_marc, kohafields => ['items.barcode','items.itemnumber'] });
751
        my $item = TransformMarcToKoha({ record => $item_marc, kohafields => ['items.barcode','items.itemnumber'] });
752
752
753
        my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} });
753
        my $item_match;
754
        my $duplicate_barcode = exists( $item->{'barcode'} );
754
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
755
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
755
756
757
        # We assume that when replaicing tiems we do not want to move them - the onus is on the importer to
758
        # ensure the correct items/records are being updated
756
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
759
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
757
        if ( $action eq "replace" && $duplicate_itemnumber ) {
760
        if (
761
            $action eq "replace" &&
762
            $duplicate_itemnumber &&
763
            ( $item_match = Koha::Items->find( $item->{itemnumber} ))
764
        ) {
758
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
765
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
759
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );
766
            ModItemFromMarc( $item_marc, $item_match->biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );
760
            $updsth->bind_param( 1, 'imported' );
767
            $updsth->bind_param( 1, 'imported' );
761
            $updsth->bind_param( 2, $item->{itemnumber} );
768
            $updsth->bind_param( 2, $item->{itemnumber} );
762
            $updsth->bind_param( 3, undef );
769
            $updsth->bind_param( 3, undef );
Lines 764-772 sub _batchCommitItems { Link Here
764
            $updsth->execute();
771
            $updsth->execute();
765
            $updsth->finish();
772
            $updsth->finish();
766
            $num_items_replaced++;
773
            $num_items_replaced++;
767
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
774
        } elsif (
768
            my $itemnumber = $duplicate_barcode->itemnumber;
775
            $action eq "replace" &&
769
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber, { skip_record_index => 1 } );
776
            $duplicate_barcode &&
777
            ( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) )
778
        ) {
779
            ModItemFromMarc( $item_marc, $item_match->biblionumber, $item_match->itemnumber, { skip_record_index => 1 } );
770
            $updsth->bind_param( 1, 'imported' );
780
            $updsth->bind_param( 1, 'imported' );
771
            $updsth->bind_param( 2, $item->{itemnumber} );
781
            $updsth->bind_param( 2, $item->{itemnumber} );
772
            $updsth->bind_param( 3, undef );
782
            $updsth->bind_param( 3, undef );
773
- 

Return to bug 32804