From 23d423365887311c29810bed2ca7718502189c87 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 19 Jan 2018 15:57:02 +0000 Subject: [PATCH] Bug 20047: Add Koha::Z3950Server Oject and use it to get server count To test: 1 - prove t/db_dependent/Koha/Z3950Servers.t 2 - Load cataloging and authority home pages 3 - Verify you can add form z395 on each page 4 - Delete all z3950 servers 5 - Viery option to add from Z3950 is removed on both pages Signed-off-by: Jesse Maseto Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- Koha/Z3950Server.pm | 46 ++++++++++++++++++++++ Koha/Z3950Servers.pm | 58 ++++++++++++++++++++++++++++ authorities/authorities-home.pl | 18 ++++----- cataloguing/addbooks.pl | 12 +----- t/db_dependent/Koha/Z3950Servers.t | 61 ++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 19 deletions(-) create mode 100644 Koha/Z3950Server.pm create mode 100644 Koha/Z3950Servers.pm create mode 100644 t/db_dependent/Koha/Z3950Servers.t diff --git a/Koha/Z3950Server.pm b/Koha/Z3950Server.pm new file mode 100644 index 0000000000..e06ef04483 --- /dev/null +++ b/Koha/Z3950Server.pm @@ -0,0 +1,46 @@ +package Koha::Z3950Server; + +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Z3950Server - Koha Z3950Server Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +Return type of Object relating to Schema ResultSet + +=cut + +sub _type { + return 'Z3950server'; +} + +1; diff --git a/Koha/Z3950Servers.pm b/Koha/Z3950Servers.pm new file mode 100644 index 0000000000..5cbf5f0cbb --- /dev/null +++ b/Koha/Z3950Servers.pm @@ -0,0 +1,58 @@ +package Koha::Z3950Servers; + +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Z3950Server; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Z3950Servers - Koha Z3950Server Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +Return type of object, relating to Schema ResultSet + +=cut + +sub _type { + return 'Z3950server'; +} + +=head3 object_class + +Return object class + +=cut + +sub object_class { + return 'Koha::Z3950Server'; +} + +1; diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 7c46794341..878c8d0bd5 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -37,6 +37,7 @@ use Koha::Authority::Types; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; use Koha::Token; +use Koha::Z3950Servers; my $query = new CGI; my $dbh = C4::Context->dbh; @@ -205,15 +206,14 @@ if ( $op eq '' ) { } -my $schema = Koha::Database->new()->schema(); -my $servers = $schema->resultset('Z3950server')->search( - { - recordtype => 'authority', - servertype => ['zed', 'sru'], - }, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator', - order_by => ['rank', 'servername'], - }, +my $servers = Koha::Z3950Servers->search( + { + recordtype => 'authority', + servertype => ['zed', 'sru'], + }, + { result_class => 'DBIx::Class::ResultClass::HashRefInflator', + order_by => ['rank', 'servername'], + }, ); $template->param( diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl index ae4d7acbde..fdbf7c7b39 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -37,6 +37,7 @@ use C4::Search; use Koha::BiblioFrameworks; use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; +use Koha::Z3950Servers; my $input = new CGI; @@ -133,16 +134,7 @@ for my $resultsbr (@resultsbr) { }; } -my $schema = Koha::Database->new()->schema(); -my $servers = $schema->resultset('Z3950server')->search( - { - recordtype => 'biblio', - servertype => ['zed', 'sru'], - }, - { result_class => 'DBIx::Class::ResultClass::HashRefInflator', - order_by => ['rank', 'servername'], - }, -); +my $servers = Koha::Z3950Servers->search(); my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); $template->param( diff --git a/t/db_dependent/Koha/Z3950Servers.t b/t/db_dependent/Koha/Z3950Servers.t new file mode 100644 index 0000000000..9714cb4599 --- /dev/null +++ b/t/db_dependent/Koha/Z3950Servers.t @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +# Copyright 2015 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 => 4; + +use Koha::Z3950Server; +use Koha::Z3950Servers; +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_z39s = Koha::Z3950Servers->search->count; +my $new_z39_1 = Koha::Z3950Server->new({ + host => 'my_host1.org', + port => '32', + db => 'db1', + servername => 'my_test_1', + servertype => 'zed', + recordtype => 'biblio', +})->store; +my $new_z39_2 = Koha::Z3950Server->new({ + host => 'my_host2.org', + port => '64', + db => 'db2', + servername => 'my_test_2', + servertype => 'zed', + recordtype => 'authority', +})->store; + +like( $new_z39_1->id, qr|^\d+$|, 'Adding a new z39 server should have set the id'); +is( Koha::Z3950Servers->search->count, $nb_of_z39s + 2, 'The 2 z39 servers should have been added' ); + +my $retrieved_z39_1 = Koha::Z3950Servers->find( $new_z39_1->id ); +is( $retrieved_z39_1->servername, $new_z39_1->servername, 'Find a z39 server by id should return the correct z39 server' ); + +$retrieved_z39_1->delete; +is( Koha::Z3950Servers->search->count, $nb_of_z39s + 1, 'Delete should have deleted the z39 server' ); + +$schema->storage->txn_rollback; -- 2.39.5