X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FZ3950Responder.pm;h=3e1f1d22cd7520550676a70035e005a883bd1f95;hb=6744cd6612be7a8ac60db45d2fdce6f303bb2122;hp=cda52ead253ed31d982c68cdbef64a4138d8f66b;hpb=f089d393dc421f484bb806b0c587ffefe0d9020b;p=koha-ffzg.git diff --git a/Koha/Z3950Responder.pm b/Koha/Z3950Responder.pm index cda52ead25..3e1f1d22cd 100644 --- a/Koha/Z3950Responder.pm +++ b/Koha/Z3950Responder.pm @@ -1,38 +1,71 @@ -#!/usr/bin/perl - package Koha::Z3950Responder; # Copyright ByWater Solutions 2016 # # 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 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. +# 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. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use Modern::Perl; use C4::Biblio qw( GetMarcFromKohaField ); use C4::Koha qw( GetAuthorisedValues ); -use Koha; -use Koha::Z3950Responder::Session; +use Koha::Caches; use Net::Z3950::SimpleServer; +=head1 NAME + +Koha::Z3950Responder - Main class for interfacing with Net::Z3950::SimpleServer + +=head1 SYNOPSIS + + use Koha::Z3950Responder; + + my $z = Koha::Z3950Responder->new( { + add_item_status_subfield => 1, + add_status_multi_subfield => 1, + debug => 0, + num_to_prefetch => 20, + config_dir => '/home/koha/etc', + yaz_options => [ ], + } ); + + $z->start(); + +=head1 DESCRIPTION + +A daemon class that interfaces with Net::Z3950::SimpleServer to provider Z39.50/SRU +service. Uses a Session class for the actual functionality. + +=head1 METHODS + +=head2 INSTANCE METHODS + +=head3 new + + $self->new({ + add_item_status_subfield => 1 + }); + +=cut + 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,19 +90,27 @@ 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'; + } + + # Set main config for SRU support and working directory + if ( $self->{config_dir} ) { + unshift @{ $self->{yaz_options} }, '-f', $self->{config_dir} . 'config.xml'; + unshift @{ $self->{yaz_options} }, '-w', $self->{config_dir}; } + # Set num to prefetch if not passed + $self->{num_to_prefetch} //= 20; + $self->{server} = Net::Z3950::SimpleServer->new( INIT => sub { $self->init_handler(@_) }, SEARCH => sub { $self->search_handler(@_) }, - PRESENT => sub { $self->present_handler(@_) }, FETCH => sub { $self->fetch_handler(@_) }, CLOSE => sub { $self->close_handler(@_) }, ); @@ -77,25 +118,52 @@ sub new { return bless( $self, $class ); } +=head3 start + + $z->start(); + +Start the daemon and begin serving requests. Does not return unless initialization fails or a +fatal error occurs. + +=cut + sub start { my ( $self ) = @_; $self->{server}->launch_server( 'Koha::Z3950Responder', @{ $self->{yaz_options} } ) } -# The rest of these methods are SimpleServer callbacks bound to this Z3950Responder object. It's -# worth noting that these callbacks don't return anything; they both receive and return data in the -# $args hashref. +=head2 CALLBACKS + +These methods are SimpleServer callbacks bound to this Z3950Responder object. +It's worth noting that these callbacks don't return anything; they both +receive and return data in the $args hashref. + +=head3 init_handler + +Callback that is called when a new connection is initialized + +=cut sub init_handler { # Called when the client first connects. my ( $self, $args ) = @_; # This holds all of the per-connection state. - my $session = Koha::Z3950Responder::Session->new({ - server => $self, - peer => $args->{PEER_NAME}, - }); + my $session; + if (C4::Context->preference('SearchEngine') eq 'Zebra') { + use Koha::Z3950Responder::ZebraSession; + $session = Koha::Z3950Responder::ZebraSession->new({ + server => $self, + peer => $args->{PEER_NAME}, + }); + } else { + use Koha::Z3950Responder::GenericSession; + $session = Koha::Z3950Responder::GenericSession->new({ + server => $self, + peer => $args->{PEER_NAME} + }); + } $args->{HANDLE} = $session; @@ -103,27 +171,42 @@ sub init_handler { $args->{IMP_VER} = Koha::version; } +=head3 search_handler + +Callback that is called when a new search is performed + +=cut + sub search_handler { - # Called when search is first sent. my ( $self, $args ) = @_; + my $SearchEngine = C4::Context->preference('SearchEngine'); + # Flushing L1 to make sure the search will be processed using the correct data + Koha::Caches->flush_L1_caches(); + $self->init_handler($args) + if $SearchEngine ne C4::Context->preference('SearchEngine'); + $args->{HANDLE}->search_handler($args); } -sub present_handler { - # Called when a set of records is requested. - my ( $self, $args ) = @_; +=head3 fetch_handler - $args->{HANDLE}->present_handler($args); -} +Callback that is called when records are requested + +=cut sub fetch_handler { - # Called when a given record is requested. my ( $self, $args ) = @_; $args->{HANDLE}->fetch_handler( $args ); } +=head3 close_handler + +Callback that is called when a session is terminated + +=cut + sub close_handler { my ( $self, $args ) = @_;