Use async ZOOM search for Z3950

A new async mode ZEBRA updating routine. We do not wailt for zebra updates anymore whether using shadow with BatchMode or not. Zebra updates in the background. System preference zebrawait determines how long zebra waits idle
This commit is contained in:
tgarip1957 2006-09-01 23:01:33 +00:00
parent 30e64942f4
commit 2dcb587229
9 changed files with 166 additions and 3498 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +0,0 @@
IMPORTING FROM Z39.50 SERVER WITH Character Set: win1250 (ISO 6937/2) into KOHA-2.0 WITH UTF-8
Files from this directory are here as a fix only and are of temporary nature. The fix was delivered to me by Zbigniew Bomart.
It will probably work for the Polish Language only. The issue needs to be addressed by Koha developers for the general audience.
There's a general problem with z39.50 import feature for koha instalations whose default charset IS NOT iso-8859-1.
When importing from z39.50 servers that keep their records in windows-1250 charset encoding and koha installation with UTF-8 one may use the replacement files in this directory.
Copy them to the following location:
/usr/local/koha/intranet/modules/C4/Biblio.pm
/usr/local/koha/intranet/cgi-bin/z3950/search.pl
and enjoy importing records in UTF-8 from Character Set: win1250 (ISO 6937/2) servers.
I tested it and the files seem to work on Fedora Core 1 and Koha-2.0
Remember to set the appropriate permissions on the files once you copy them. On my machine it is:
-rwxr-xr-x 1 apache apache 91813 May 2 18:34 Biblio.pm
-rwxr-xr-x 1 apache apache 3263 May 2 18:39 search.pl
Benedict P. Barszcz

View File

@ -1,18 +0,0 @@
IMPORTOWANIE DANYCH BIBLIOGRAFICZNYCH Z SERWERA BIBLIOTEKI NARODOWEJ W KODOWANIU win1250 (ISO 6937/2) DO KOHA-2.0 Z KODOWANIEM UTF-8.
Pliki w tym katalogu są czasowym rozwiązaniem problemu, który istnieje podczas importowania danych bibliograficznych przez sieć z biblioteki Narodowej w Warszawie. Rozwiązanie działa prawdopodobnie tylko dla języka polskiego dlatego deweloperzy Koha będą musieli coś zrobić z tym problemem w przyszłości.
Pliki z tego katalogu należy przekopiować do ich właściwego katalogu na zainstalowanym serwerze Koha-2.0:
/usr/local/koha/intranet/modules/C4/Biblio.pm
/usr/local/koha/intranet/cgi-bin/z3950/search.pl
Po skopiowaniu należy upewnić się, że przywileje plików są właściwe. U mnie to jest:
-rwxr-xr-x 1 apache apache 91813 May 2 18:34 Biblio.pm
-rwxr-xr-x 1 apache apache 3263 May 2 18:39 search.pl
Po tym zabiegu można spokojnie korzystać z serwera ( http://www.bn.org.pl/Z3950_eng.htm) INNOPAC biblioteki Narodowej w Warszawie do importu rekordów, które jakimś cudem nadal trzymają w win1250 (ISO 6937/2).
Autorem przedstawionego rozwiązania jest Zbigniew Bomart.
Benedykt P. Barszcz

View File

@ -1,110 +0,0 @@
#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# 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 2 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.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use CGI;
use C4::Auth;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Biblio;
use C4::Context;
use C4::Koha; # XXX subfield_is_koha_internal_p
use C4::Z3950;
use C4::Search;
use HTML::Template;
use MARC::File::USMARC;
use vars qw( $tagslib );
use vars qw( $is_a_modif );
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $error = $input->param('error');
my $bibid=$input->param('bibid');
my $title = $input->param('title');
my $author = $input->param('author');
my $isbn = $input->param('isbn');
my $issn = $input->param('issn');
my $random = $input->param('random');
my @results;
my $count;
my $toggle;
my $record;
my $oldbiblio;
if ($bibid > 0) {
$record = MARCgetbiblio($dbh,$bibid);
$oldbiblio = MARCmarc2koha($dbh,$record);
}
my $errmsg;
unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
if ($isbn) {
$random =rand(1000000000);
$errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
} elsif ($author) {
$random =rand(1000000000);
$errmsg = addz3950queue($author, "author", $random, 'CHECKED');
} elsif ($title) {
$random =rand(1000000000);
$errmsg = addz3950queue($title, "title", $random, 'CHECKED');
}
}
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "z3950/searchresult.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {catalogue => 1},
debug => 1,
});
# fill with books in breeding farm
($count, @results) = breedingsearch($title,$isbn,$random);
my $numberpending= &checkz3950searchdone($random);
my @breeding_loop = ();
for (my $i=0; $i <= $#results; $i++) {
my %row_data;
if ($i % 2) {
$toggle="#ffffcc";
} else {
$toggle="white";
}
$row_data{toggle} = $toggle;
$row_data{id} = $results[$i]->{'id'};
$row_data{isbn} = $results[$i]->{'isbn'};
$row_data{file} = $results[$i]->{'file'};
$row_data{title} = char_decode($results[$i]->{'title'}, "MARC21");
$row_data{author} = char_decode($results[$i]->{'author'}, "MARC21");
push (@breeding_loop, \%row_data);
}
$template->param(isbn => $isbn,
title => $title,
author => $author,
breeding_loop => \@breeding_loop,
refresh => ($numberpending eq 0 ? 0 : "search.pl?bibid=$bibid&random=$random"),
numberpending => $numberpending,
oldbiblionumber => $oldbiblio->{'biblionumber'},
);
print $input->header(
-type => guesstype($template->output),
-cookie => $cookie
),$template->output;

