--- /dev/null
+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;
--- /dev/null
+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;
use Koha::SearchEngine::Search;
use Koha::SearchEngine::QueryBuilder;
use Koha::Token;
+use Koha::Z3950Servers;
my $query = new CGI;
my $dbh = C4::Context->dbh;
}
-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(
use Koha::BiblioFrameworks;
use Koha::SearchEngine::Search;
use Koha::SearchEngine::QueryBuilder;
+use Koha::Z3950Servers;
my $input = new CGI;
};
}
-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(
--- /dev/null
+#!/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 <http://www.gnu.org/licenses>.
+
+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;