View | Details | Raw Unified | Return to bug 13937
Collapse All | Expand All

(-)a/C4/Installer/PerlDependencies.pm (-5 lines)
Lines 893-903 our $PERL_DEPS = { Link Here
893
        required => '1',
893
        required => '1',
894
        min_ver  => '0.37',
894
        min_ver  => '0.37',
895
    },
895
    },
896
    'Path::Tiny' => {
897
        usage => 'core',
898
        required => 1,
899
        min_ver => '0.058',
900
    },
901
    'Net::Z3950::SimpleServer' => {
896
    'Net::Z3950::SimpleServer' => {
902
        'usage'    => 'Z39.50 responder',
897
        'usage'    => 'Z39.50 responder',
903
        'required' => '0',
898
        'required' => '0',
(-)a/Koha/Z3950Responder.pm (-4 / +4 lines)
Lines 32-38 use Net::Z3950::SimpleServer; Link Here
32
sub new {
32
sub new {
33
    my ( $class, $config ) = @_;
33
    my ( $class, $config ) = @_;
34
34
35
    my ($item_tag, $itemnumber_subfield) = GetMarcFromKohaField( "items.itemnumber", '' );
35
    my ($item_tag, $itemnumber_subfield) = GetMarcFromKohaField( "items.itemnumber" );
36
36
37
    # We hardcode the strings for English so SOMETHING will work if the authorized value doesn't exist.
37
    # We hardcode the strings for English so SOMETHING will work if the authorized value doesn't exist.
38
    my $status_strings = {
38
    my $status_strings = {
Lines 57-69 sub new { Link Here
57
        status_strings => $status_strings,
57
        status_strings => $status_strings,
58
    };
58
    };
59
59
60
    # Turn off Yaz's built-in logging (can be turned back on if desired).
61
    unshift @{ $self->{yaz_options} }, '-v', 'none';
62
63
    # If requested, turn on debugging.
60
    # If requested, turn on debugging.
64
    if ( $self->{debug} ) {
61
    if ( $self->{debug} ) {
65
        # Turn on single-process mode.
62
        # Turn on single-process mode.
66
        unshift @{ $self->{yaz_options} }, '-S';
63
        unshift @{ $self->{yaz_options} }, '-S';
64
    } else {
65
        # Turn off Yaz's built-in logging apart from fatal errors (can be turned back on if desired).
66
        unshift @{ $self->{yaz_options} }, '-v', 'none,fatal';
67
    }
67
    }
68
68
69
    $self->{server} = Net::Z3950::SimpleServer->new(
69
    $self->{server} = Net::Z3950::SimpleServer->new(
(-)a/Koha/Z3950Responder/Session.pm (-4 / +5 lines)
Lines 80-85 sub _log_error { Link Here
80
80
81
sub _set_error {
81
sub _set_error {
82
    my ( $self, $args, $code, $msg ) = @_;
82
    my ( $self, $args, $code, $msg ) = @_;
83
83
    ( $args->{ERR_CODE}, $args->{ERR_STR} ) = ( $code, $msg );
84
    ( $args->{ERR_CODE}, $args->{ERR_STR} ) = ( $code, $msg );
84
85
85
    $self->_log_error("    returning error $code: $msg");
86
    $self->_log_error("    returning error $code: $msg");
Lines 140-147 sub _check_fetch { Link Here
140
        return 0;
141
        return 0;
141
    }
142
    }
142
143
143
    if ( $offset + $num_records > $resultset->{hits} )  {
144
    if ( $offset < 0 || $offset + $num_records > $resultset->{hits} )  {
144
        $self->_set_error( $args, ERR_PRESENT_OUT_OF_RANGE, 'Fetch request out of range' );
145
        $self->_set_error( $args, ERR_PRESENT_OUT_OF_RANGE, 'Present request out of range' );
145
        return 0;
146
        return 0;
146
    }
147
    }
147
148
Lines 155-161 sub _fetch_record { Link Here
155
156
156
    eval {
157
    eval {
157
        if ( !$resultset->{results}->record_immediate( $index ) ) {
158
        if ( !$resultset->{results}->record_immediate( $index ) ) {
158
            my $start = int( $index / $num_to_prefetch ) * $num_to_prefetch;
159
            my $start = $num_to_prefetch ? int( $index / $num_to_prefetch ) * $num_to_prefetch : $index;
159
160
160
            if ( $start + $num_to_prefetch >= $resultset->{results}->size() ) {
161
            if ( $start + $num_to_prefetch >= $resultset->{results}->size() ) {
161
                $num_to_prefetch = $resultset->{results}->size() - $start;
162
                $num_to_prefetch = $resultset->{results}->size() - $start;
Lines 184-190 sub search_handler { Link Here
184
    my $database = $args->{DATABASES}->[0];
185
    my $database = $args->{DATABASES}->[0];
185
186
186
    if ( $database !~ /^(biblios|authorities)$/ ) {
187
    if ( $database !~ /^(biblios|authorities)$/ ) {
187
        $self->_set_error( ERR_DB_DOES_NOT_EXIST, 'No such database' );
188
        $self->_set_error( $args, ERR_DB_DOES_NOT_EXIST, 'No such database' );
188
        return;
189
        return;
189
    }
190
    }
190
191
(-)a/misc/bin/koha-zebra-ctl-oma.sh (+88 lines)
Line 0 Link Here
1
#!/bin/bash
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
### BEGIN INIT INFO
19
# Provides:          koha-zebra-daemon
20
# Required-Start:    $syslog $remote_fs
21
# Required-Stop:     $syslog $remote_fs
22
# Default-Start:     2 3 4 5
23
# Default-Stop:      0 1 6
24
# Short-Description: Zebra server daemon for Koha indexing
25
### END INIT INFO
26
27
USER=ere
28
GROUP=users
29
DBNAME=koha3
30
NAME=koha-zebra-ctl.koha3
31
LOGDIR=/home/ere/koha-dev/var/log
32
ERRLOG=$LOGDIR/koha-zebradaemon.err
33
STDOUT=$LOGDIR/koha-zebradaemon.log
34
OUTPUT=$LOGDIR/koha-zebradaemon-output.log
35
KOHA_CONF=/home/ere/koha-dev/etc/koha-conf.xml
36
RUNDIR=/home/ere/koha-dev/var/run
37
LOCKDIR=/home/ere/koha-dev/var/lock
38
# you may need to change this depending on where zebrasrv is installed
39
ZEBRASRV=/usr/bin/zebrasrv
40
ZEBRAOPTIONS="-v none,fatal,warn"
41
42
test -f $ZEBRASRV || exit 0
43
44
OTHERUSER=''
45
if [[ $EUID -eq 0 ]]; then
46
    OTHERUSER="--user=$USER.$GROUP"
47
fi
48
49
case "$1" in
50
    start)
51
      echo "Starting Zebra Server"
52
53
      # create run and lock directories if needed;
54
      # /var/run and /var/lock are completely cleared at boot
55
      # on some platforms
56
      if [[ ! -d $RUNDIR ]]; then
57
        umask 022
58
        mkdir -p $RUNDIR
59
        if [[ $EUID -eq 0 ]]; then
60
            chown $USER:$GROUP $RUNDIR
61
        fi
62
      fi
63
      if [[ ! -d $LOCKDIR ]]; then
64
        umask 022
65
        mkdir -p $LOCKDIR
66
        mkdir -p $LOCKDIR/biblios
67
        mkdir -p $LOCKDIR/authorities
68
        mkdir -p $LOCKDIR/rebuild
69
        if [[ $EUID -eq 0 ]]; then
70
            chown -R $USER:$GROUP $LOCKDIR
71
        fi
72
      fi
73
74
      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER -- $ZEBRASRV $ZEBRAOPTIONS -f $KOHA_CONF
75
      ;;
76
    stop)
77
      echo "Stopping Zebra Server"
78
      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER --stop -- $ZEBRASRV -f $KOHA_CONF
79
      ;;
80
    restart)
81
      echo "Restarting the Zebra Server"
82
      daemon --name=$NAME --errlog=$ERRLOG --stdout=$STDOUT --output=$OUTPUT --verbose=1 --respawn --delay=30 $OTHERUSER --restart -- $ZEBRASRV -f $KOHA_CONF
83
      ;;
84
    *)
85
      echo "Usage: /etc/init.d/$NAME {start|stop|restart}"
86
      exit 1
87
      ;;
88
esac
(-)a/misc/z3950_responder.pl (-1 / +8 lines)
Lines 36-41 use Koha::Z3950Responder; Link Here
36
36
37
=head1 OPTIONS
37
=head1 OPTIONS
38
38
39
See https://software.indexdata.com/yaz/doc/server.invocation.html for more information about YAZ options
40
not described below.
41
39
=over 8
42
=over 8
40
43
41
=item B<--help>
44
=item B<--help>
Lines 102-108 my @yaz_options; Link Here
102
105
103
sub add_yaz_option {
106
sub add_yaz_option {
104
    my ( $opt_name, $opt_value ) = @_;
107
    my ( $opt_name, $opt_value ) = @_;
105
    warn "name: $opt_name and value: $opt_value";
106
108
107
    push @yaz_options, "-$opt_name", "$opt_value";
109
    push @yaz_options, "-$opt_name", "$opt_value";
108
}
110
}
Lines 145-150 GetOptions( Link Here
145
pod2usage(1) if $help;
147
pod2usage(1) if $help;
146
pod2usage( -verbose => 2 ) if $man;
148
pod2usage( -verbose => 2 ) if $man;
147
149
150
if (!@ARGV || $ARGV[-1] =~ /^-/) {
151
    # No bind address specified. Use @:2100 by default.
152
    push(@ARGV, '@:2100');
153
}
154
148
# Create and start the server.
155
# Create and start the server.
149
156
150
die "This tool only works with Zebra" if C4::Context->preference('SearchEngine') ne 'Zebra';
157
die "This tool only works with Zebra" if C4::Context->preference('SearchEngine') ne 'Zebra';
(-)a/t/Koha/Z3950responder.t (-21 / +3 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 8;
4
use Test::More tests => 2;
5
5
6
BEGIN {
6
BEGIN {
7
    use_ok('Koha::Z3950Responder');
7
    use_ok('Koha::Z3950Responder');
Lines 9-31 BEGIN { Link Here
9
9
10
my $zR = Koha::Z3950Responder->new({});
10
my $zR = Koha::Z3950Responder->new({});
11
11
12
my $args={ PEER_NAME => 'PEER'};
12
my $args = { PEER_NAME => 'PEER' };
13
$zR->init_handler($args);
13
$zR->init_handler($args);
14
is ( $args->{IMP_NAME}, 'Koha',"Server returns basic info");
14
is ( $args->{IMP_NAME}, 'Koha', 'Server returns basic info' );
15
$args->{DATABASES} = ['biblios'];
16
$args->{QUERY} = 'biblios';
17
$args->{SETNAME} = 'biblios';
18
$args->{START} = 0;
19
$args->{OFFSET} = 0;
20
$args->{NUMBER} = 42;
21
$zR->search_handler( $args );
22
is ( $args->{ERR_CODE}, 2, "We didn't start server , should fail");
23
is ( $args->{ERR_STR}, 'Cannot connect to upstream server', "We didn't start server, should fail because it cannot connect");
24
$zR->present_handler( $args );
25
is ( $args->{ERR_CODE}, 30, "There is no handler as we aren't connected");
26
is ( $args->{ERR_STR}, 'No such resultset', "We don't have a handler, should fail because we don't");
27
my $arg_check = ( $args );
28
$zR->fetch_handler( $args );
29
is_deeply( $args, $arg_check, "nothing should change");
30
$zR->close_handler( $args );
31
is_deeply( $args, $arg_check, "nothing should change");
32
- 

Return to bug 13937