From 13ab1707af23e2be37a929c93c920fe29da623e9 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Wed, 10 Jul 2024 14:06:15 +0000 Subject: [PATCH] Bug 35659: (QA follow-up): Auth unit tests & dbrev Add unit tests for authorities and deletion Fix dbrev and kohastructure discrepancies Signed-off-by: Victor Grousset/tuxayo Signed-off-by: David Cook Sponsored-by: Association KohaLa - https://koha-fr.org/ --- Koha/Import/OAI/Authorities.pm | 2 +- Koha/Import/OAI/Authority.pm | 2 +- Koha/OAI/Client/Harvester.pm | 3 - admin/oai_servers.pl | 6 +- .../data/mysql/atomicupdate/Bug-35659.pl | 6 +- installer/data/mysql/kohastructure.sql | 12 +- .../prog/en/modules/admin/oai_servers.tt | 16 +- t/db_dependent/Koha/OAIHarvester.t | 153 +++++++++++++++++- 8 files changed, 170 insertions(+), 30 deletions(-) diff --git a/Koha/Import/OAI/Authorities.pm b/Koha/Import/OAI/Authorities.pm index c66daa6816..cdff207854 100644 --- a/Koha/Import/OAI/Authorities.pm +++ b/Koha/Import/OAI/Authorities.pm @@ -36,7 +36,7 @@ This object represents a collection of OAI-PMH records being imported as authori =cut sub _type { - return 'ImportOAIAuthority'; + return 'ImportOaiAuthority'; } =head3 object_class diff --git a/Koha/Import/OAI/Authority.pm b/Koha/Import/OAI/Authority.pm index 8f44b235f4..f4e3a0d31f 100644 --- a/Koha/Import/OAI/Authority.pm +++ b/Koha/Import/OAI/Authority.pm @@ -35,7 +35,7 @@ This object represents an OAI-PMH record being imported as an authority =cut sub _type { - return 'ImportOAIAuthority'; + return 'ImportOaiAuthority'; } 1; diff --git a/Koha/OAI/Client/Harvester.pm b/Koha/OAI/Client/Harvester.pm index 462f56e06f..779632824d 100644 --- a/Koha/OAI/Client/Harvester.pm +++ b/Koha/OAI/Client/Harvester.pm @@ -32,7 +32,6 @@ use open qw( :std :utf8 ); use C4::Biblio qw( AddBiblio GetFrameworkCode ModBiblio DelBiblio ); use C4::AuthoritiesMarc qw (AddAuthority GuessAuthTypeCode ModAuthority DelAuthority ); -use C4::Log qw( cronlogaction ); use HTTP::OAI; use HTTP::OAI::Metadata::OAI_DC; use Koha::DateUtils qw( dt_from_string ); @@ -276,14 +275,12 @@ sub processRecord { "Record " . $oai_record->identifier . " not deleted, biblionumber: $biblionumber ($error)" ); $status = 'in_error'; } else { - $imported_record->delete; $self->printlog( "Record " . $oai_record->identifier . " deleted, biblionumber: $biblionumber" ); $status = 'deleted'; } } else { my $authid = $imported_record->authid; DelAuthority( { authid => $authid } ); - $imported_record->delete; $self->printlog( "Record " . $oai_record->identifier . " deleted, authid: $authid" ); $status = 'deleted'; } diff --git a/admin/oai_servers.pl b/admin/oai_servers.pl index af35b14110..3edb2e118c 100755 --- a/admin/oai_servers.pl +++ b/admin/oai_servers.pl @@ -83,7 +83,7 @@ if ( $op eq 'cud-delete_confirmed' && $id ) { } } elsif ( $op eq 'search' ) { - #use searchfield only in remaining operations + # use searchfield only in remaining operations $searchfield = $input->param('searchfield') || ''; } @@ -108,11 +108,11 @@ output_html_with_http_headers $input, $cookie, $template->output; # End of main code -sub server_search { #find server(s) by id or name +sub server_search { # find server(s) by id or name my ( $schema, $id, $searchstring ) = @_; return Koha::OAIServers->search( - $id ? { id => $id } : { servername => { like => $searchstring . '%' } }, + $id ? { oai_server_id => $id } : { servername => { like => $searchstring . '%' } }, )->unblessed; } diff --git a/installer/data/mysql/atomicupdate/Bug-35659.pl b/installer/data/mysql/atomicupdate/Bug-35659.pl index c637027d45..584d5c4869 100755 --- a/installer/data/mysql/atomicupdate/Bug-35659.pl +++ b/installer/data/mysql/atomicupdate/Bug-35659.pl @@ -16,7 +16,7 @@ return { `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format', `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records', `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results', - PRIMARY KEY (`id`) + PRIMARY KEY (`oai_server_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; } ); @@ -32,7 +32,7 @@ return { `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), + PRIMARY KEY (`import_oai_biblio_id`), KEY biblionumber (biblionumber), CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -49,7 +49,7 @@ return { `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), + PRIMARY KEY (`import_oai_authority_id`), KEY authid (authid), CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e583980be0..03c88982ee 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4864,14 +4864,14 @@ DROP TABLE IF EXISTS `oai_servers`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `oai_servers` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', + `oai_server_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', `endpoint` varchar(255) NOT NULL COMMENT 'OAI endpoint (host + port + path)', `oai_set` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', `servername` longtext NOT NULL COMMENT 'name given to the target by the library', `dataformat` enum('oai_dc','marc-xml', 'marcxml') NOT NULL DEFAULT 'oai_dc' COMMENT 'data format', `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'server contains bibliographic or authority records', `add_xslt` longtext DEFAULT NULL COMMENT 'zero or more paths to XSLT files to be processed on the search results', - PRIMARY KEY (`id`) + PRIMARY KEY (`oai_server_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- @@ -4882,14 +4882,14 @@ DROP TABLE IF EXISTS `import_oai_biblios`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `import_oai_biblios` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', + `import_oai_biblio_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', `biblionumber` int(11) NOT NULL COMMENT 'unique identifier assigned to each koha record', `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier', `repository` varchar(255) NOT NULL COMMENT 'OAI repository', `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), + PRIMARY KEY (import_oai_biblio_id), KEY biblionumber (biblionumber), CONSTRAINT FK_import_oai_biblios_1 FOREIGN KEY (biblionumber) REFERENCES biblio (biblionumber) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; @@ -4902,14 +4902,14 @@ DROP TABLE IF EXISTS `import_oai_authorities`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `import_oai_authorities` ( - `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', + `import_oai_authority_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier assigned by Koha', `authid` bigint(20) unsigned NOT NULL COMMENT 'unique identifier assigned to each koha record', `identifier` varchar(255) NOT NULL COMMENT 'OAI record identifier', `repository` varchar(255) NOT NULL COMMENT 'OAI repository', `recordtype` enum('authority','biblio') NOT NULL DEFAULT 'biblio' COMMENT 'is the record bibliographic or authority', `datestamp` varchar(255) DEFAULT NULL COMMENT 'OAI set to harvest', `last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (id), + PRIMARY KEY (import_oai_authority_id), KEY authid (authid), CONSTRAINT FK_import_oai_authorities_1 FOREIGN KEY (authid) REFERENCES auth_header (authid) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_servers.tt index 07751b636e..8603e83ccc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_servers.tt @@ -70,7 +70,7 @@ [% INCLUDE 'csrf-token.inc' %] [% IF op == 'edit' %]

Modify OAI repository

- + [% ELSE %]

New OAI repository

[% END %] @@ -138,8 +138,8 @@ [% FOREACH loo IN loop %] - [% loo.id | html %] - [% loo.servername | html %][% loo.endpoint | html %][% loo.oai_set | html %] + [% loo.oai_server_id | html %] + [% loo.servername | html %][% loo.endpoint | html %][% loo.oai_set | html %] [% loo.dataformat | html %] [% IF ( loo.recordtype == 'biblio' ) %] Bibliographic @@ -153,14 +153,14 @@ Actions