Browse Source

Bug 13937: Fix issues found in QA

Signed-off-by: Stefan Berndtsson <stefan.berndtsson@ub.gu.se>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
remotes/origin/19.11.x
Ere Maijala 3 years ago
committed by Martin Renvoize
parent
commit
925db0baef
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 5
      C4/Installer/PerlDependencies.pm
  2. 8
      Koha/Z3950Responder.pm
  3. 9
      Koha/Z3950Responder/Session.pm
  4. 9
      misc/z3950_responder.pl
  5. 23
      t/Koha/Z3950responder.t

5
C4/Installer/PerlDependencies.pm

@ -908,11 +908,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',

8
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(

9
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;
}

9
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';

23
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' );

Loading…
Cancel
Save