Bug 15685: Send the basket to _cancel_items_receipt
[koha-ffzg.git] / C4 / XISBN.pm
index d04f2e7..cff35c9 100644 (file)
@@ -26,13 +26,16 @@ use C4::External::Syndetics qw(get_syndetics_editions);
 use LWP::UserAgent;
 use HTTP::Request::Common;
 
+use Koha::Biblios;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
 use strict;
 #use warnings; FIXME - Bug 2505
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 BEGIN {
        require Exporter;
-    $VERSION = 3.07.00.049;
        @ISA = qw(Exporter);
        @EXPORT_OK = qw(
                &get_xisbns
@@ -64,17 +67,20 @@ sub _get_biblio_from_xisbn {
     my $xisbn = shift;
     my $dbh = C4::Context->dbh;
 
-    my ( $errors, $results, $total_hits ) = C4::Search::SimpleSearch( "nb=$xisbn", 0, 1 );
+    my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
+    my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( "nb=$xisbn", 0, 1 );
     return unless ( !$errors && scalar @$results );
 
     my $record = C4::Search::new_record_from_zebra( 'biblioserver', $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;
+    my $biblio = Koha::Biblios->find( $biblionumber );
+    return unless $biblio;
+    my $isbn = $biblio->biblioitem->isbn;
+    $biblio = $biblio->unblessed;
+    $biblio->{normalized_isbn} = GetNormalizedISBN($isbn);
+    return $biblio;
 }
 
 =head1 get_xisbns($isbn);
@@ -85,7 +91,7 @@ sub _get_biblio_from_xisbn {
 
 sub get_xisbns {
     my ( $isbn ) = @_;
-    my ($response,$thing_response,$xisbn_response,$syndetics_response);
+    my ($response,$thing_response,$xisbn_response,$syndetics_response,$errors);
     # THINGISBN
     if ( C4::Context->preference('ThingISBN') ) {
         my $url = "http://www.librarything.com/api/thingISBN/".$isbn;
@@ -111,6 +117,8 @@ sub get_xisbns {
         unless ($reached_limit) {
             $xisbn_response = _get_url($url,'xisbn');
         }
+        $errors->{xisbn} = $xisbn_response->{ stat }
+            if $xisbn_response->{ stat } ne 'ok';
     }
 
     $response->{isbn} = [ @{ $xisbn_response->{isbn} or [] },  @{ $syndetics_response->{isbn} or [] }, @{ $thing_response->{isbn} or [] } ];
@@ -126,7 +134,12 @@ sub get_xisbns {
         my $xbiblio= _get_biblio_from_xisbn($response_data->{content});
         push @xisbns, $xbiblio if $xbiblio;
     }
-    return \@xisbns;
+    if ( wantarray ) {
+        return (\@xisbns, $errors);
+    }
+    else {
+        return \@xisbns;
+    }
 }
 
 sub _get_url {