From fdf6a82746e2b430048997c04cbb44af2c2c0f92 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 15 Sep 2022 12:42:56 +0000 Subject: [PATCH] Bug 31569: DB update and objects Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer --- Koha/Import/Record.pm | 15 +++++ Koha/Import/Record/Biblio.pm | 44 +++++++++++++++ Koha/Import/Record/Biblios.pm | 56 +++++++++++++++++++ .../data/mysql/atomicupdate/bug_31569.pl | 14 +++++ installer/data/mysql/kohastructure.sql | 1 + 5 files changed, 130 insertions(+) create mode 100644 Koha/Import/Record/Biblio.pm create mode 100644 Koha/Import/Record/Biblios.pm create mode 100755 installer/data/mysql/atomicupdate/bug_31569.pl diff --git a/Koha/Import/Record.pm b/Koha/Import/Record.pm index 49a7710e23..a1fedab5fe 100644 --- a/Koha/Import/Record.pm +++ b/Koha/Import/Record.pm @@ -22,6 +22,7 @@ use MARC::Record; use C4::Context; use Koha::Database; +use Koha::Import::Record::Biblios; use base qw(Koha::Object); @@ -56,6 +57,20 @@ sub get_marc_record { return $record; } +=head3 import_biblio + +Returns the import biblio object for this import record + + my $import_biblio = $import_record->import_biblio() + +=cut + +sub import_biblio { + my ( $self ) = @_; + my $import_biblio_rs = $self->_result->import_biblio; + return Koha::Import::Record::Biblio->_new_from_dbic( $import_biblio_rs ); +} + =head2 Internal methods =head3 _type diff --git a/Koha/Import/Record/Biblio.pm b/Koha/Import/Record/Biblio.pm new file mode 100644 index 0000000000..16d3f0eeba --- /dev/null +++ b/Koha/Import/Record/Biblio.pm @@ -0,0 +1,44 @@ +package Koha::Import::Record::Biblio; + +# 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::Biblio - Koha Import Record Biblio Object class + +=head1 API + +=head2 Internal methods + +=head3 _type + +Returns name of corresponding DBIC resultset + +=cut + +sub _type { + return 'ImportBiblio'; +} + +1; diff --git a/Koha/Import/Record/Biblios.pm b/Koha/Import/Record/Biblios.pm new file mode 100644 index 0000000000..36d725f589 --- /dev/null +++ b/Koha/Import/Record/Biblios.pm @@ -0,0 +1,56 @@ +package Koha::Import::Record::Biblios; + +# 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 Koha::Import::Record::Biblio; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Import::Record::Biblios - Koha Import Record Biblios Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'ImportBiblio'; +} + +=head3 object_class + +Koha::Object class + +=cut + +sub object_class { + return 'Koha::Import::Record::Biblio'; +} + +1; diff --git a/installer/data/mysql/atomicupdate/bug_31569.pl b/installer/data/mysql/atomicupdate/bug_31569.pl new file mode 100755 index 0000000000..c3d98c61c0 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_31569.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "31569", + description => "Add primary key for import_biblios", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + unless( primary_key_exists('import_biblios') ){ + $dbh->do(q{ALTER TABLE import_biblios ADD PRIMARY KEY (import_record_id)}); + say $out "Added primary key to import_biblios table"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 7025f9bbf9..3d8a5efea2 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3052,6 +3052,7 @@ CREATE TABLE `import_biblios` ( `isbn` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, `issn` longtext COLLATE utf8mb4_unicode_ci DEFAULT NULL, `has_items` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`import_record_id`), KEY `import_biblios_ibfk_1` (`import_record_id`), KEY `matched_biblionumber` (`matched_biblionumber`), KEY `title` (`title`(191)), -- 2.30.2