Bugzilla – Attachment 23144 Details for
Bug 11297
Add support for custom PQF attributes for Z39.50 server searches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Add support for custom Z39.50 attributes for Z39.50 servers.
0001-Add-support-for-custom-Z39.50-attributes-for-Z39.50-.patch (text/plain), 10.83 KB, created by
Frédérick Capovilla
on 2013-11-25 16:23:24 UTC
(
hide
)
Description:
Add support for custom Z39.50 attributes for Z39.50 servers.
Filename:
MIME Type:
Creator:
Frédérick Capovilla
Created:
2013-11-25 16:23:24 UTC
Size:
10.83 KB
patch
obsolete
>From 1088b08537d8ff491b1df82f24236860e8bb833c Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= <frederick.capovilla@libeo.com> >Date: Wed, 6 Nov 2013 12:34:21 -0500 >Subject: [PATCH 1/2] Add support for custom Z39.50 attributes for Z39.50 servers. > >This feature can be useful if a Z39.50 server requires a certain >attribute to always be set to return results. >--- > C4/Breeding.pm | 57 +++++++++++++++----- > admin/z3950servers.pl | 17 ++++--- > installer/data/mysql/updatedatabase.pl | 7 +++ > .../prog/en/modules/admin/z3950servers.tt | 3 + > 4 files changed, 63 insertions(+), 21 deletions(-) > >diff --git a/C4/Breeding.pm b/C4/Breeding.pm >index 8e01d41..1d20f4a 100644 >--- a/C4/Breeding.pm >+++ b/C4/Breeding.pm >@@ -254,59 +254,59 @@ sub Z3950Search { > my @oResult; > my @errconn; > my $s = 0; >- my $query; >+ my @query = ''; > my $nterms=0; > my $imported=0; > my @serverinfo; #replaces former serverhost, servername, encoding > > if ($isbn) { > $term=$isbn; >- $query .= " \@attr 1=7 \@attr 5=1 \"$term\" "; >+ push @query, "\@attr 1=7 \@attr 5=1 \"$term\""; > $nterms++; > } > if ($issn) { > $term=$issn; >- $query .= " \@attr 1=8 \@attr 5=1 \"$term\" "; >+ push @query, "\@attr 1=8 \@attr 5=1 \"$term\""; > $nterms++; > } > if ($title) { >- $query .= " \@attr 1=4 \"$title\" "; >+ push @query, "\@attr 1=4 \"$title\""; > $nterms++; > } > if ($author) { >- $query .= " \@attr 1=1003 \"$author\" "; >+ push @query, "\@attr 1=1003 \"$author\""; > $nterms++; > } > if ($dewey) { >- $query .= " \@attr 1=16 \"$dewey\" "; >+ push @query, "\@attr 1=16 \"$dewey\""; > $nterms++; > } > if ($subject) { >- $query .= " \@attr 1=21 \"$subject\" "; >+ push @query, "\@attr 1=21 \"$subject\""; > $nterms++; > } > if ($lccn) { >- $query .= " \@attr 1=9 $lccn "; >+ push @query, "\@attr 1=9 $lccn"; > $nterms++; > } > if ($lccall) { >- $query .= " \@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\" "; >+ push @query, "\@attr 1=16 \@attr 2=3 \@attr 3=1 \@attr 4=1 \@attr 5=1 \@attr 6=1 \"$lccall\""; > $nterms++; > } > if ($controlnumber) { >- $query .= " \@attr 1=12 \"$controlnumber\" "; >+ push @query, "\@attr 1=12 \"$controlnumber\""; > $nterms++; > } > if($srchany) { >- $query .= " \@attr 1=1016 \"$srchany\" "; >+ push @query, "\@attr 1=1016 \"$srchany\""; > $nterms++; > } > if($stdid) { >- $query .= " \@attr 1=1007 \"$stdid\" "; >+ push @query, "\@attr 1=1007 \"$stdid\""; > $nterms++; > } > for my $i (1..$nterms-1) { >- $query = "\@and " . $query; >+ $query[0] = "\@and " . $query[0]; > } > > my $dbh = C4::Context->dbh; >@@ -326,6 +326,35 @@ sub Z3950Search { > $oConnection[$s]->connect( $server->{host}, $server->{port} ); > $serverinfo[$s]->{host}= $server->{host}; > $serverinfo[$s]->{name}= $server->{name}; >+ # Add additional attributes if some specified >+ if($server->{attributes}) { >+ # Extract all additional server attributes >+ my %additional_attributes; >+ my @split_attributes = split(/\s+/, $server->{attributes}); >+ for(my $i=0; $i<=$#split_attributes; $i++) { >+ if($split_attributes[$i] eq "\@attr" and $split_attributes[$i+1] =~ /^(\d+)=\d+$/) { >+ $additional_attributes{$1} = $split_attributes[$i] . ' ' . $split_attributes[$i+1]; >+ $i++; >+ } >+ } >+ >+ # Clone the query and modify it >+ $serverinfo[$s]->{query} = [@query]; >+ foreach my $querypart (@{$serverinfo[$s]->{query}}) { >+ # Ignore parts without attributes >+ next if $querypart !~ /\@attr/; >+ # Only add additional attributes if they don't already exist in the query part >+ foreach my $attr_type (keys %additional_attributes) { >+ if($querypart !~ /\@attr $attr_type=/) { >+ $querypart = $additional_attributes{$attr_type} . ' ' . $querypart; >+ } >+ } >+ } >+ } >+ else { >+ # Use a reference to the original query >+ $serverinfo[$s]->{query} = \@query; >+ } > $serverinfo[$s]->{encd}= $server->{encoding} // "iso-5426"; > $s++; > } ## while fetch >@@ -333,7 +362,7 @@ sub Z3950Search { > my $nremaining = $s; > > for ( my $z = 0 ; $z < $s ; $z++ ) { >- $oResult[$z] = $oConnection[$z]->search_pqf($query); >+ $oResult[$z] = $oConnection[$z]->search_pqf( join(' ', @{$serverinfo[$z]->{query}}) ) > } > > while ( $nremaining-- ) { >diff --git a/admin/z3950servers.pl b/admin/z3950servers.pl >index 1dbd118..8907f69 100755 >--- a/admin/z3950servers.pl >+++ b/admin/z3950servers.pl >@@ -93,14 +93,14 @@ if ( $op eq 'add_form' ) { > if ($searchfield) { > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare( >-"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype from z3950servers where (name = ?) order by rank,name" >+"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype,attributes 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 timeout encoding )); >+ for (qw( host port db userid password checked rank timeout encoding attributes )); > $template->param( $_ . $data->{$_} => 1 ) for (qw( syntax recordtype )); > > # END $OP eq ADD_FORM >@@ -113,7 +113,7 @@ if ( $op eq 'add_form' ) { > my $checked = $input->param('checked') ? 1 : 0; > if ($sth->rows) { > $template->param(confirm_update => 1); >- $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,timeout=?,recordtype=? where name=?"); >+ $sth=$dbh->prepare("update z3950servers set host=?, port=?, db=?, userid=?, password=?, name=?, checked=?, rank=?,syntax=?,encoding=?,timeout=?,recordtype=?,attributes=? where name=?"); > $sth->execute($input->param('host'), > $input->param('port'), > $input->param('db'), >@@ -126,6 +126,7 @@ if ( $op eq 'add_form' ) { > $input->param('encoding'), > $input->param('timeout'), > $input->param('recordtype'), >+ $input->param('attributes'), > $input->param('searchfield'), > ); > } >@@ -133,15 +134,16 @@ if ( $op eq 'add_form' ) { > $template->param(confirm_add => 1); > $sth=$dbh->prepare( > "INSERT INTO z3950servers " . >- "(host,port,db,userid,password,name,checked,rank,syntax,encoding,timeout,recordtype) " . >- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); >+ "(host,port,db,userid,password,name,checked,rank,syntax,encoding,timeout,recordtype,attributes) " . >+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ); > $sth->execute( > $input->param('host'), $input->param('port'), > $input->param('db'), $input->param('userid'), > $input->param('password'), $input->param('searchfield'), > $checked, $input->param('rank'), > $input->param('syntax'), $input->param('encoding'), >- $input->param('timeout'), $input->param('recordtype') >+ $input->param('timeout'), $input->param('recordtype'), >+ $input->param('attributes') > ); > } > $sth->finish; >@@ -154,7 +156,7 @@ if ( $op eq 'add_form' ) { > my $dbh = C4::Context->dbh; > > my $sth2 = $dbh->prepare( >-"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype from z3950servers where (name = ?) order by rank,name" >+"select host,port,db,userid,password,name,id,checked,rank,syntax,encoding,timeout,recordtype,attributes from z3950servers where (name = ?) order by rank,name" > ); > $sth2->execute($searchfield); > my $data = $sth2->fetchrow_hashref; >@@ -171,6 +173,7 @@ if ( $op eq 'add_form' ) { > syntax => $data->{'syntax'}, > timeout => $data->{'timeout'}, > recordtype => $data->{'recordtype'}, >+ attributes => $data->{'attributes'}, > encoding => $data->{'encoding'} > ); > >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index b031ed8..9ace5cf 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -7330,6 +7330,13 @@ if ( CheckVersion($DBversion) ) { > SetVersion($DBversion); > } > >+$DBversion = "3.13.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do("ALTER TABLE z3950servers ADD COLUMN attributes VARCHAR(255);"); >+ print "Upgrade to $DBversion done (Add new column z3950servers.attributes)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($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 915e531..b3249c1 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/z3950servers.tt >@@ -139,6 +139,8 @@ > </li> > <li><label for="rank">Rank (display order): </label> <input type="text" name="rank" id="rank" size="4" value="[% rank %]" onblur="isNum(this)" /> > </li> >+ <li><label for="attributes">Attributes (additional PQF attributes added to each query): </label> <input type="text" name="attributes" id="attributes" size="30" value="[% attributes %]" /> >+ </li> > <li><label for="syntax">Syntax (z3950 can send<br /> records in various format. Choose one): </label> > <select name="syntax"> > [% IF ( syntaxUNIMARC ) %] >@@ -289,6 +291,7 @@ > <li><strong>Encoding: </strong>[% encoding %]</li> > <li><strong>Timeout: </strong>[% timeout %]</li> > <li><strong>Record type: </strong>[% recordtype %]</li> >+ <li><strong>Attributes: </strong>[% attributes %]</li> > </ul> <form action="[% script_name %]" method="post"><input type="hidden" name="op" value="delete_confirmed" /><input type="hidden" name="searchfield" value="[% searchfield %]" /><input type="submit" value="Delete this server" /></form> <form action="[% script_name %]" method="post"><input type="submit" value="Do not delete" /></form> > > >-- >1.7.2.5 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11297
:
23144
|
23145
|
40829
|
40889
|
48649
|
50415
|
50416
|
50420
|
50954
|
59448
|
62938
|
62939
|
70190
|
70191
|
70192
|
70193
|
70194
|
70195
|
70196
|
71992
|
71993
|
71994
|
72061
|
72062
|
72063
|
77718
|
77719
|
77720
|
77721
|
77722
|
77723
|
78294
|
78295
|
78296
|
78297
|
80372
|
80496
|
80497
|
80498
|
80499
|
81328
|
81342
|
81343
|
81344
|
81345
|
81346
|
92719
|
92720
|
92721
|
92722
|
98598
|
98599
|
98600
|
98601
|
99227
|
99228
|
99229
|
99230
|
99231