From 08b7061c7f0104dedaff1081b0afba4b1ee63d2b Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Wed, 21 Nov 2018 16:20:33 +0200 Subject: [PATCH] Bug 13937: Fix issues found in QA --- C4/Installer/PerlDependencies.pm | 5 -- Koha/Z3950Responder.pm | 8 +-- Koha/Z3950Responder/Session.pm | 9 ++-- misc/bin/koha-zebra-ctl-oma.sh | 88 ++++++++++++++++++++++++++++++++ misc/z3950_responder.pl | 9 +++- t/Koha/Z3950responder.t | 23 ++------- 6 files changed, 108 insertions(+), 34 deletions(-) create mode 100755 misc/bin/koha-zebra-ctl-oma.sh diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index c9b6fefc84..323713aa5b 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -893,11 +893,6 @@ our $PERL_DEPS = { required => '1', min_ver => '0.37', }, - 'Path::Tiny' => { - usage => 'core', - required => 1, - min_ver => '0.058', - }, 'Net::Z3950::SimpleServer' => { 'usage' => 'Z39.50 responder', 'required' => '0', diff --git a/Koha/Z3950Responder.pm b/Koha/Z3950Responder.pm index cda52ead25..c7a7bf2973 100644 --- a/Koha/Z3950Responder.pm +++ b/Koha/Z3950Responder.pm @@ -32,7 +32,7 @@ use Net::Z3950::SimpleServer; sub new { my ( $class, $config ) = @_; - my ($item_tag, $itemnumber_subfield) = GetMarcFromKohaField( "items.itemnumber", '' ); + my ($item_tag, $itemnumber_subfield) = GetMarcFromKohaField( "items.itemnumber" ); # We hardcode the strings for English so SOMETHING will work if the authorized value doesn't exist. my $status_strings = { @@ -57,13 +57,13 @@ sub new { status_strings => $status_strings, }; - # Turn off Yaz's built-in logging (can be turned back on if desired). - unshift @{ $self->{yaz_options} }, '-v', 'none'; - # If requested, turn on debugging. if ( $self->{debug} ) { # Turn on single-process mode. unshift @{ $self->{yaz_options} }, '-S'; + } else { + # Turn off Yaz's built-in logging apart from fatal errors (can be turned back on if desired). + unshift @{ $self->{yaz_options} }, '-v', 'none,fatal'; } $self->{server} = Net::Z3950::SimpleServer->new( diff --git a/Koha/Z3950Responder/Session.pm b/Koha/Z3950Responder/Session.pm index 209a96d858..338056bb15 100644 --- a/Koha/Z3950Responder/Session.pm +++ b/Koha/Z3950Responder/Session.pm @@ -80,6 +80,7 @@ sub _log_error { sub _set_error { my ( $self, $args, $code, $msg ) = @_; + ( $args->{ERR_CODE}, $args->{ERR_STR} ) = ( $code, $msg ); $self->_log_error(" returning error $code: $msg"); @@ -140,8 +141,8 @@ sub _check_fetch { return 0; } - if ( $offset + $num_records > $resultset->{hits} ) { - $self->_set_error( $args, ERR_PRESENT_OUT_OF_RANGE, 'Fetch request out of range' ); + if ( $offset < 0 || $offset + $num_records > $resultset->{hits} ) { + $self->_set_error( $args, ERR_PRESENT_OUT_OF_RANGE, 'Present request out of range' ); return 0; } @@ -155,7 +156,7 @@ sub _fetch_record { eval { if ( !$resultset->{results}->record_immediate( $index ) ) { - my $start = int( $index / $num_to_prefetch ) * $num_to_prefetch; + my $start = $num_to_prefetch ? int( $index / $num_to_prefetch ) * $num_to_prefetch : $index; if ( $start + $num_to_prefetch >= $resultset->{results}->size() ) { $num_to_prefetch = $resultset->{results}->size() - $start; @@ -184,7 +185,7 @@ sub search_handler { my $database = $args->{DATABASES}->[0]; if ( $database !~ /^(biblios|authorities)$/ ) { - $self->_set_error( ERR_DB_DOES_NOT_EXIST, 'No such database' ); + $self->_set_error( $args, ERR_DB_DOES_NOT_EXIST, 'No such database' ); return; } diff --git a/misc/bin/koha-zebra-ctl-oma.sh b/misc/bin/koha-zebra-ctl-oma.sh new file mode 100755 index 0000000000..d5e2ffa69d --- /dev/null +++ b/misc/bin/koha-zebra-ctl-oma.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# 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 . + +### BEGIN INIT INFO +# Provides: koha-zebra-daemon +# Required-Start: $syslog $remote_fs +# Required-Stop: $syslog $remote_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Zebra server daemon for Koha indexing +### END INIT INFO + +USER=ere +GROUP=users +DBNAME=koha3 +NAME=koha-zebra-ctl.koha3 +LOGDIR=/home/ere/koha-dev/var/log +ERRLOG=$LOGDIR/koha-zebradaemon.err +STDOUT=$LOGDIR/koha-zebradaemon.log +OUTPUT=$LOGDIR/koha-zebradaemon-output.log +KOHA_CONF=/home/ere/koha-dev/etc/koha-conf.xml +RUNDIR=/home/ere/koha-dev/var/run +LOCKDIR=/home/ere/koha-dev/var/lock +# you may need to change this depending on where zebrasrv is installed +ZEBRASRV=/usr/bin/zebrasrv +ZEBRAOPTIONS="-v none,fatal,warn" + +test -f $ZEBRASRV || exit 0 + +OTHERUSER='' +if [[ $EUID -eq 0 ]]; then + OTHERUSER="--user=$USER.$GROUP" +fi + +case "$1" in + start) + echo "Starting Zebra Server" + + # create run and lock directories if needed; + # /var/run and /var/lock are completely cleared at boot + # on some platforms + if [[ ! -d $RUNDIR ]]; then + umask 022 + mkdir -p $RUNDIR + if [[ $EUID -eq 0 ]]; then + chown $USER:$GROUP $RUNDIR + fi + fi + if [[ ! -d $LOCKDIR ]]; then + umask 022 + mkdir -p $LOCKDIR + mkdir -p $LOCKDIR/biblios + mkdir -p $LOCKDIR/authorities + mkdir -p $LOCKDIR/rebuild + if [[ $EUID -eq 0 ]]; then + chown -R $USER:$GROUP $LOCKDIR + fi + fi + + daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER -- $ZEBRASRV $ZEBRAOPTIONS -f $KOHA_CONF + ;; + stop) + echo "Stopping Zebra Server" + daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER --stop -- $ZEBRASRV -f $KOHA_CONF + ;; + restart) + echo "Restarting the Zebra Server" + daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER --restart -- $ZEBRASRV -f $KOHA_CONF + ;; + *) + echo "Usage: /etc/init.d/$NAME {start|stop|restart}" + exit 1 + ;; +esac diff --git a/misc/z3950_responder.pl b/misc/z3950_responder.pl index 2e63177d22..729934338d 100755 --- a/misc/z3950_responder.pl +++ b/misc/z3950_responder.pl @@ -36,6 +36,9 @@ use Koha::Z3950Responder; =head1 OPTIONS +See https://software.indexdata.com/yaz/doc/server.invocation.html for more information about YAZ options +not described below. + =over 8 =item B<--help> @@ -102,7 +105,6 @@ my @yaz_options; sub add_yaz_option { my ( $opt_name, $opt_value ) = @_; - warn "name: $opt_name and value: $opt_value"; push @yaz_options, "-$opt_name", "$opt_value"; } @@ -145,6 +147,11 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; +if (!@ARGV || $ARGV[-1] =~ /^-/) { + # No bind address specified. Use @:2100 by default. + push(@ARGV, '@:2100'); +} + # Create and start the server. die "This tool only works with Zebra" if C4::Context->preference('SearchEngine') ne 'Zebra'; diff --git a/t/Koha/Z3950responder.t b/t/Koha/Z3950responder.t index 3d74e5df8f..7f2219783b 100644 --- a/t/Koha/Z3950responder.t +++ b/t/Koha/Z3950responder.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 2; BEGIN { use_ok('Koha::Z3950Responder'); @@ -9,23 +9,6 @@ BEGIN { my $zR = Koha::Z3950Responder->new({}); -my $args={ PEER_NAME => 'PEER'}; +my $args = { PEER_NAME => 'PEER' }; $zR->init_handler($args); -is ( $args->{IMP_NAME}, 'Koha',"Server returns basic info"); -$args->{DATABASES} = ['biblios']; -$args->{QUERY} = 'biblios'; -$args->{SETNAME} = 'biblios'; -$args->{START} = 0; -$args->{OFFSET} = 0; -$args->{NUMBER} = 42; -$zR->search_handler( $args ); -is ( $args->{ERR_CODE}, 2, "We didn't start server , should fail"); -is ( $args->{ERR_STR}, 'Cannot connect to upstream server', "We didn't start server, should fail because it cannot connect"); -$zR->present_handler( $args ); -is ( $args->{ERR_CODE}, 30, "There is no handler as we aren't connected"); -is ( $args->{ERR_STR}, 'No such resultset', "We don't have a handler, should fail because we don't"); -my $arg_check = ( $args ); -$zR->fetch_handler( $args ); -is_deeply( $args, $arg_check, "nothing should change"); -$zR->close_handler( $args ); -is_deeply( $args, $arg_check, "nothing should change"); +is ( $args->{IMP_NAME}, 'Koha', 'Server returns basic info' ); -- 2.17.1