From d5886dee2eb75b9ba129b543934b88aec00ead3c Mon Sep 17 00:00:00 2001 From: Juan Romay Sieira Date: Wed, 21 Mar 2012 14:56:54 +0100 Subject: [PATCH 18/18] Bug 6140 - Set a timeout to z3950 servers that could have network problems occasionally Content-Type: text/plain; charset="utf-8" --- admin/z3950servers.pl | 20 ++++++++++++-------- cataloguing/z3950_search.pl | 3 ++- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 9 +++++++++ .../prog/en/modules/admin/z3950servers.tt | 8 ++++++-- .../prog/en/modules/cataloguing/z3950_search.tt | 3 ++- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index f0a4dbb..f06a4f3 100755 --- a/admin/z3950servers.pl +++ b/admin/z3950servers.pl @@ -32,7 +32,7 @@ sub StringSearch { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $sth=$dbh->prepare("Select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name like ?) order by rank,name"); + my $sth=$dbh->prepare("Select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout from z3950servers where (name like ?) order by rank,name"); $sth->execute("$data[0]\%"); my @results; while (my $data=$sth->fetchrow_hashref) { @@ -74,13 +74,13 @@ if ($op eq 'add_form') { my $data; if ($searchfield) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name = ?) order by rank,name"); + my $sth=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout from z3950servers where (name = ?) order by rank,name"); $sth->execute($searchfield); $data=$sth->fetchrow_hashref; $sth->finish; } $template->param( $_ => $data->{$_} ) - for ( qw( host port db userid password checked rank ) ); + for ( qw( host port db userid password checked rank timeout ) ); $template->param( $_ . $data->{$_} => 1) for ( qw( syntax encoding ) ); # END $OP eq ADD_FORM @@ -93,7 +93,7 @@ if ($op eq 'add_form') { $sth->execute($input->param('searchfield')); my $checked = $input->param('checked') ? 1 : 0; if ($sth->rows) { - $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=? where name=?"); + $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,timeout=? where name=?"); $sth->execute($input->param('host'), $input->param('port'), $input->param('db'), @@ -104,14 +104,15 @@ if ($op eq 'add_form') { $input->param('rank'), $input->param('syntax'), $input->param('encoding'), + $input->param('timeout'), $input->param('searchfield'), ); } else { $sth=$dbh->prepare( "INSERT INTO z3950servers " . - "(host,port,db,userid,password,name,checked,rank,syntax,encoding) " . - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); + "(host,port,db,userid,password,name,checked,rank,syntax,encoding,timeout) " . + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); $sth->execute( $input->param( 'host' ), $input->param( 'port' ), @@ -122,6 +123,7 @@ if ($op eq 'add_form') { $input->param( 'checked' ), $input->param( 'rank' ), $input->param( 'syntax' ), + $input->param( 'timeout' ), $input->param( 'encoding' ) ); } $sth->finish; @@ -132,7 +134,7 @@ if ($op eq 'add_form') { $template->param(delete_confirm => 1); my $dbh = C4::Context->dbh; - my $sth2=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding from z3950servers where (name = ?) order by rank,name"); + my $sth2=$dbh->prepare("select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout from z3950servers where (name = ?) order by rank,name"); $sth2->execute($searchfield); my $data=$sth2->fetchrow_hashref; $sth2->finish; @@ -145,6 +147,7 @@ if ($op eq 'add_form') { checked => $data->{'checked'}, rank => $data->{'rank'}, syntax => $data->{'syntax'}, + timeout => $data->{'timeout'}, encoding => $data->{'encoding'} ); # END $OP eq DELETE_CONFIRM @@ -175,7 +178,8 @@ if ($op eq 'add_form') { checked => $results->[$i]{'checked'}, rank => $results->[$i]{'rank'}, syntax => $results->[$i]{'syntax'}, - encoding => $results->[$i]{'encoding'}); + encoding => $results->[$i]{'encoding'}, + timeout => $results->[$i]{'timeout'}); push @loop, \%row; } diff --git a/cataloguing/z3950_search.pl b/cataloguing/z3950_search.pl index b12a9c9..10320e2 100755 --- a/cataloguing/z3950_search.pl +++ b/cataloguing/z3950_search.pl @@ -179,6 +179,7 @@ warn "query ".$query if $DEBUG; $option1->option('user', $server->{userid} ) if $server->{userid}; $option1->option('password', $server->{password}) if $server->{password}; $option1->option('preferredRecordSyntax', $server->{syntax}); + $option1->option( 'timeout', $server->{timeout} ) if ($server->{timeout}); $oConnection[$s] = create ZOOM::Connection($option1) || $DEBUG && warn( "" . $oConnection[$s]->errmsg() ); @@ -222,7 +223,7 @@ warn "query ".$query if $DEBUG; $oConnection[$k]->error_x(); if ($error) { if ($error =~ m/^(10000|10007)$/ ) { - push(@errconn, {'server' => $serverhost[$k]}); + push(@errconn, {'server' => $serverhost[$k], 'error' => $error}); } $DEBUG and warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n"; } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e0ce034..289645f 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2094,6 +2094,7 @@ CREATE TABLE `z3950servers` ( -- connection information for the Z39.50 targets u `checked` smallint(6) default NULL, -- whether this target is checked by default (1 for yes, 0 for no) `rank` int(11) default NULL, -- where this target appears in the list of targets `syntax` varchar(80) default NULL, -- marc format provided by this target + `timeout` int(11) NOT NULL DEFAULT '0', `icon` text, -- unused in Koha `position` enum('primary','secondary','') NOT NULL default 'primary', `type` enum('zed','opensearch') NOT NULL default 'zed', diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index a2335af..504d523 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4960,6 +4960,15 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.07.00.xxx"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(qq{ + ALTER TABLE `z3950servers` ADD `timeout` INT( 11 ) NOT NULL DEFAULT '0' AFTER `syntax`; + }); + print "Upgrade to $DBversion done (New timeout field in z3950servers)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt index 12585b3..d5de0db 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt @@ -230,6 +230,9 @@ [% END %] +
  • + seconds +
  • @@ -258,6 +261,7 @@
  • Rank: [% rank %]
  • Syntax: [% syntax %]
  • Encoding: [% encoding %]
  • +
  • Timeout: [% timeout %]
  • @@ -301,7 +305,7 @@ You searched for [% searchfield %] [% END %] - + [% FOREACH loo IN loop %] [% UNLESS ( loop.odd ) %] @@ -309,7 +313,7 @@ [% ELSE %] [% END %] - + [% END %]
    TargetHostname/PortDatabaseUseridPasswordCheckedRank SyntaxEncoding 
    TargetHostname/PortDatabaseUseridPasswordCheckedRank SyntaxEncodingTimeout 
    [% loo.name %][% loo.host %]:[% loo.port %][% loo.db %][% loo.userid %][% loo.password %][% IF ( loo.checked ) %]Yes[% ELSE %]No[% END %][% loo.rank %] [% loo.syntax %][% loo.encoding %]EditDelete
    [% loo.name %][% loo.host %]:[% loo.port %][% loo.db %][% loo.userid %][% loo.password %][% IF ( loo.checked ) %]Yes[% ELSE %]No[% END %][% loo.rank %] [% loo.syntax %][% loo.encoding %][% loo.timeout %]EditDelete
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt index 7775f1f..5d5cb1d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/z3950_search.tt @@ -166,7 +166,8 @@ tr.selected { background-color : #FFFFCC; } tr.selected td { background-color :
    -- 1.7.5.4