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

(-)a/Koha/Import/Record.pm (+44 lines)
Line 0 Link Here
1
package Koha::Import::Record;
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 - Koha Import Record Object class
29
30
=head1 API
31
32
=head2 Class methods
33
34
=head2 Internal methods
35
36
=head3 _type
37
38
=cut
39
40
sub _type {
41
    return 'ImportRecord';
42
}
43
44
1;
(-)a/Koha/Import/Record/Match.pm (+60 lines)
Line 0 Link Here
1
package Koha::Import::Record::Match;
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
use Koha::Import::Record;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::Import::Record::Match - Koha Import Record Match Object class
30
31
=head1 API
32
33
=head2 Class methods
34
35
=head3 import_record
36
37
my $import_record = $match->import_record;
38
39
Return the import record of this match
40
41
=cut
42
43
sub import_record {
44
    my ( $self ) = @_;
45
    my $record_rs = $self->_result->import_record;
46
    return Koha::Import::Record->_new_from_dbic( $record_rs );
47
}
48
49
50
=head2 Internal methods
51
52
=head3 _type
53
54
=cut
55
56
sub _type {
57
    return 'ImportRecordMatch';
58
}
59
60
1;
(-)a/Koha/Import/Record/Matches.pm (+71 lines)
Line 0 Link Here
1
package Koha::Import::Record::Matches;
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::Match;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Import::Record::Matches - Koha Import Record Matches Object set class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 unset_chosen
39
40
Koha:Import::Record::Matches->search->unset_chosen();
41
42
Unselect all candidates as matches for the current resultset
43
44
=cut
45
46
sub unset_chosen {
47
    my ( $self ) = @_;
48
    while ( my $match = $self->next ){
49
        $match->chosen(0)->store;
50
    }
51
}
52
53
=head3 _type
54
55
=cut
56
57
sub _type {
58
    return 'ImportRecordMatch';
59
}
60
61
=head3 object_class
62
63
Koha::Object class
64
65
=cut
66
67
sub object_class {
68
    return 'Koha::Import::Record::Match';
69
}
70
71
1;
(-)a/Koha/Import/Records.pm (+56 lines)
Line 0 Link Here
1
package Koha::Import::Records;
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;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Import::Records - Koha Import Record 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 'ImportRecord';
44
}
45
46
=head3 object_class
47
48
Koha::Object class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Import::Record';
54
}
55
56
1;
(-)a/Koha/Schema/Result/ImportRecord.pm (+7 lines)
Lines 265-270 __PACKAGE__->has_many( Link Here
265
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-18 10:50:48
265
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-18 10:50:48
266
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bqIAQzhgioWtBWU8zFdtjw
266
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bqIAQzhgioWtBWU8zFdtjw
267
267
268
sub koha_object_class {
269
    'Koha::Import::Record';
270
}
271
sub koha_objects_class {
272
    'Koha::Import::Records';
273
}
274
268
275
269
# You can replace this text with custom content, and it will be preserved on regeneration
276
# You can replace this text with custom content, and it will be preserved on regeneration
270
1;
277
1;
(-)a/Koha/Schema/Result/ImportRecordMatch.pm (-1 / +6 lines)
Lines 78-83 __PACKAGE__->belongs_to( Link Here
78
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
78
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
79
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kWU/SGWvZBBvVwEvDysrtA
79
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kWU/SGWvZBBvVwEvDysrtA
80
80
81
sub koha_object_class {
82
    'Koha::Import::Record::Match';
83
}
84
sub koha_objects_class {
85
    'Koha::Import::Record::Matches';
86
}
81
87
82
# You can replace this text with custom code or comments, and it will be preserved on regeneration
83
1;
88
1;
(-)a/installer/data/mysql/atomicupdate/bug_26326.perl (+12 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    unless(
4
        primary_key_exists('import_record_matches','import_record_id') &&
5
        primary_key_exists('import_record_matches','candidate_match_id')
6
    ){
7
        $dbh->do( "ALTER TABLE import_record_matches DROP PRIMARY KEY" );
8
        $dbh->do( "ALTER TABLE import_record_matches ADD PRIMARY KEY (import_record_id,candidate_match_id)" );
9
    }
10
11
    NewVersion( $DBversion, 26326, "Add primary key to import_record_matches");
12
}
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2901-2906 CREATE TABLE `import_record_matches` ( Link Here
2901
  `import_record_id` int(11) NOT NULL COMMENT 'the id given to the imported bib record (import_records.import_record_id)',
2901
  `import_record_id` int(11) NOT NULL COMMENT 'the id given to the imported bib record (import_records.import_record_id)',
2902
  `candidate_match_id` int(11) NOT NULL COMMENT 'the biblio the imported record matches (biblio.biblionumber)',
2902
  `candidate_match_id` int(11) NOT NULL COMMENT 'the biblio the imported record matches (biblio.biblionumber)',
2903
  `score` int(11) NOT NULL DEFAULT 0 COMMENT 'the match score',
2903
  `score` int(11) NOT NULL DEFAULT 0 COMMENT 'the match score',
2904
  PRIMARY KEY (`import_record_id`,`candidate_match_id`),
2904
  KEY `record_score` (`import_record_id`,`score`),
2905
  KEY `record_score` (`import_record_id`,`score`),
2905
  CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`) REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE
2906
  CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`) REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE
2906
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
2907
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
(-)a/t/db_dependent/Koha/Import/Record/Matches.t (+51 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 => 5;
23
24
use Koha::Import::Record::Matches;
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_matches = Koha::Import::Record::Matches->search->count;
34
35
my $match_1 = $builder->build({ source => 'ImportRecordMatch', });
36
my $match_2 = $builder->build({ source => 'ImportRecordMatch', value => { import_record_id => $match_1->{import_record_id} } });
37
38
is( Koha::Import::Record::Matches->search->count, $nb_of_matches + 2, 'The 2 matches should have been added' );
39
40
my $retrieved_match_1 = Koha::Import::Record::Matches->search({ import_record_id => $match_1->{import_record_id}, candidate_match_id => $match_1->{candidate_match_id} })->next;
41
is_deeply( $retrieved_match_1->unblessed, $match_1, 'Find a match by import record id and candidate should return the correct match' );
42
43
$retrieved_match_1->delete;
44
is( Koha::Import::Record::Matches->search->count, $nb_of_matches + 1, 'Delete should have deleted the match' );
45
46
my $retrieved_match_2 = Koha::Import::Record::Matches->search({ import_record_id => $match_2->{import_record_id}, candidate_match_id => $match_2->{candidate_match_id} })->next;
47
my $import_record = $retrieved_match_2->import_record;
48
is( ref($import_record), 'Koha::Import::Record', "import_record has the correct class");
49
is( $import_record->import_record_id, $retrieved_match_2->import_record_id, "We have the right record");
50
51
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Import/Records.t (-1 / +46 lines)
Line 0 Link Here
0
- 
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::Records;
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_records = Koha::Import::Records->search->count;
34
35
my $record_1 = $builder->build({ source => 'ImportRecord' });
36
my $record_2 = $builder->build({ source => 'ImportRecord' });
37
38
is( Koha::Import::Records->search->count, $nb_of_records + 2, 'The 2 records should have been added' );
39
40
my $retrieved_record_1 = Koha::Import::Records->search({ import_record_id => $record_1->{import_record_id}})->next;
41
is_deeply( $retrieved_record_1->unblessed, $record_1, 'Find a record by import record id should return the correct record' );
42
43
$retrieved_record_1->delete;
44
is( Koha::Import::Records->search->count, $nb_of_records + 1, 'Delete should have deleted the record' );
45
46
$schema->storage->txn_rollback;

Return to bug 26326