View File

@ -1,347 +0,0 @@
#!/usr/bin/perl
# $Id$
use MARC::Record;
use C4::Context;
use DBI;
use strict;
use C4::Biblio;
use C4::Output;
use C4::Breeding;
use ZOOM;
=head1 NAME
processz3950queue. The script that does z3950 searches.
=head1 SYNOPSIS
This script can be used on a console (as normal user) or by the daemon-launch script.
Don't forget to EXPORT PERL5LIB=/PATH/to/KOHA before executing it if you use console mode.
It :
1- extracts z3950 requests from z3950queue table,
2- creates entries in z3950results to store the result
3- launch z3950 queries in asynchronous mode, using Unix fork()
4- store results in marc_breeding table.
The z3950 results queries are managed in z3950/search.pl script (poped-up window in MARC editor).
=head1 DESCRIPTION
=head2 table z3950servers
This table stores the differents z3950 servers.
A server is used if checked=1. The rank is NOT used as searches are now asynchronous.
=head2 table z3950queue
Table use to manage queries. A single line is created in this table for each z3950 search request.
If more than 1 server is called, the C<servers> field containt all of them separated by |.
z3950 search requests are done by z3950/search.pl script.
At this stage, the fields are created with C<startdate> and C<done> empty
Then, the processz3950queue finds this entry and :
1- store date (time()) in C<startdate>
2- set C<done> = -1
when the requests are all sent :
2- set C<done> = 1
3- set C<enddate> (FIXME: always equal to startdate for me)
entries are deleted when :
- C<startdate> is more than 1 day ago.
FIXME:
- results, numrecords fields are unused
=head2 table z3950results
1 entry is created for each request, for each server called.
when created :
* C<startdate> is filled
* C<enddate> is null
* active is set to 0. when active is 0, it means the request has not been sent. when set to 1, it means it's on the way.
When a search is ended, C<enddate> is set, and C<active> is set to -1
=head1 How it's written
on every loop :
* delete old queries
* for each entry in z3950queue table that is not done=1 {
for each search request {
for each server {
try to connect
look for results
* results can be :
- existing and already running on another process (active=1)
- existing & finished (active=-1)
- non existent => create it and run the request.
}
}
}
=over 2
=cut
if ($< == 0) {
# Running as root, switch privs
if (-d "/var/run") {
open PID, ">/var/run/processz3950queue.pid";
print PID $$."\n";
close PID;
}
# Get real apacheuser from koha.conf or reparsing httpd.conf
my $apacheuser=C4::Context->config("httpduser");
my $uid=0;
unless ($uid = (getpwnam($apacheuser))[2]) {
die "Attempt to run daemon as non-existent or superuser\n";
}
$>=$uid;
$<=$uid;
}
my $db_driver = C4::Context->config("db_scheme") || "mysql";
my $db_name = C4::Context->config("database");
my $db_host = C4::Context->config("hostname");
my $db_user = C4::Context->config("user");
my $db_passwd = C4::Context->config("pass");
my $dbh = DBI->connect("DBI:$db_driver:$db_name:$db_host",$db_user, $db_passwd);
# we begin the script, so "unactive" every pending request : they will never give anything, the script died :-(
my $sth=$dbh->prepare("update z3950results set active=0 where active<>-1");
$sth->execute;
$sth->finish;
$SIG{CHLD}='reap';
$SIG{HUP}='checkqueue';
my $logdir=$ARGV[0];
open PID, ">$logdir/processz3950queue.pid";
print PID $$."\n";
close PID;
my $reapcounter=0;
my $forkcounter=0;
my $checkqueue=1;
my $pid=$$;
my $lastrun=0;
while (1) {
if ((time-$lastrun)>5) {
$checkqueue = 1; # FIXME during testing, this line forces the loop. REMOVE it to use SIG{HUP} when "daemonized" !
# clean DB
my $now = time();
# delete z3950queue entries that are more than 1 day old
my $sth = $dbh->prepare("delete from z3950queue where ?-startdate > 86400");
$sth->execute($now);
# delete z3950results queries that are more than 1 hour old
$sth = $dbh->prepare("delete from z3950results where ?-startdate > 3600");
$sth->execute($now);
if ($checkqueue) { # everytime a SIG{HUP} is recieved
$checkqueue=0;
# parse every entry in QUEUE
$sth=$dbh->prepare("select id,term,type,servers,identifier from z3950queue where done<>1 or done is null order by id");
$sth->execute;
while (my ($id, $term, $type, $servers,$random) = $sth->fetchrow) {
# FIXME: there is no "else". So, if more than 12 requests at the same time => requests are lost !
if ($forkcounter<12) {
my $now=time();
# search for results entries for this request
my $stk=$dbh->prepare("select id,server,startdate,enddate,numrecords,active from z3950results where queryid=?");
($stk->execute($id)) || (next);
my %serverdone;
# if no results => set queue to done = -1, set startdate and begin creating z3950results table entries & z3950 queries
unless ($stk->rows) {
my $sti=$dbh->prepare("update z3950queue set done=-1,startdate=? where id=?");
$sti->execute($now,$id);
}
# check which servers calls have already been created (before a crash)
while (my ($r_id, $r_server,$r_startdate,$r_enddate,$r_numrecords,$active) = $stk->fetchrow) {
if ($r_enddate >0) { # result entry exist & finished
$serverdone{$r_server}=1;
} elsif ($active) { # result entry exists & on the way (active=1) or already done (active=-1)
$serverdone{$r_server}=1;
} else { # otherwise
$serverdone{$r_server}=-1;
}
# note that is the entry doesn't exist, the $serverdone{$r_server} is 0 (important later !)
}
$stk->finish;
foreach my $serverinfo (split(/\|/, $servers)) {
(next) if ($serverdone{$serverinfo} == 1); #(otherwise, is 0 or -1)
my $totalrecords=0;
my $globalname;
my $globalsyntax;
my $globalencoding;
# fork a process for this z3950 query
if (my $pid=fork()) {
$forkcounter++;
} else {
# and connect to z3950 server
#FIXME: why do we need $dbi ? can't we use $dbh ?
my $db_driver = C4::Context->config("db_scheme") || "mysql";
my $db_name = C4::Context->config("database");
my $db_host = C4::Context->config("hostname");
my $db_user = C4::Context->config("user");
my $db_passwd = C4::Context->config("pass");
my $dbi = DBI->connect("DBI:$db_driver:$db_name:$db_host",$db_user, $db_passwd);
$dbh->{"InactiveDestroy"} = "true";
my ($name, $server, $database, $user, $password,$syntax) = split(/\//, $serverinfo, 6);
$globalname=$name;
$globalsyntax = $syntax;
$server=~/(.*)\:(\d+)/;
my $servername=$1;
my $port=$2;
my $attr='';
if ($type eq 'isbn') {
$attr='1=7';
} elsif ($type eq 'title') {
$attr='1=4';
} elsif ($type eq 'author') {
$attr='1=1003';
} elsif ($type eq 'lccn') {
$attr='1=9';
} elsif ($type eq 'keyword') {
$attr='1=1016';
}
my $query = "\@attr $attr \"$term\"";
print "$$/$id : Processing $type=$term at $name $server $database $syntax (".($forkcounter+1)." forks)\n";
# try to connect
my $conn;
my $noconnection=0;
my $error=0;
# the z3950 query is builded. Launch it.
if ($user) {
$conn= new ZOOM::Connection($servername, $port, databaseName => $database, user => $user, password => $password) || ($noconnection=1);
} else {
$conn= new ZOOM::Connection($servername, $port, databaseName => $database) || ($noconnection=1);
}
if ($noconnection || $error) {
# if connection impossible, don't go further !
print "$$/$id : no connection at $globalname\n";
my $result = MARC::Record->new();
my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($result,-1,"$globalname server is NOT responding","",$random);
} else {
# else, build z3950 query and do it !
$now=time();
my $resultsid="";
# create z3950results entries.
if ($serverdone{$serverinfo}==-1) { # if entry exist, just retrieve it
my $stj=$dbi->prepare("select id from z3950results where server=? and queryid=?");
$stj->execute($serverinfo,$id);
($resultsid) = $stj->fetchrow;
$stj->finish;
print "$$/$id : 1 >> $resultsid\n";
} else { # else create it : (may be serverdone=1 or 0)
my $stj=$dbi->prepare("select id from z3950results where server=? and queryid=?");
$stj->execute($serverinfo,$id);
($resultsid) = $stj->fetchrow;
$stj->finish;
print "$$/$id : 2 >> $resultsid\n";
unless ($resultsid) {
$stj=$dbi->prepare("insert into z3950results (server, queryid, startdate) values (?,?,?)");
$stj->execute($serverinfo, $id, $now);
$resultsid=$dbi->{'mysql_insertid'};
$stj->finish;
print "$$/$id : creating and ";
}
}
print "$$/$id : working on results entry $resultsid\n";
# set active to 1 => this request is on the way.
my $stj=$dbi->prepare("update z3950results set active=1 where id=?");
$stj->execute($resultsid);
#######
print "$$/$id : connected to $globalname\n";
print "Global Syntax =>".$globalsyntax."<=";
eval {$conn->option(elementSetName => 'F')};
eval { $conn->option(preferredRecordSyntax => 'USMARC');} if ($globalsyntax eq "USMARC");
eval { $conn->option(preferredRecordSyntax => 'UNIMARC');} if ($globalsyntax eq "UNIMARC");
if ($@) {
print "$$/$id : $globalname ERROR: $@ for $resultsid\n";
# in case pb during connexion, set result to "empty" to avoid everlasting loops
my $stj=$dbi->prepare("update z3950results set numrecords=?,numdownloaded=?,highestseen=0,results='',enddate=? where id=?");
$stj->execute(0,0,$now,$resultsid);
} else {
my $rs=$conn->search_pqf($query) or warn "Connection Problem:".$conn->errmsg();
pe();
# we have an answer for a query => get results & store them in marc_breeding table
my $numresults=$rs->size();
if ($numresults eq 0) {
print "$$/$id : $globalname : no records found\n";
} else {
print "$$/$id : $globalname : $numresults records found, retrieving them (max 80)\n";
}
pe();
my $i;
my $result='';
my $scantimerstart=time();
for ($i=1; $i<=(($numresults<80) ? ($numresults) : (80)); $i++) {
my $rec=$rs->record($i-1);
my $marcdata = $rec->raw();
#my $marcrecord = MARC::Record->new_from_usmarc($marcdata);
#warn $marcrecord->as_formatted();
$globalencoding = ref($rec);
$result.=$marcdata;
}
my @x=split /::/,$globalencoding;
my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported) = ImportBreeding($result,-1,"Z3950-$globalname",$x[3],$random);
my $scantimerend=time();
my $numrecords;
($numresults<80) ? ($numrecords=$numresults) : ($numrecords=80);
my $elapsed=$scantimerend-$scantimerstart;
if ($elapsed) {
my $speed=int($numresults/$elapsed*100)/100;
print "$$/$id : $globalname : $server records retrieved $numrecords SPEED: $speed\n";
}
my $q_result=$dbi->quote($result);
($q_result) || ($q_result='""');
$now=time();
if ($numresults >0) {
my $stj=$dbi->prepare("update z3950results set numrecords=?,numdownloaded=?,highestseen=0,results=?,enddate=? where id=?");
$stj->execute($numresults,$numrecords,$q_result,$now,$resultsid);
} else { # no results...
my $stj=$dbi->prepare("update z3950results set numrecords=?,numdownloaded=?,highestseen=0,results='',enddate=? where id=?");
$stj->execute($numresults,$numrecords,$now,$resultsid);
}
}
$stj=$dbi->prepare("update z3950results set active=-1 where id=?");
$stj->execute($resultsid);
eval {my $stj->finish};
}
#OK, the search is done inactivate it..
print "$$/$id : $server search done.\n";
exit;
}
}
} else {
# $forkcounter >=12
}
# delete z3950queue entry, as everything is done
my $sti=$dbh->prepare("update z3950queue set done=1,enddate=? where id=?");
$now=time();
$sti->execute($now,$id);
}
$lastrun=time();
}
sleep 10;
}
}
sub reap {
$forkcounter--;
wait;
}
sub checkqueue {
$checkqueue=1;
}
sub pe {
return 0;
}

