Bug 32437: Add Objects for ImportAuths

This patch:
1 - Adds an atomic update to add a primary key to import_auths table
2 - Adds objects for Koha::Import::Records::Auths
3 - Adds tests for import auth and biblio objects

Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Nick Clemens 2022-12-12 13:59:56 +00:00 committed by Tomas Cohen Arazi
parent b68a6b3297
commit f41f272ff0
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
6 changed files with 208 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package Koha::Import::Record::Auth;
# 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::Auth - Koha Import Record Authority Object class
=head1 API
=head2 Internal methods
=head3 _type
Returns name of corresponding DBIC resultset
=cut
sub _type {
return 'ImportAuth';
}
1;

View File

@ -0,0 +1,52 @@
package Koha::Import::Record::Auths;
# 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 Koha::Import::Record::Auth;
use base qw(Koha::Objects);
=head1 NAME
Koha::Import::Record::Auths - Koha Import Record Auths Object set class
=head1 API
=head2 Class Methods
=cut
=head3 type
=cut
sub _type {
return 'ImportAuth';
}
=head3 object_class
Koha::Object class
=cut
sub object_class {
return 'Koha::Import::Record::Auth';
}
1;

View File

@ -0,0 +1,19 @@
use Modern::Perl;
return {
bug_number => "32437",
description => "Add primary key to import_auths tables",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
if( !primary_key_exists('import_auths') ){
$dbh->do(q{ALTER TABLE import_auths ADD PRIMARY KEY (import_record_id);});
say $out "Added PRIMARY KEY ON import_record_id to import_authd table";
} elsif( !primary_key_exists('import_auths','import_record_id') ){
say $out "Found an existing PRIMARY KEY on import_auths table";
say $out "You must delete this key and replace it with a key on import_record_id";
} else {
say $out "PRIMARY KEY import_record_id on import_auths already exists";
}
},
};

View File

@ -3285,6 +3285,7 @@ CREATE TABLE `import_auths` (
`control_number` varchar(25) DEFAULT NULL,
`authorized_heading` varchar(128) DEFAULT NULL,
`original_source` varchar(25) DEFAULT NULL,
PRIMARY KEY (`import_record_id`),
KEY `import_auths_ibfk_1` (`import_record_id`),
KEY `matched_authid` (`matched_authid`),
CONSTRAINT `import_auths_ibfk_1` FOREIGN KEY (`import_record_id`) REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE

View File

@ -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::Record::Auths;
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_record_auths = Koha::Import::Record::Auths->search->count;
my $record_auth_1 = $builder->build({ source => 'ImportAuth' });
my $record_auth_2 = $builder->build({ source => 'ImportAuth' });
is( Koha::Import::Record::Auths->search->count, $nb_of_record_auths + 2, 'The 2 record auths should have been added' );
my $retrieved_record_auth_1 = Koha::Import::Record::Auths->search({ import_record_id => $record_auth_1->{import_record_id}})->next;
is_deeply( $retrieved_record_auth_1->unblessed, $record_auth_1, 'Find a record auth by import record id should return the correct record auth' );
$retrieved_record_auth_1->delete;
is( Koha::Import::Record::Auths->search->count, $nb_of_record_auths + 1, 'Delete should have deleted the record auth' );
$schema->storage->txn_rollback;

View File

@ -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::Record::Biblios;
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_record_biblios = Koha::Import::Record::Biblios->search->count;
my $record_biblio_1 = $builder->build({ source => 'ImportBiblio' });
my $record_biblio_2 = $builder->build({ source => 'ImportBiblio' });
is( Koha::Import::Record::Biblios->search->count, $nb_of_record_biblios + 2, 'The 2 record biblios should have been added' );
my $retrieved_record_biblio_1 = Koha::Import::Record::Biblios->search({ import_record_id => $record_biblio_1->{import_record_id}})->next;
is_deeply( $retrieved_record_biblio_1->unblessed, $record_biblio_1, 'Find a record biblio by import record id should return the correct record biblio' );
$retrieved_record_biblio_1->delete;
is( Koha::Import::Record::Biblios->search->count, $nb_of_record_biblios + 1, 'Delete should have deleted the record biblio' );
$schema->storage->txn_rollback;