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

(-)a/Koha/Import/Record/Match.pm (+44 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
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Import::Record::Match - Koha Import Record Match 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 'ImportRecordMatch';
42
}
43
44
1;
(-)a/Koha/Import/Record/Matches.pm (+50 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 type
39
40
=cut
41
42
sub _type {
43
    return 'ImportRecordMatch';
44
}
45
46
sub object_class {
47
    return 'Koha::Import::Record::Match';
48
}
49
50
1;
(-)a/Koha/Schema/Result/ImportRecordMatch.pm (-1 / +6 lines)
Lines 72-77 __PACKAGE__->belongs_to( Link Here
72
# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-07-11 09:26:55
72
# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-07-11 09:26:55
73
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hJW36EeP+H8+0/Ij3iuIFw
73
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hJW36EeP+H8+0/Ij3iuIFw
74
74
75
sub koha_object_class {
76
    'Koha::Import::Record::Match';
77
}
78
sub koha_objects_class {
79
    'Koha::Import::Record::Matches';
80
}
75
81
76
# You can replace this text with custom code or comments, and it will be preserved on regeneration
77
1;
82
1;
(-)a/installer/data/mysql/atomicupdate/bug_26326.perl (+11 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
    NewVersion( $DBversion, 22785, "Add primary key to import_record_matches");
11
}
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 758-763 CREATE TABLE `import_record_matches` ( -- matches found when importing a batch o Link Here
758
  `import_record_id` int(11) NOT NULL, -- the id given to the imported bib record (import_records.import_record_id)
758
  `import_record_id` int(11) NOT NULL, -- the id given to the imported bib record (import_records.import_record_id)
759
  `candidate_match_id` int(11) NOT NULL, -- the biblio the imported record matches (biblio.biblionumber)
759
  `candidate_match_id` int(11) NOT NULL, -- the biblio the imported record matches (biblio.biblionumber)
760
  `score` int(11) NOT NULL default 0, -- the match score
760
  `score` int(11) NOT NULL default 0, -- the match score
761
  PRIMARY KEY (`import_record_id`,`candidate_match_id`),
761
  CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
762
  CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
762
             REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
763
             REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
763
  KEY `record_score` (`import_record_id`, `score`)
764
  KEY `record_score` (`import_record_id`, `score`)
(-)a/t/db_dependent/Koha/Import/Record/Matches.t (-1 / +47 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::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' });
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
$schema->storage->txn_rollback;
47

Return to bug 26326