View File

@ -19,94 +19,210 @@
use strict;
use CGI;
use C4::Auth;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Biblio;
use C4::Context;
use C4::Koha; # XXX subfield_is_koha_internal_p
use C4::Z3950;
use C4::Search;
use C4::Breeding;
use HTML::Template;
use MARC::File::USMARC;
use vars qw( $tagslib );
use vars qw( $is_a_modif );
use ZOOM;
use Encode;;
my $input = new CGI;
my $dbh = C4::Context->dbh;
my $error = $input->param('error');
my $bibid=$input->param('bibid');
my $oldbiblionumber=$input->param('oldbiblionumber');
$oldbiblionumber=0 unless $oldbiblionumber;
my $title = $input->param('title');
my $author = $input->param('author');
my $isbn = $input->param('isbn');
my $issn = $input->param('issn');
my $random = $input->param('random');
my $op=$input->param('op');
my $noconnection;
my $numberpending;
my $attr='';
my $term;
my $host;
my $server;
my $database;
my $port;
my $marcdata;
my $encoding=C4::Context->preference("marcflavour");
my @results;
my $count;
my $toggle;
my @breeding_loop = ();
my $record;
my $biblionumber;
if ($bibid > 0) {
$record = MARCgetbiblio($dbh,$bibid);
$biblionumber=MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid);
my $oldbiblio;
my $dbh = C4::Context->dbh;
my $errmsg;
my @serverloop=();
my @serverhost;
unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
$random =rand(1000000000);
}
my $errmsg;
unless ($random) { # if random is a parameter => we're just waiting for the search to end, it's a refresh.
if ($isbn) {
$random =rand(1000000000);
$errmsg = addz3950queue($isbn, "isbn", $random, 'CHECKED');
} elsif ($author) {
$random =rand(1000000000);
$errmsg = addz3950queue($author, "author", $random, 'CHECKED');
} elsif ($title) {
$random =rand(1000000000);
$errmsg = addz3950queue($title, "title", $random, 'CHECKED');
}
my ($template, $loggedinuser, $cookie);
if ($op ne "do_search"){
my $sth=$dbh->prepare("select id,host,checked from z3950servers order by host");
$sth->execute();
while ($server=$sth->fetchrow_hashref) {
my %temploop;
$temploop{server}=$server->{host};
$temploop{id}=$server->{id};
$temploop{checked}=$server->{checked};
push (@serverloop, \%temploop);
}
my ($template, $loggedinuser, $cookie)
($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "z3950/searchresult.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
authnotrequired => 1,
flagsrequired => {catalogue => 1},
debug => 1,
});
$template->param(isbn=>$isbn, issn=>$issn,title=>$title,author=>$author,
serverloop => \@serverloop,
opsearch => "search",
oldbiblionumber => $oldbiblionumber,
);
output_html_with_http_headers $input, $cookie, $template->output;
# fill with books in breeding farm
($count, @results) = BreedingSearch($title,$isbn,$random);
my $numberpending= &checkz3950searchdone($random);
my @breeding_loop = ();
for (my $i=0; $i <= $#results; $i++) {
my %row_data;
}else{
my @id=$input->param('id');
my @oConnection;
my @oResult;
my $s=0;
if ($isbn ne "/" || $issn ne "/") {
$attr='1=7';
$term=$isbn if ($isbn ne"/");
$term=$issn if ($issn ne"/");
} elsif ($title ne"/") {
$attr='1=4 @attr 4=1 ';
$term=$title;
} elsif ($author ne "/") {
$attr='1=1003';
$term=$author;
}
my $query="\@attr $attr \"$term\"";
foreach my $servid ( @id){
my $sth=$dbh->prepare("select name, port, db, host from z3950servers where id=?");
$sth->execute($servid);
while ($server=$sth->fetchrow_hashref) {
my $noconnection=0;
#$numberpending=1;
my $option1=new ZOOM::Options();
$option1->option(async=>1);
$option1->option('elementSetName', 'F');
$option1->option('databaseName',$server->{db}) ;
$option1->option('preferredRecordSyntax', 'USMARC');
$oConnection[$s]=create ZOOM::Connection($option1);
$oConnection[$s]->connect($server->{name}, $server->{port});
$serverhost[$s]=$server->{host};
$s++;
}## while fetch
}# foreach
my $nremaining = $s;
my $firstresult=1;
for (my $z=0 ;$z<$s;$z++){
$oResult[$z] = $oConnection[$z]->search_pqf($query);
}
AGAIN:
my $k;
my $event;
while (($k = ZOOM::event(\@oConnection)) != 0) {
$event = $oConnection[$k-1]->last_event();
# warn ("connection ", $k-1, ": event $event (", ZOOM::event_str($event), ")\n");
last if $event == ZOOM::Event::ZEND;
}
if ($k != 0) {
$k--;
#warn $serverhost[$k];
my($error, $errmsg, $addinfo, $diagset) = $oConnection[$k]->error_x();
if ($error) {
warn "$k $serverhost[$k] error $query: $errmsg ($error) $addinfo\n";
goto MAYBE_AGAIN;
}
my $numresults=$oResult[$k]->size() ;
my $i;
my $result='';
if ($numresults>0){
for ($i=0; $i<(($numresults<5) ? ($numresults) : (5)) ; $i++) {
my $rec=$oResult[$k]->record($i);
my $marcrecord;
$marcdata = $rec->raw();
$marcrecord = MARC::File::USMARC::decode($marcdata);
my $marcxml=$marcrecord->as_xml_record($marcrecord);
$marcxml=Encode::encode('utf8',$marcxml);
#$marcxml=Encode::decode('utf8',$marcxml);
my $xmlhash=XML_xml2hash_onerecord($marcxml);
my $oldbiblio = XMLmarc2koha_onerecord($dbh,$xmlhash,'biblios');
$oldbiblio->{isbn} =~ s/ |-|\.//g,
$oldbiblio->{isbn} = substr($oldbiblio->{isbn},0,10);
$oldbiblio->{issn} =~ s/ |-|\.//g,
$oldbiblio->{issn} = substr($oldbiblio->{issn},0,10);
my ($notmarcrecord,$alreadyindb,$alreadyinfarm,$imported,$bid)=ImportBreeding($marcdata,1,$serverhost[$k],$encoding,$random);
my %row_data;
@breeding_loop = ();
if ($i % 2) {
$toggle="#ffffcc";
} else {
$toggle="white";
}
$row_data{toggle} = $toggle;
$row_data{id} = $results[$i]->{'id'};
$row_data{isbn} = $results[$i]->{'isbn'};
$row_data{file} = $results[$i]->{'file'};
$row_data{title} = $results[$i]->{'title'};
$row_data{author} = $results[$i]->{'author'};
$row_data{server} = $serverhost[$k];
$row_data{isbn} = $oldbiblio->{isbn};
$row_data{title} =$oldbiblio->{title};
$row_data{author} = $oldbiblio->{author};
$row_data{id} = $bid;
$row_data{oldbiblionumber}=$oldbiblionumber;
push (@breeding_loop, \%row_data);
}
$template->param(isbn => $isbn,
title => $title,
author => $author,
}# $numresults
}#for up to 5 results
}# if $k !=0
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "z3950/searchresult.tmpl",
query => $input,
type => "intranet",
authnotrequired => 1,
flagsrequired => {catalogue => 1},
debug => 1,
});
$numberpending=$nremaining-1;
$template->param(
breeding_loop => \@breeding_loop,
refresh => ($numberpending eq 0 ? "" : "search.pl?bibid=$bibid&random=$random"),
# refresh=>($numberpending eq 0 ? "" : "search.pl?random=$random"),
numberpending => $numberpending,
oldbiblionumber => $oldbiblio->{'biblionumber'},
# oldbiblionumber => $oldbiblionumber,
);
print $input->header(
-type => guesstype($template->output),
-cookie => $cookie
),$template->output;
output_html_with_http_headers $input, "", $template->output if $firstresult==1;
$firstresult++;
print $template->output if $firstresult !=1;
MAYBE_AGAIN:
if (--$nremaining > 0) {
goto AGAIN;
}
} ## if op=search

