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

(-)a/C4/ImportBatch.pm (-6 / +10 lines)
Lines 770-782 sub BatchCommitItems { Link Here
770
        my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} });
770
        my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} });
771
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
771
        my $duplicate_itemnumber = exists( $item->{'itemnumber'} );
772
772
773
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?");
773
        my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?");
774
        if ( $action eq "replace" && $duplicate_itemnumber ) {
774
        if ( $action eq "replace" && $duplicate_itemnumber ) {
775
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
775
            # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying
776
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
776
            ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} );
777
            $updsth->bind_param( 1, 'imported' );
777
            $updsth->bind_param( 1, 'imported' );
778
            $updsth->bind_param( 2, $item->{itemnumber} );
778
            $updsth->bind_param( 2, $item->{itemnumber} );
779
            $updsth->bind_param( 3, $row->{'import_items_id'} );
779
            $updsth->bind_param( 3, undef );
780
            $updsth->bind_param( 4, $row->{'import_items_id'} );
780
            $updsth->execute();
781
            $updsth->execute();
781
            $updsth->finish();
782
            $updsth->finish();
782
            $num_items_replaced++;
783
            $num_items_replaced++;
Lines 785-798 sub BatchCommitItems { Link Here
785
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
786
            ModItemFromMarc( $item_marc, $biblionumber, $itemnumber );
786
            $updsth->bind_param( 1, 'imported' );
787
            $updsth->bind_param( 1, 'imported' );
787
            $updsth->bind_param( 2, $item->{itemnumber} );
788
            $updsth->bind_param( 2, $item->{itemnumber} );
788
            $updsth->bind_param( 3, $row->{'import_items_id'} );
789
            $updsth->bind_param( 3, undef );
790
            $updsth->bind_param( 4, $row->{'import_items_id'} );
789
            $updsth->execute();
791
            $updsth->execute();
790
            $updsth->finish();
792
            $updsth->finish();
791
            $num_items_replaced++;
793
            $num_items_replaced++;
792
        } elsif ($duplicate_barcode) {
794
        } elsif ($duplicate_barcode) {
793
            $updsth->bind_param( 1, 'error' );
795
            $updsth->bind_param( 1, 'error' );
794
            $updsth->bind_param( 2, 'duplicate item barcode' );
796
            $updsth->bind_param( 2, undef );
795
            $updsth->bind_param( 3, $row->{'import_items_id'} );
797
            $updsth->bind_param( 3, 'duplicate item barcode' );
798
            $updsth->bind_param( 4, $row->{'import_items_id'} );
796
            $updsth->execute();
799
            $updsth->execute();
797
            $num_items_errored++;
800
            $num_items_errored++;
798
        } else {
801
        } else {
Lines 804-810 sub BatchCommitItems { Link Here
804
            if( $itemnumber ) {
807
            if( $itemnumber ) {
805
                $updsth->bind_param( 1, 'imported' );
808
                $updsth->bind_param( 1, 'imported' );
806
                $updsth->bind_param( 2, $itemnumber );
809
                $updsth->bind_param( 2, $itemnumber );
807
                $updsth->bind_param( 3, $row->{'import_items_id'} );
810
                $updsth->bind_param( 3, undef );
811
                $updsth->bind_param( 4, $row->{'import_items_id'} );
808
                $updsth->execute();
812
                $updsth->execute();
809
                $updsth->finish();
813
                $updsth->finish();
810
                $num_items_added++;
814
                $num_items_added++;
(-)a/Koha/Import/Record/Item.pm (+44 lines)
Line 0 Link Here
1
package Koha::Import::Record::Item;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Import::Record::Item - Koha Import Record Item Object class
29
30
=head1 API
31
32
=head2 Internal methods
33
34
=head3 _type
35
36
Returns name of corresponding DBIC resultset
37
38
=cut
39
40
sub _type {
41
    return 'ImportItem';
42
}
43
44
1;
(-)a/Koha/Import/Record/Items.pm (+56 lines)
Line 0 Link Here
1
package Koha::Import::Record::Items;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Import::Record::Item;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Import::Record::Items - Koha Import Record Items Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub _type {
43
    return 'ImportItem';
44
}
45
46
=head3 object_class
47
48
Koha::Object class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Import::Record::Item';
54
}
55
56
1;
(-)a/Koha/Schema/Result/ImportItem.pm (+6 lines)
Lines 120-125 __PACKAGE__->belongs_to( Link Here
120
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
120
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
121
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GaUyqPnOhETQO8YuuKvfNQ
121
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GaUyqPnOhETQO8YuuKvfNQ
122
122
123
sub koha_object_class {
124
    'Koha::Import::Record::Item';
125
}
126
sub koha_objects_class {
127
    'Koha::Import::Record::Items';
128
}
123
129
124
# You can replace this text with custom content, and it will be preserved on regeneration
130
# You can replace this text with custom content, and it will be preserved on regeneration
125
1;
131
1;
(-)a/t/db_dependent/Koha/Import/Record/Items.t (+46 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2020 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 3;
23
24
use Koha::Import::Record::Items;
25
use Koha::Database;
26
27
use t::lib::TestBuilder;
28
29
my $schema = Koha::Database->new->schema;
30
$schema->storage->txn_begin;
31
32
my $builder = t::lib::TestBuilder->new;
33
my $nb_of_record_items = Koha::Import::Record::Items->search->count;
34
35
my $record_item_1 = $builder->build({ source => 'ImportItem' });
36
my $record_item_2 = $builder->build({ source => 'ImportItem' });
37
38
is( Koha::Import::Record::Items->search->count, $nb_of_record_items + 2, 'The 2 record items should have been added' );
39
40
my $retrieved_record_item_1 = Koha::Import::Record::Items->search({ import_items_id => $record_item_1->{import_items_id}})->next;
41
is_deeply( $retrieved_record_item_1->unblessed, $record_item_1, 'Find a record item by import items id should return the correct record item' );
42
43
$retrieved_record_item_1->delete;
44
is( Koha::Import::Record::Items->search->count, $nb_of_record_items + 1, 'Delete should have deleted the record item' );
45
46
$schema->storage->txn_rollback;
(-)a/t/lib/TestBuilder.pm (-1 / +4 lines)
Lines 605-610 sub _gen_default_values { Link Here
605
            issue_id => undef, # It should be a FK but we removed it
605
            issue_id => undef, # It should be a FK but we removed it
606
                               # We don't want to generate a random value
606
                               # We don't want to generate a random value
607
        },
607
        },
608
        ImportItem => {
609
            status => 'staged',
610
            import_error => undef
611
        },
608
    };
612
    };
609
}
613
}
610
614
611
- 

Return to bug 30830