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 / +13 lines)
Lines 7067-7072 if ( CheckVersion($DBversion) ) { Link Here
7067
    SetVersion($DBversion);
7067
    SetVersion($DBversion);
7068
}
7068
}
7069
7069
7070
$DBversion = "3.13.00.XXX";
7071
if ( CheckVersion($DBversion) ) {
7072
    $dbh->do("
7073
        ALTER TABLE `import_batches`
7074
        CHANGE `item_action` `item_action`
7075
          ENUM( 'always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore', 'replace' )
7076
          NOT NULL DEFAULT 'always_add'
7077
    ");
7078
    print "Upgrade to $DBversion done (Bug 7131 - way to overlay items in in marc import)\n";
7079
    SetVersion($DBversion);
7080
}
7081
7082
7070
=head1 FUNCTIONS
7083
=head1 FUNCTIONS
7071
7084
7072
=head2 TableExists($table)
7085
=head2 TableExists($table)
7073
- 

Return to bug 7131