From dd7fbbd70d5004c7fcf3b9d6a1b26c73d3fcebaa 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 bibliographic search instead of SQL to fetch related bibs XISBN API uses normalized ISBN of a biblio to get a list of ISBNs of related editions, then searched via SQL in database for biblios with those ISBNs. I noticed that if input ISBN has hyphens, the ISBNs returned by the OCLC XISBN service also have hyphens; otherwise, if the input ISBN doesn't have hyphens, the returned ISBNs don't either. Consequently, an SQL query on biblioitems.isbn may not turn up the right biblios. Also, if biblio has several ISBNs, only first one can be found with the original 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 Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton --- C4/XISBN.pm | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/C4/XISBN.pm b/C4/XISBN.pm index 12025f8857..1211f9f5c4 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); -- 2.39.5