View File

@ -1,313 +0,0 @@
#!/usr/bin/perl -w
#
# Copyright 2000-2002 Katipo Communications
#
# 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 2 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.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
#-----------------------------------
# Script Name: zed-koha-server.pl
# Script Version: 1.4
# Date: 2004/06/02
# Author: Joshua Ferraro [jmf at kados dot org]
# Description: A very basic Z3950 Server
# Usage: zed-koha-server.pl
# Revision History:
# 0.00 2003/08/14: Original version; search works.
# 0.01 2003/10/02: First functional version; search and fetch working
# records returned in USMARC (ISO2709) format,
# Bath compliant to Level 1 in Functional Areas A, B.
# 0.02 2004/04/14: Cleaned up documentation, etc. No functional
# changes.
# 1.30 2004/04/22: Changing version numbers to correspond with CVS;
# Fixed the substitution bug (e.g., 4=100 before 4=1);
# Added support for the truncation attribute (5=1 and
# 5=100; thanks to Tomasz M. Wolniewicz for pointing
# out these improvements)
# 1.4.0 2004/06/02: Changed sql queries to account for the difference
# between bibid and biblionumber. Thanks again to
# Tomasz M. Wolniewicz for suggesting a great solution
# to this problem.
#-----------------------------------
# Note: After installing SimpleServer (indexdata.dk/simpleserver) and
# changing the leader information in Koha's MARCgetbiblio subroutine in
# Biblio.pm you can run this script as root:
#
# ./zed-koha-server.pl
#
# and the server will start running on port 9999 and will allow searching
# and retrieval of records in MARC21 (USMARC; ISO2709) bibliographic format.
# ----------------------------------
use DBI;
use Net::Z3950::OID;
use Net::Z3950::SimpleServer;
use MARC::Record;
use C4::Context;
use C4::Biblio;
use strict;
# my $dbh = C4::Context->dbh;
my @bib_list; ## Stores the list of biblionumbers in a query
## I should eventually move this to different scope
my $handler = Net::Z3950::SimpleServer->new(INIT => \&init_handler,
SEARCH => \&search_handler,
FETCH => \&fetch_handler);
$handler->launch_server("zed-koha-server.pl", @ARGV);
sub init_handler {
my $args = shift;
my $session = {};
# FIXME: I should force use of my database name
$args->{IMP_NAME} = "Zed-Koha";
$args->{IMP_VER} = "1.40";
$args->{ERR_CODE} = 0;
$args->{HANDLE} = $session;
if (defined($args->{PASS}) && defined($args->{USER})) {
printf("Received USER/PASS=%s/%s\n", $args->{USER},$args->{PASS});
}
}
sub run_query { ## Run the query and store the biblionumbers:
my ($sql_query, $query, $args) = @_;
my $dbh = C4::Context->dbh;
my $sth_get = $dbh->prepare("$sql_query");
## Send the query to the database:
$sth_get->execute($query);
my $count = 0;
while(my ($data)=$sth_get->fetchrow_array) {
## Store Biblioitem info for later
$bib_list[$count] = "$data";
## Implement count:
$count ++;
}
$args->{HITS} = $count;
print "got search: ", $args->{RPN}->{query}->render(), "\n";
}
sub search_handler {
my($args) = @_;
## Place the user's query into a variable
my $query = $args->{QUERY};
## The actual Term
my $term = $args->{term};
$term =~ s| |\%|g;
$term .= "\%"; ## Add the wildcard to search term
$_ = "$query";
## Strip out the junk and call the mysql query subroutine:
if (/1=7/) { ## isbn
$query =~ s|\@attrset 1.2.840.10003.3.1 \@attr 1=7 ||g;
$query =~ s|"||g;
$query =~ s| |%|g;
## Bib-1 Structure Attributes:
$query =~ s|\@attr||g;
$query =~ s|4=100||g; ## date (un-normalized)
$query =~ s|4=101||g; ## name (normalized)
$query =~ s|4=102||g; ## sme (un-normalized)
$query =~ s|4=1||g; ## Phrase
$query =~ s|4=2||g; ## Keyword
$query =~ s|4=3||g; ## Key
$query =~ s|4=4||g; ## year
$query =~ s|4=5||g; ## Date (normalized)
$query =~ s|4=6||g; ## word list
$query =~ s|5=100||g; ## truncation
$query =~ s|5=1||g; ## truncation
$query =~ s|\@and ||g;
$query =~ s|2=3||g;
$query =~ s|,|%|g; ## replace commas with wildcard
$query .= "\%"; ## Add the wildcard to search term
$query .= "\%"; ## Add the wildcard to search term
print "The term was:\n";
print "$term\n";
print "The query was:\n";
print "$query\n";
my $sql_query = "SELECT marc_biblio.bibid FROM marc_biblio RIGHT JOIN biblioitems ON marc_biblio.biblionumber = biblioitems.biblionumber WHERE biblioitems.isbn LIKE ?";
&run_query($sql_query, $query, $args);
}
elsif (/1=1003/) { ## author
$query =~ s|\@attrset||g;
$query =~ s|1.2.840.10003.3.1||g;
$query =~ s|1=1003||g;
## Bib-1 Structure Attributes:
$query =~ s|\@attr ||g;
$query =~ s|4=100||g; ## date (un-normalized)
$query =~ s|4=101||g; ## name (normalized)
$query =~ s|4=102||g; ## sme (un-normalized)
$query =~ s|4=1||g; ## Phrase
$query =~ s|4=2||g; ## Keyword
$query =~ s|4=3||g; ## Key
$query =~ s|4=4||g; ## year
$query =~ s|4=5||g; ## Date (normalized)
$query =~ s|4=6||g; ## word list
$query =~ s|5=100||g; ## truncation
$query =~ s|5=1||g; ## truncation
$query =~ s|2=3||g;
$query =~ s|"||g;
$query =~ s| |%|g;
$query .= "\%"; ## Add the wildcard to search term
print "$query\n";
my $sql_query = "SELECT marc_biblio.bibid FROM marc_biblio RIGHT JOIN biblio ON marc_biblio.biblionumber = biblio.biblionumber WHERE biblio.author LIKE ?";
&run_query($sql_query, $query, $args);
## used for debugging--works!
## print "@bib_list\n";
}
elsif (/1=4/) { ## title
$query =~ s|\@attrset||g;
$query =~ s|1.2.840.10003.3.1||g;
$query =~ s|1=4||g;
$query =~ s|"||g;
$query =~ s| |%|g;
## Bib-1 Structure Attributes:
$query =~ s|\@attr||g;
$query =~ s|4=100||g; ## date (un-normalized)
$query =~ s|4=101||g; ## name (normalized)
$query =~ s|4=102||g; ## sme (un-normalized)
$query =~ s|4=1||g; ## Phrase
$query =~ s|4=2||g; ## Keyword
$query =~ s|4=3||g; ## Key
$query =~ s|4=4||g; ## year
$query =~ s|4=5||g; ## Date (normalized)
$query =~ s|4=6||g; ## word list
$query =~ s|5=100||g; ## truncation
$query =~ s|5=1||g; ## truncation
$query =~ s|2=3||g;
#$query =~ s|\@and||g;
$query .= "\%"; ## Add the wildcard to search term
print "The term was:\n";
print "$term\n";
print "The query was:\n";
print "$query\n";
my $sql_query = "SELECT marc_biblio.bibid FROM marc_biblio RIGHT JOIN biblio ON marc_biblio.biblionumber = biblio.biblionumber WHERE biblio.title LIKE ?";
&run_query($sql_query, $query, $args);
}
elsif (/1=21/) { ## subject
$query =~ s|\@attrset 1.2.840.10003.3.1 \@attr 1=21 ||g;
$query =~ s|"||g;
$query =~ s| |%|g;
## Bib-1 Structure Attributes:
$query =~ s|\@attr ||g;
$query =~ s|4=100||g; ## date (un-normalized)
$query =~ s|4=101||g; ## name (normalized)
$query =~ s|4=102||g; ## sme (un-normalized)
$query =~ s|4=1||g; ## Phrase
$query =~ s|4=2||g; ## Keyword
$query =~ s|4=3||g; ## Key
$query =~ s|4=4||g; ## year
$query =~ s|4=5||g; ## Date (normalized)
$query =~ s|4=6||g; ## word list
$query =~ s|5=100||g; ## truncation
$query =~ s|5=1||g; ## truncation
$query .= "\%"; ## Add the wildcard to search term
print "$query\n";
my $sql_query = "SELECT marc_biblio.bibid FROM marc_biblio RIGHT JOIN biblio ON marc_biblio.biblionumber = biblio.biblionumber WHERE biblio.subject LIKE ?";
&run_query($sql_query, $query, $args);
}
elsif (/1=1016/) { ## any
$query =~ s|\@attrset 1.2.840.10003.3.1 \@attr 1=1016 ||g;
$query =~ s|"||g;
$query =~ s| |%|g;
## Bib-1 Structure Attributes:
$query =~ s|\@attr||g;
$query =~ s|4=100||g; ## date (un-normalized)
$query =~ s|4=101||g; ## name (normalized)
$query =~ s|4=102||g; ## sme (un-normalized)
$query =~ s|4=1||g; ## Phrase
$query =~ s|4=2||g; ## Keyword
$query =~ s|4=3||g; ## Key
$query =~ s|4=4||g; ## year
$query =~ s|4=5||g; ## Date (normalized)
$query =~ s|4=6||g; ## word list
$query =~ s|5=100||g; ## truncation
$query =~ s|5=1||g; ## truncation
$query .= "\%"; ## Add the wildcard to search term
print "$query\n";
my $sql_query = "SELECT bibid FROM marc_word WHERE word LIKE?";
&run_query($sql_query, $query, $args);
}
}
sub fetch_handler {
my ($args) = @_;
# warn "in fetch_handler"; ## troubleshooting
my $offset = $args->{OFFSET};
$offset -= 1; ## because $args->{OFFSET} 1 = record #1
chomp (my $bibid = $bib_list[$offset]); ## Not sure about this
## print "the bibid is:$bibid\n";
my $dbh = C4::Context->dbh;
my $MARCRecord = &MARCgetbiblio($dbh,$bibid);
$MARCRecord->leader(' nac 22 1u 4500');
## Set the REP_FORM
$args->{REP_FORM} = &Net::Z3950::OID::unimarc;
## Return the record string to the client
$args->{RECORD} = $MARCRecord->as_usmarc();
# $args->{RECORD} = $recordstringdone;
}
## This stuff doesn't work yet...I should include boolean searching someday
## though
package Net::Z3950::RPN::Term;
sub render {
my $self = shift;
return '"' . $self->{term} . '"';
}
package Net::Z3950::RPN::And;
sub render {
my $self = shift;
return '(' . $self->[0]->render() . ' AND ' .
$self->[1]->render() . ')';
}
package Net::Z3950::RPN::Or;
sub render {
my $self = shift;
return '(' . $self->[0]->render() . ' OR ' .
$self->[1]->render() . ')';
}
package Net::Z3950::RPN::AndNot;
sub render {
my $self = shift;
return '(' . $self->[0]->render() . ' ANDNOT ' .
$self->[1]->render() . ')';
}

