From ccb0ce027bb93d176100e0edf31779959d6b0bd6 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 12 Dec 2022 13:59:56 +0000 Subject: [PATCH] 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 Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi (cherry picked from commit f41f272ff087d65ed11d760e6c7c58818c3a24d4) Signed-off-by: Jacob O'Mara --- Koha/Import/Record/Auth.pm | 44 ++++++++++++++++ Koha/Import/Record/Auths.pm | 52 +++++++++++++++++++ .../data/mysql/atomicupdate/bug_32437.pl | 19 +++++++ installer/data/mysql/kohastructure.sql | 1 + t/db_dependent/Koha/Import/Record/Auths.t | 46 ++++++++++++++++ t/db_dependent/Koha/Import/Record/Biblios.t | 46 ++++++++++++++++ 6 files changed, 208 insertions(+) create mode 100644 Koha/Import/Record/Auth.pm create mode 100644 Koha/Import/Record/Auths.pm create mode 100755 installer/data/mysql/atomicupdate/bug_32437.pl create mode 100755 t/db_dependent/Koha/Import/Record/Auths.t create mode 100755 t/db_dependent/Koha/Import/Record/Biblios.t diff --git a/Koha/Import/Record/Auth.pm b/Koha/Import/Record/Auth.pm new file mode 100644 index 0000000000..beaab30eaf --- /dev/null +++ b/Koha/Import/Record/Auth.pm @@ -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 . + +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; diff --git a/Koha/Import/Record/Auths.pm b/Koha/Import/Record/Auths.pm new file mode 100644 index 0000000000..2a8f1b2970 --- /dev/null +++ b/Koha/Import/Record/Auths.pm @@ -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 . + +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; diff --git a/installer/data/mysql/atomicupdate/bug_32437.pl b/installer/data/mysql/atomicupdate/bug_32437.pl new file mode 100755 index 0000000000..6ff91391b9 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_32437.pl @@ -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"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 6211c5a622..34c4a0c877 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3281,6 +3281,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 diff --git a/t/db_dependent/Koha/Import/Record/Auths.t b/t/db_dependent/Koha/Import/Record/Auths.t new file mode 100755 index 0000000000..d992a41735 --- /dev/null +++ b/t/db_dependent/Koha/Import/Record/Auths.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 . + +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; diff --git a/t/db_dependent/Koha/Import/Record/Biblios.t b/t/db_dependent/Koha/Import/Record/Biblios.t new file mode 100755 index 0000000000..cfd0f71b9d --- /dev/null +++ b/t/db_dependent/Koha/Import/Record/Biblios.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 . + +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; -- 2.39.5