From 3b5151f8aa8e2f29af736176a26bf6b7bcea30a7 Mon Sep 17 00:00:00 2001 From: Fridolyn SOMERS Date: Thu, 28 Feb 2013 12:36:24 +0100 Subject: [PATCH] Bug 9728: XISBN use simple search instead of SQL XISBN API uses normalized ISBN of a biblio to get a list of ISBNs, then searches via SQL in database for notices with those ISBNs. I noticed that if input ISBN has hyphens then returned ISBNs have hyphens else they don't have. So SQL query will not find if ISBNs have hyphens in database. Also, if biblio has several ISBN, only first one can be found with actual SQL query (isbn LIKE '$xisbn%'). This patch replaces SQL query by a simple search "nb=$xisbn". This will find biblio from ISBN with or without hyphen. Test plan : - Activate FRBRizeEditions and XISBN sysprefs - Go to a biblio witch has several editions - Note its normalized ISBN (you may look in amazon links) - Replace [ISBN] by biblio normalized ISBN in this URL : http://xisbn.worldcat.org/webservices/xid/isbn/[ISBN]?method=getEditions&format=xml&fl=form,year,lang,ed - Go to this URL and see which ISBNs are returned - Perform a simple search on thoses ISBNs : nb:1234567890 - Look at "Editions" tab => Check that diplayed biblios are the same you found by simple search Signed-off-by: jmbroust --- C4/XISBN.pm | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) diff --git a/C4/XISBN.pm b/C4/XISBN.pm index 8616c95..ad63ff6 100644 --- a/C4/XISBN.pm +++ b/C4/XISBN.pm @@ -21,6 +21,7 @@ use XML::Simple; #use LWP::Simple; use C4::Biblio; use C4::Koha; +use C4::Search; use C4::External::Syndetics qw(get_syndetics_editions); use LWP::UserAgent; use HTTP::Request::Common; @@ -61,18 +62,19 @@ This module provides facilities for retrieving ThingISBN and XISBN content in Ko sub _get_biblio_from_xisbn { my $xisbn = shift; - $xisbn.='%'; my $dbh = C4::Context->dbh; - my $query = "SELECT biblionumber FROM biblioitems WHERE isbn LIKE ?"; - my $sth = $dbh->prepare($query); - $sth->execute($xisbn); - my $xbib_data = $sth->fetchrow_hashref(); - my $xbiblio; - if ($xbib_data->{biblionumber}) { - $xbiblio = GetBiblioData($xbib_data->{biblionumber}); - $xbiblio->{normalized_isbn} = GetNormalizedISBN($xbiblio->{isbn}); - } - return ($xbiblio); + + my ( $errors, $results, $total_hits ) = SimpleSearch( "nb=$xisbn", 0, 1 ); + return unless ( !$errors && scalar @$results ); + + my $record = MARC::Record::new_from_usmarc( $results->[0] ); + my $biblionumber = C4::Biblio::get_koha_field_from_marc('biblio', 'biblionumber', $record, ''); + return unless $biblionumber; + + my $xbiblio = GetBiblioData($biblionumber); + return unless $xbiblio; + $xbiblio->{normalized_isbn} = GetNormalizedISBN($xbiblio->{isbn}); + return $xbiblio; } =head1 get_xisbns($isbn); -- 1.7.2.5