View File

@ -1,83 +0,0 @@
#!/bin/sh
# $Id$
# Script to start Koha background Z39.50 search daemon
# Part of the Koha Library Mgmt System - www.koha.org
# Licensed under the GPL
#----------------------------
# Call this script during system startup, such as from rc.local
# Bugs/To Do:
# Needs SysV-type start/stop options
#----------------------------
. $(dirname $0)/z3950-daemon-options
export KohaZ3950Dir
#----------------------------
if [ ! -d $KohaZ3950Dir ]
then
echo ERROR: Cannot find Koha directory $KohaZ3950Dir
exit 1
fi
KohaZ3950Shell=$KohaZ3950Dir/z3950-daemon-shell.sh
if [ ! -x $KohaZ3950Shell ]
then
echo ERROR: Cannot find Koha Z39.50 daemon launcher $KohaZ3950Shell
exit 1
fi
su -c $KohaZ3950Shell - $RunAsUser &
exit
#--------------
# $Log$
# Revision 1.6 2005/10/26 09:13:54 tipaul
# big commit, still breaking things...
#
# * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply.
# * code cleaning (cleaning warnings from perl -w) continued
#
# Revision 1.4.4.1 2005/06/27 23:10:55 hdl
# Removing -s from su call after Thomas D reports it breaks FreeBSD
#
# Revision 1.4 2003/11/05 23:33:45 slef
# Now figures out what directory the scripts are in
#
# Revision 1.3 2003/10/06 09:10:39 slef
# Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39)
#
# Revision 1.2 2003/04/29 16:48:25 tipaul
# really proud of this commit :-)
# z3950 search and import seems to works fine.
# Let me explain how :
# * a "search z3950" button is added in the addbiblio template.
# * when clicked, a popup appears and z3950/search.pl is called
# * z3950/search.pl calls addz3950search in the DB
# * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
# * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
# * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
#
# Note :
# * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support.
# * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup.
#
# Revision 1.1 2002/11/22 10:15:22 tipaul
# moving z3950 related scripts to specific dir
#
# Revision 1.3 2002/07/02 22:08:50 tonnesen
# merging changes from rel-1-2
#
# Revision 1.1.2.3 2002/06/26 19:56:57 tonnesen
# Bug fix. Single quotes were causing $KohaZ3950Shell variable to not get
# expanded
#
# Revision 1.1.2.2 2002/06/26 16:25:51 amillar
# Make directory variable name more explanatory
#

