Browse Source

Bug 26326: Add Koha Objects for Import Records and Import Record Matches

To test:
1 - Apply patches
2 - Update database
3 - Generate schema files (dbic)
4 - prove -v t/db_dependent/Koha/Import/Records.t
5 - prove -v t/db_dependent/Koha/Import/Record/Matches.t

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

JD Amended patch: remove unused unset_chosen method

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.11.x
Nick Clemens 4 years ago
committed by Jonathan Druart
parent
commit
a78306e63f
  1. 44
      Koha/Import/Record.pm
  2. 60
      Koha/Import/Record/Match.pm
  3. 56
      Koha/Import/Record/Matches.pm
  4. 56
      Koha/Import/Records.pm
  5. 7
      Koha/Schema/Result/ImportRecord.pm
  6. 7
      Koha/Schema/Result/ImportRecordMatch.pm
  7. 12
      installer/data/mysql/atomicupdate/bug_26326.perl
  8. 1
      installer/data/mysql/kohastructure.sql
  9. 51
      t/db_dependent/Koha/Import/Record/Matches.t
  10. 46
      t/db_dependent/Koha/Import/Records.t

44
Koha/Import/Record.pm

@ -0,0 +1,44 @@
package Koha::Import::Record;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Carp;
use Koha::Database;
use base qw(Koha::Object);
=head1 NAME
Koha::Import::Record - Koha Import Record Object class
=head1 API
=head2 Class methods
=head2 Internal methods
=head3 _type
=cut
sub _type {
return 'ImportRecord';
}
1;

60
Koha/Import/Record/Match.pm

@ -0,0 +1,60 @@
package Koha::Import::Record::Match;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Carp;
use Koha::Database;
use Koha::Import::Record;
use base qw(Koha::Object);
=head1 NAME
Koha::Import::Record::Match - Koha Import Record Match Object class
=head1 API
=head2 Class methods
=head3 import_record
my $import_record = $match->import_record;
Return the import record of this match
=cut
sub import_record {
my ( $self ) = @_;
my $record_rs = $self->_result->import_record;
return Koha::Import::Record->_new_from_dbic( $record_rs );
}
=head2 Internal methods
=head3 _type
=cut
sub _type {
return 'ImportRecordMatch';
}
1;

56
Koha/Import/Record/Matches.pm

@ -0,0 +1,56 @@
package Koha::Import::Record::Matches;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Carp;
use Koha::Database;
use Koha::Import::Record::Match;
use base qw(Koha::Objects);
=head1 NAME
Koha::Import::Record::Matches - Koha Import Record Matches Object set class
=head1 API
=head2 Class Methods
=cut
=head3 _type
=cut
sub _type {
return 'ImportRecordMatch';
}
=head3 object_class
Koha::Object class
=cut
sub object_class {
return 'Koha::Import::Record::Match';
}
1;

56
Koha/Import/Records.pm

@ -0,0 +1,56 @@
package Koha::Import::Records;
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Carp;
use Koha::Database;
use Koha::Import::Record;
use base qw(Koha::Objects);
=head1 NAME
Koha::Import::Records - Koha Import Record Object set class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub _type {
return 'ImportRecord';
}
=head3 object_class
Koha::Object class
=cut
sub object_class {
return 'Koha::Import::Record';
}
1;

7
Koha/Schema/Result/ImportRecord.pm

@ -265,6 +265,13 @@ __PACKAGE__->has_many(
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-04-18 10:50:48
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:bqIAQzhgioWtBWU8zFdtjw
sub koha_object_class {
'Koha::Import::Record';
}
sub koha_objects_class {
'Koha::Import::Records';
}
# You can replace this text with custom content, and it will be preserved on regeneration
1;

7
Koha/Schema/Result/ImportRecordMatch.pm

@ -78,6 +78,11 @@ __PACKAGE__->belongs_to(
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:kWU/SGWvZBBvVwEvDysrtA
sub koha_object_class {
'Koha::Import::Record::Match';
}
sub koha_objects_class {
'Koha::Import::Record::Matches';
}
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1;

12
installer/data/mysql/atomicupdate/bug_26326.perl

@ -0,0 +1,12 @@
$DBversion = 'XXX';
if( CheckVersion( $DBversion ) ) {
unless(
primary_key_exists('import_record_matches','import_record_id') &&
primary_key_exists('import_record_matches','candidate_match_id')
){
$dbh->do( "ALTER TABLE import_record_matches DROP PRIMARY KEY" );
$dbh->do( "ALTER TABLE import_record_matches ADD PRIMARY KEY (import_record_id,candidate_match_id)" );
}
NewVersion( $DBversion, 26326, "Add primary key to import_record_matches");
}

1
installer/data/mysql/kohastructure.sql

@ -2902,6 +2902,7 @@ CREATE TABLE `import_record_matches` (
`import_record_id` int(11) NOT NULL COMMENT 'the id given to the imported bib record (import_records.import_record_id)',
`candidate_match_id` int(11) NOT NULL COMMENT 'the biblio the imported record matches (biblio.biblionumber)',
`score` int(11) NOT NULL DEFAULT 0 COMMENT 'the match score',
PRIMARY KEY (`import_record_id`,`candidate_match_id`),
KEY `record_score` (`import_record_id`,`score`),
CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`) REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

51
t/db_dependent/Koha/Import/Record/Matches.t

@ -0,0 +1,51 @@
#!/usr/bin/perl
# Copyright 2020 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 5;
use Koha::Import::Record::Matches;
use Koha::Database;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $nb_of_matches = Koha::Import::Record::Matches->search->count;
my $match_1 = $builder->build({ source => 'ImportRecordMatch', });
my $match_2 = $builder->build({ source => 'ImportRecordMatch', value => { import_record_id => $match_1->{import_record_id} } });
is( Koha::Import::Record::Matches->search->count, $nb_of_matches + 2, 'The 2 matches should have been added' );
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;
is_deeply( $retrieved_match_1->unblessed, $match_1, 'Find a match by import record id and candidate should return the correct match' );
$retrieved_match_1->delete;
is( Koha::Import::Record::Matches->search->count, $nb_of_matches + 1, 'Delete should have deleted the match' );
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;
my $import_record = $retrieved_match_2->import_record;
is( ref($import_record), 'Koha::Import::Record', "import_record has the correct class");
is( $import_record->import_record_id, $retrieved_match_2->import_record_id, "We have the right record");
$schema->storage->txn_rollback;

46
t/db_dependent/Koha/Import/Records.t

@ -0,0 +1,46 @@
#!/usr/bin/perl
# Copyright 2020 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 3;
use Koha::Import::Records;
use Koha::Database;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $builder = t::lib::TestBuilder->new;
my $nb_of_records = Koha::Import::Records->search->count;
my $record_1 = $builder->build({ source => 'ImportRecord' });
my $record_2 = $builder->build({ source => 'ImportRecord' });
is( Koha::Import::Records->search->count, $nb_of_records + 2, 'The 2 records should have been added' );
my $retrieved_record_1 = Koha::Import::Records->search({ import_record_id => $record_1->{import_record_id}})->next;
is_deeply( $retrieved_record_1->unblessed, $record_1, 'Find a record by import record id should return the correct record' );
$retrieved_record_1->delete;
is( Koha::Import::Records->search->count, $nb_of_records + 1, 'Delete should have deleted the record' );
$schema->storage->txn_rollback;
Loading…
Cancel
Save