Browse Source
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
10 changed files with 339 additions and 1 deletions
@ -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; |
@ -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; |
@ -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; |
@ -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; |
@ -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"); |
|||
} |
@ -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; |
@ -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…
Reference in new issue