From 39f48130416132063dfb7b44bcb8bf2344f1b9ef Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Tue, 25 Sep 2018 07:04:03 +0000 Subject: [PATCH] Bug 21404: Refactor _build_query subroutines Test plan: 1) Apply the patch 2) prove t/db_dependent/Breeding.t 3) Try to search using Z39.50, both, authority and biblio should still work Signed-off-by: Owen Leonard Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- C4/Breeding.pm | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/C4/Breeding.pm b/C4/Breeding.pm index db8a3a48a5..fc539d0044 100644 --- a/C4/Breeding.pm +++ b/C4/Breeding.pm @@ -147,7 +147,7 @@ sub Z3950Search { my $s = 0; my $imported=0; - my ( $zquery, $squery ) = _build_query( $pars ); + my ( $zquery, $squery ) = _bib_build_query( $pars ); my $schema = Koha::Database->new()->schema(); my $rs = $schema->resultset('Z3950server')->search( @@ -244,26 +244,11 @@ sub _auth_build_query { controlnumber => '@attr 1=12 "#term" ', }; - my $zquery=''; - my $squery=''; - my $nterms=0; - foreach my $k ( sort keys %$pars ) { - #note that the sort keys forces an identical result under Perl 5.18 - #one of the unit tests is based on that assumption - if( ( my $val=$pars->{$k} ) && $qry_build->{$k} ) { - $qry_build->{$k} =~ s/#term/$val/g; - $zquery .= $qry_build->{$k}; - $squery .= "[$k]=\"$val\" and "; - $nterms++; - } - } - $zquery = "\@and " . $zquery for 2..$nterms; - $squery =~ s/ and $//; - return ( $zquery, $squery ); - + return _build_query( $pars, $qry_build ); } -sub _build_query { +sub _bib_build_query { + my ( $pars ) = @_; my $qry_build = { @@ -280,6 +265,13 @@ sub _build_query { stdid => '@attr 1=1007 "#term" ', }; + return _build_query( $pars, $qry_build ); +} + +sub _build_query { + + my ( $pars, $qry_build ) = @_; + my $zquery=''; my $squery=''; my $nterms=0; -- 2.39.5