View File

@ -1,80 +0,0 @@
#!/bin/sh
# $Id$
# Script to start Koha background Z39.50 search daemon
# Part of the Koha Library Mgmt System - www.koha.org
# Licensed under the GPL
#----------------------------
# Do NOT run this script directly from system startup-- this should not run as root
# Call z3950-daemon-launch.sh instead
#----------------------------
. $(dirname $0)/z3950-daemon-options
#----------------------------
LOGFILE=$LogDir/z3950-daemon-`date +%Y%m%d-%H%M`.log
touch $LOGFILE
if [ ! -w $LOGFILE ]
then
echo ERROR: Cannot write to log file $LOGFILE
exit 1
fi
KohaZ3950Script=$KohaZ3950Dir/processz3950queue
if [ ! -x $KohaZ3950Script ]
then
echo ERROR: Cannot find Koha Z39.50 daemon script $KohaZ3950Script
exit 1
fi
PERL5LIB=$KohaModuleDir
export PERL5LIB
KOHA_CONF=$KohaConf
export KOHA_CONF
exec $KohaZ3950Script $LogDir >>$LOGFILE 2>&1
#-------------------
# $Log$
# Revision 1.5 2003/11/05 23:33:45 slef
# Now figures out what directory the scripts are in
#
# Revision 1.4 2003/10/20 19:16:50 slef
# Work on install bugs (see bug 632)
#
# Revision 1.3 2003/10/06 09:10:39 slef
# Removing config info from z3950*sh and using C4::Context in processz3950queue (Fixed bug 39)
#
# Revision 1.2 2003/04/29 16:48:25 tipaul
# really proud of this commit :-)
# z3950 search and import seems to works fine.
# Let me explain how :
# * a "search z3950" button is added in the addbiblio template.
# * when clicked, a popup appears and z3950/search.pl is called
# * z3950/search.pl calls addz3950search in the DB
# * the z3950 daemon retrieve the records and stores them in z3950results AND in marc_breeding table.
# * as long as there as searches pending, the popup auto refresh every 2 seconds, and says how many searches are pending.
# * when the user clicks on a z3950 result => the parent popup is called with the requested biblio, and auto-filled
#
# Note :
# * character encoding support : (It's a nightmare...) In the z3950servers table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this column. Depending on this, the char_decode in C4::Biblio.pm replaces marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import this value has been added too, for a better support.
# * the marc_breeding and z3950* tables have been modified : they have an encoding column and the random z3950 number is stored too for convenience => it's the key I use to list only requested biblios in the popup.
#
# Revision 1.1 2002/11/22 10:15:22 tipaul
# moving z3950 related scripts to specific dir
#
# Revision 1.3 2002/07/02 22:08:50 tonnesen
# merging changes from rel-1-2
#
# Revision 1.1.2.3 2002/06/28 17:45:39 tonnesen
# z3950queue now listens for a -HUP signal before processing the queue. Z3950.pm
# sends the -HUP signal when queries are added to the queue.
#
# Revision 1.1.2.2 2002/06/26 16:25:51 amillar
# Make directory variable name more explanatory
#