From e81d21901fedb7b315723ca8689f6c7172f14cdf Mon Sep 17 00:00:00 2001 From: Juan Romay Sieira <juan.sieira@xercode.es> Date: Fri, 8 Apr 2011 12:09:52 +0200 Subject: [PATCH] Set a timeout to z3950 servers that could have network problems occasionally Content-Type: text/plain; charset="utf-8" --- admin/z3950servers.pl | 24 +++++++++++-------- cataloguing/z3950_search.pl | 1 + installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 9 ++++--- .../prog/en/modules/admin/z3950servers.tmpl | 7 ++++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl index 44b3967..752c4dc 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 @@ -92,7 +92,7 @@ if ($op eq 'add_form') { my $sth=$dbh->prepare("select * from z3950servers where name=?"); $sth->execute($input->param('searchfield')); 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'), @@ -103,14 +103,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' ), @@ -121,7 +122,8 @@ if ($op eq 'add_form') { $input->param( 'checked' ), $input->param( 'rank' ), $input->param( 'syntax' ), - $input->param( 'encoding' ) ); + $input->param( 'encoding' ), + $input->param( 'timeout' ) ); } $sth->finish; # END $OP eq ADD_VALIDATE @@ -131,7 +133,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; @@ -144,7 +146,8 @@ if ($op eq 'add_form') { checked => $data->{'checked'}, rank => $data->{'rank'}, syntax => $data->{'syntax'}, - encoding => $data->{'encoding'} ); + encoding => $data->{'encoding'}, + timeout => $data->{'timeout'} ); # END $OP eq DELETE_CONFIRM ################## DELETE_CONFIRMED ################################## @@ -174,7 +177,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..d66945c 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() ); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index b722411..4f98cda 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1990,6 +1990,7 @@ CREATE TABLE `z3950servers` ( `checked` smallint(6) default NULL, `rank` int(11) default NULL, `syntax` varchar(80) default NULL, + `timeout` int(11) NOT NULL DEFAULT '0', `icon` text, `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 648e35b..9fca4a7 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4261,13 +4261,14 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { $DBversion = "3.03.00.047"; if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { - $dbh->do(" - ALTER TABLE `marc_subfield_structure` ADD `punctuation` VARCHAR( 5 ) NULL , ADD `help` VARCHAR( 255 ) NULL; - "); - print "Upgrade to $DBversion done (Punctuation and cataloguing help)\n"; + $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.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tmpl index 93ec488..14862ec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tmpl @@ -226,6 +226,8 @@ <!-- /TMPL_IF --> </select> </li> + <li><label for="timeout">Timeout (0 its like not set): </label> <input type="text" name="timeout" id="timeout" size="4" value="<!-- TMPL_VAR NAME="timeout" -->" onblur="isNum(this)" /> + </li> </ol> </fieldset> @@ -254,6 +256,7 @@ <li><strong>Rank: </strong><!-- TMPL_VAR NAME="rank" --></li> <li><strong>Syntax: </strong><!-- TMPL_VAR NAME="syntax" --></li> <li><strong>Encoding: </strong><!-- TMPL_VAR NAME="encoding" --></li> + <li><strong>Timeout: </strong><!-- TMPL_VAR NAME="timeout" --></li> </ul> <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post"><input type="hidden" name="op" value="delete_confirmed" /><input type="hidden" name="searchfield" value="<!-- TMPL_VAR NAME="searchfield" -->" /><input type="submit" value="Delete this Server" /></form> <form action="<!-- TMPL_VAR NAME="script_name" -->" method="post"><input type="submit" value="Do Not Delete" /></form> @@ -297,7 +300,7 @@ You searched for <!-- TMPL_VAR NAME="searchfield" --> <!-- /TMPL_IF --> <table id="serverst"> - <thead><tr><th>Target</th><th>Hostname/Port</th><th>Database</th><th>Userid</th><th>Password</th><th>Checked</th><th>Rank</th> <th>Syntax</th><th>Encoding</th><th colspan="2"> </th> + <thead><tr><th>Target</th><th>Hostname/Port</th><th>Database</th><th>Userid</th><th>Password</th><th>Checked</th><th>Rank</th> <th>Syntax</th><th>Encoding</th><th>Timeout</th><th colspan="2"> </th> </tr></thead> <tbody><!-- TMPL_LOOP NAME="loop" --> <!-- TMPL_UNLESS NAME="__odd__" --> @@ -305,7 +308,7 @@ <!-- TMPL_ELSE --> <tr> <!-- /TMPL_UNLESS --> -<td><a href="<!-- TMPL_VAR name="script_name" -->?op=add_form&searchfield=<!-- TMPL_VAR NAME="name" ESCAPE="url" -->"><!-- TMPL_VAR NAME="name" --></a></td><td><!-- TMPL_VAR NAME="host" -->:<!-- TMPL_VAR NAME="port" --></td><td><!-- TMPL_VAR NAME="db" --></td><td><!-- TMPL_VAR NAME="userid" --></td><td><!-- TMPL_VAR NAME="password" --></td><td><!-- TMPL_VAR NAME="checked" --></td><td><!-- TMPL_VAR NAME="rank" --></td> <td><!-- TMPL_VAR NAME="syntax" --></td><td><!-- TMPL_VAR NAME="encoding" --></td><td><a href="<!-- TMPL_VAR name="script_name" -->?op=add_form&searchfield=<!-- TMPL_VAR NAME="name" ESCAPE="url" -->">Edit</a></td><td><a href="<!-- TMPL_VAR name="script_name" -->?op=delete_confirm&searchfield=<!-- TMPL_VAR NAME="name" ESCAPE="url" -->">Delete</a></td> </tr> +<td><a href="<!-- TMPL_VAR name="script_name" -->?op=add_form&searchfield=<!-- TMPL_VAR NAME="name" ESCAPE="url" -->"><!-- TMPL_VAR NAME="name" --></a></td><td><!-- TMPL_VAR NAME="host" -->:<!-- TMPL_VAR NAME="port" --></td><td><!-- TMPL_VAR NAME="db" --></td><td><!-- TMPL_VAR NAME="userid" --></td><td><!-- TMPL_VAR NAME="password" --></td><td><!-- TMPL_VAR NAME="checked" --></td><td><!-- TMPL_VAR NAME="rank" --></td> <td><!-- TMPL_VAR NAME="syntax" --></td><td><!-- TMPL_VAR NAME="encoding" --></td><td><!-- TMPL_VAR NAME="timeout" --></td><td><a href="<!-- TMPL_VAR name="script_name" -->?op=add_form&searchfield=<!-- TMPL_VAR NAME="name" ESCAPE="url" -->">Edit</a></td><td><a href="<!-- TMPL_VAR name="script_name" -->?op=delete_confirm&searchfield=<!-- TMPL_VAR NAME="name" ESCAPE="url" -->">Delete</a></td> </tr> <!-- /TMPL_LOOP --></tbody> </table> -- 1.7.4.1