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

(-)a/C4/ImportBatch.pm (-4 / +16 lines)
Lines 654-662 sub BatchCommitRecords { Link Here
654
            SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
654
            SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
655
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
655
            SetImportRecordStatus($rowref->{'import_record_id'}, 'imported');
656
        } elsif ($record_result eq 'ignore') {
656
        } elsif ($record_result eq 'ignore') {
657
            $recordid = $record_match;
657
            $num_ignored++;
658
            $num_ignored++;
658
            $recordid = $record_match;
659
            $recordid = $record_match;
659
            if ($record_type eq 'biblio' and defined $recordid and $item_result eq 'create_new') {
660
            if ($record_type eq 'biblio' and defined $recordid and ( $item_result eq 'create_new' || $item_result eq 'replace' ) ) {
660
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
661
                my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
661
                $num_items_added += $bib_items_added;
662
                $num_items_added += $bib_items_added;
662
         $num_items_replaced += $bib_items_replaced;
663
         $num_items_replaced += $bib_items_replaced;
Lines 688-706 sub BatchCommitItems { Link Here
688
    my $dbh = C4::Context->dbh;
689
    my $dbh = C4::Context->dbh;
689
690
690
    my ( $num_items_added, $num_items_errored, $num_items_replaced ) = 0;
691
    my ( $num_items_added, $num_items_errored, $num_items_replaced ) = 0;
691
    my $sth = $dbh->prepare("
692
    my $sth = $dbh->prepare( "
692
        SELECT import_items_id, import_items.marcxml, encoding
693
        SELECT import_items_id, import_items.marcxml, encoding
693
        FROM import_items
694
        FROM import_items
694
        JOIN import_records USING (import_record_id)
695
        JOIN import_records USING (import_record_id)
695
        WHERE import_record_id = ?
696
        WHERE import_record_id = ?
696
        ORDER BY import_items_id
697
        ORDER BY import_items_id
697
    ");
698
    " );
698
    $sth->bind_param( 1, $import_record_id );
699
    $sth->bind_param( 1, $import_record_id );
699
    $sth->execute();
700
    $sth->execute();
701
700
    while ( my $row = $sth->fetchrow_hashref() ) {
702
    while ( my $row = $sth->fetchrow_hashref() ) {
701
        my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
703
        my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} );
702
704
703
        #delete date_due subfield as to not accidentally delete item checkout due dates
705
        # Delete date_due subfield as to not accidentally delete item checkout due dates
704
        my ( $MARCfield, $MARCsubfield ) = GetMarcFromKohaField( 'items.onloan', GetFrameworkCode($biblionumber) );
706
        my ( $MARCfield, $MARCsubfield ) = GetMarcFromKohaField( 'items.onloan', GetFrameworkCode($biblionumber) );
705
        $item_marc->field($MARCfield)->delete_subfield( code => $MARCsubfield );
707
        $item_marc->field($MARCfield)->delete_subfield( code => $MARCsubfield );
706
708
Lines 711-716 sub BatchCommitItems { Link Here
711
713
712
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
714
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
713
        if ( $action eq "replace" && $duplicate_itemnumber ) {
715
        if ( $action eq "replace" && $duplicate_itemnumber ) {
716
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
714
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
717
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
715
            $updsth->bind_param( 1, 'imported' );
718
            $updsth->bind_param( 1, 'imported' );
716
            $updsth->bind_param( 2, $item->{itemnumber} );
719
            $updsth->bind_param( 2, $item->{itemnumber} );
Lines 718-723 sub BatchCommitItems { Link Here
718
            $updsth->execute();
721
            $updsth->execute();
719
            $updsth->finish();
722
            $updsth->finish();
720
            $num_items_replaced++;
723
            $num_items_replaced++;
724
        } elsif ( $action eq "replace" && $duplicate_barcode ) {
725
            my $itemnumber = GetItemnumberFromBarcode( $item->{'barcode'} );
726
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
727
            $updsth->bind_param( 1, 'imported' );
728
            $updsth->bind_param( 2, $item->{itemnumber} );
729
            $updsth->bind_param( 3, $row->{'import_items_id'} );
730
            $updsth->execute();
731
            $updsth->finish();
732
            $num_items_replaced++;
721
        } elsif ($duplicate_barcode) {
733
        } elsif ($duplicate_barcode) {
722
            $updsth->bind_param( 1, 'error' );
734
            $updsth->bind_param( 1, 'error' );
723
            $updsth->bind_param( 2, 'duplicate item barcode' );
735
            $updsth->bind_param( 2, 'duplicate item barcode' );
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +11 lines)
Lines 6983-6988 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ( Link Here
6983
    SetVersion($DBversion);
6983
    SetVersion($DBversion);
6984
}
6984
}
6985
6985
6986
$DBversion = "3.13.00.XXX";
6987
if ( CheckVersion($DBversion) ) {
6988
    $dbh->do("
6989
        ALTER TABLE `import_batches`
6990
        CHANGE `item_action` `item_action`
6991
          ENUM( 'always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore', 'replace' )
6992
          NOT NULL DEFAULT 'always_add'
6993
    ");
6994
    print "Upgrade to $DBversion done (Bug 7131 - way to overlay items in in marc import)\n";
6995
    SetVersion($DBversion);
6996
}
6986
6997
6987
=head1 FUNCTIONS
6998
=head1 FUNCTIONS
6988
6999
6989
- 

Return to bug 7131