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

(-)a/C4/ImportBatch.pm (-24 / +50 lines)
Lines 764-803 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 $item_match;
768
        my $duplicate_barcode = exists( $item->{'barcode'} );
767
        my $duplicate_barcode = exists( $item->{'barcode'} );
769
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
768
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
770
769
771
        # We assume that when replaicing tiems we do not want to move them - the onus is on the importer to
770
        # We assume that when replaicing tiems we do not want to move them - the onus is on the importer to
772
        # ensure the correct items/records are being updated
771
        # ensure the correct items/records are being updated
773
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
772
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
773
        my $matched_itemnumber_item = Koha::Items->find( $item->{itemnumber} );
774
        my $matched_barcode_item = Koha::Items->find({ barcode => $item->{barcode} });
774
        if (
775
        if (
775
            $action eq "replace" &&
776
            rindex( $action, 'replace', 0 ) &&
776
            $duplicate_itemnumber &&
777
            $duplicate_itemnumber &&
777
            ( $item_match = Koha::Items->find( $item->{itemnumber} ))
778
            $matched_itemnumber_item
778
        ) {
779
        ) {
779
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
780
            if ( $action eq 'replace_if_bib_match' && $matched_itemnumber_item->biblionumber != $biblionumber ) {
780
            ModItemFromMarc( $item_marc, $item_match->biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );
781
                $updsth->bind_param( 1, 'error' );
781
            $updsth->bind_param( 1, 'imported' );
782
                $updsth->bind_param( 2, undef );
782
            $updsth->bind_param( 2, $item->{itemnumber} );
783
                $updsth->bind_param( 3, 'matched itemnumber on different record' );
783
            $updsth->bind_param( 3, undef );
784
                $updsth->bind_param( 4, $row->{'import_items_id'} );
784
            $updsth->bind_param( 4, $row->{'import_items_id'} );
785
                $updsth->execute();
785
            $updsth->execute();
786
                $num_items_errored++;
786
            $updsth->finish();
787
            } else {
787
            $num_items_replaced++;
788
                # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
789
                ModItemFromMarc( $item_marc, $matched_itemnumber_item->biblionumber, $item->{itemnumber}, { skip_record_index => 1 } );
790
                $updsth->bind_param( 1, 'imported' );
791
                $updsth->bind_param( 2, $item->{itemnumber} );
792
                $updsth->bind_param( 3, undef );
793
                $updsth->bind_param( 4, $row->{'import_items_id'} );
794
                $updsth->execute();
795
                $updsth->finish();
796
                $num_items_replaced++;
797
            }
788
        } elsif (
798
        } elsif (
789
            $action eq "replace" &&
799
            $action eq "replace" &&
790
            $duplicate_barcode &&
800
            $duplicate_barcode &&
791
            ( $item_match = Koha::Items->find({ barcode => $item->{'barcode'} }) )
801
            $matched_barcode_item
792
        ) {
802
        ) {
793
            ModItemFromMarc( $item_marc, $item_match->biblionumber, $item_match->itemnumber, { skip_record_index => 1 } );
803
            if ( $action eq 'replace_if_bib_match' && $matched_barcode_item->biblionumber != $biblionumber ) {
794
            $updsth->bind_param( 1, 'imported' );
804
                $updsth->bind_param( 1, 'error' );
795
            $updsth->bind_param( 2, $item->{itemnumber} );
805
                $updsth->bind_param( 2, undef );
796
            $updsth->bind_param( 3, undef );
806
                $updsth->bind_param( 3, 'matched barcode on different record' );
797
            $updsth->bind_param( 4, $row->{'import_items_id'} );
807
                $updsth->bind_param( 4, $row->{'import_items_id'} );
798
            $updsth->execute();
808
                $updsth->execute();
799
            $updsth->finish();
809
                $num_items_errored++;
800
            $num_items_replaced++;
810
            } else {
811
                ModItemFromMarc( $item_marc, $matched_barcode_item->biblionumber, $matched_barcode_item->itemnumber, { skip_record_index => 1 } );
812
                $updsth->bind_param( 1, 'imported' );
813
                $updsth->bind_param( 2, $item->{itemnumber} );
814
                $updsth->bind_param( 3, undef );
815
                $updsth->bind_param( 4, $row->{'import_items_id'} );
816
                $updsth->execute();
817
                $updsth->finish();
818
                $num_items_replaced++;
819
            }
801
        } elsif ($duplicate_barcode) {
820
        } elsif ($duplicate_barcode) {
802
            $updsth->bind_param( 1, 'error' );
821
            $updsth->bind_param( 1, 'error' );
803
            $updsth->bind_param( 2, undef );
822
            $updsth->bind_param( 2, undef );
Lines 1748-1758 sub _get_commit_action { Link Here
1748
1767
1749
            $bib_result = $overlay_action;
1768
            $bib_result = $overlay_action;
1750
1769
1751
            if($item_action eq 'always_add' or $item_action eq 'add_only_for_matches'){
1770
            if (   $item_action eq 'always_add'
1771
                or $item_action eq 'add_only_for_matches' )
1772
            {
1752
                $item_result = 'create_new';
1773
                $item_result = 'create_new';
1753
            } elsif($item_action eq 'replace'){
1774
            }
1775
            elsif ( $item_action eq 'replace' ) {
1754
                $item_result = 'replace';
1776
                $item_result = 'replace';
1755
            } else {
1777
            }
1778
            elsif ( $item_action eq 'replace_if_bib_match' ) {
1779
                $item_result = 'replace_if_bib_match';
1780
            }
1781
            else {
1756
                $item_result = 'ignore';
1782
                $item_result = 'ignore';
1757
            }
1783
            }
1758
1784
(-)a/installer/data/mysql/atomicupdate/bug_32902.pl (+14 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "32902",
5
    description => "Add new item overlay action 'replace_if_bib_match'",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        $dbh->do(q{
10
            ALTER TABLE import_batches MODIFY item_action
11
            enum('always_add','add_only_for_matches','add_only_for_new','ignore','replace','replace_if_bib_match') NOT NULL DEFAULT 'always_add'
12
            COMMENT 'what to do with item records'});
13
        },
14
};
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 3328-3334 CREATE TABLE `import_batches` ( Link Here
3328
  `upload_timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date and time the file was uploaded',
3328
  `upload_timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date and time the file was uploaded',
3329
  `overlay_action` enum('replace','create_new','use_template','ignore') NOT NULL DEFAULT 'create_new' COMMENT 'how to handle duplicate records',
3329
  `overlay_action` enum('replace','create_new','use_template','ignore') NOT NULL DEFAULT 'create_new' COMMENT 'how to handle duplicate records',
3330
  `nomatch_action` enum('create_new','ignore') NOT NULL DEFAULT 'create_new' COMMENT 'how to handle records where no match is found',
3330
  `nomatch_action` enum('create_new','ignore') NOT NULL DEFAULT 'create_new' COMMENT 'how to handle records where no match is found',
3331
  `item_action` enum('always_add','add_only_for_matches','add_only_for_new','ignore','replace') NOT NULL DEFAULT 'always_add' COMMENT 'what to do with item records',
3331
  `item_action` enum('always_add','add_only_for_matches','add_only_for_new','ignore','replace','replace_if_bib_match') NOT NULL DEFAULT 'always_add' COMMENT 'what to do with item records',
3332
  `import_status` enum('staging','staged','importing','imported','reverting','reverted','cleaned') NOT NULL DEFAULT 'staging' COMMENT 'the status of the imported file',
3332
  `import_status` enum('staging','staged','importing','imported','reverting','reverted','cleaned') NOT NULL DEFAULT 'staging' COMMENT 'the status of the imported file',
3333
  `batch_type` enum('batch','z3950','webservice') NOT NULL DEFAULT 'batch' COMMENT 'where this batch has come from',
3333
  `batch_type` enum('batch','z3950','webservice') NOT NULL DEFAULT 'batch' COMMENT 'where this batch has come from',
3334
  `record_type` enum('biblio','auth','holdings') NOT NULL DEFAULT 'biblio' COMMENT 'type of record in the batch',
3334
  `record_type` enum('biblio','auth','holdings') NOT NULL DEFAULT 'biblio' COMMENT 'type of record in the batch',
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-item-action.inc (-1 / +7 lines)
Lines 26-32 Link Here
26
            [% ELSE %]
26
            [% ELSE %]
27
                <option value="replace">
27
                <option value="replace">
28
            [% END %]
28
            [% END %]
29
                Replace items if matching record was found (only for existing items)</option>
29
                Replace matching items if any matching record was found (only for existing items)</option>
30
            [% IF ( item_action_replace_if_bib_match ) %]
31
                <option value="replace_if_bib_match" selected="selected">
32
            [% ELSE %]
33
                <option value="replace_if_bib_match">
34
            [% END %]
35
                Replace matching items if matching item is on matching record (only for existing items)</option>
30
            [% IF ( item_action_ignore ) %]
36
            [% IF ( item_action_ignore ) %]
31
                <option value="ignore" selected="selected">
37
                <option value="ignore" selected="selected">
32
            [% ELSE %]
38
            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt (-1 / +4 lines)
Lines 243-248 Link Here
243
                                                <span>Add items only if no matching record was found</span>
243
                                                <span>Add items only if no matching record was found</span>
244
                                            [% ELSIF ( item_action == 'ignore' ) %]
244
                                            [% ELSIF ( item_action == 'ignore' ) %]
245
                                                <span>Ignore items</span>
245
                                                <span>Ignore items</span>
246
                                            [% ELSIF ( item_action == 'replace' ) %]
247
                                                <span>Replace matching items if any matching record was found (only for existing items)</span>
248
                                            [% ELSIF ( item_action == 'replace_if_bib_match' ) %]
249
                                                <span>Replace matching items if matching item is on matching record (only for existing items)</span>
246
                                            [% ELSE %]
250
                                            [% ELSE %]
247
                                                <span>[% item_action | html %]</span>
251
                                                <span>[% item_action | html %]</span>
248
                                            [% END %]
252
                                            [% END %]
249
- 

Return to bug 32902