From 36e1dda006d1454776a4e657d61131d26931f609 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 Signed-off-by: Stefan Berndtsson --- C4/Installer/PerlDependencies.pm | 5 ----- Koha/Z3950Responder.pm | 8 ++++---- Koha/Z3950Responder/Session.pm | 9 +++++---- misc/z3950_responder.pl | 9 ++++++++- t/Koha/Z3950responder.t | 23 +++-------------------- 5 files changed, 20 insertions(+), 34 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index b46c6d1ea0..6407504656 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/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