Bug 12537: Don't retrieve XISBN results for the same biblionumber
authorNick Clemens <nick@bywatersolutions.com>
Mon, 10 Jun 2019 18:54:30 +0000 (18:54 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 15 Jul 2019 10:27:59 +0000 (11:27 +0100)
For a biblio with multiple ISBNS we sometimes get our own record back when
check XISBN, we should test for this

To test:
1 - Edit a record in the catalogue, add two isbns:
     0521240670
     0521284198
2 - Enable ThingISBN and FRBRizeEditions and OPACFRBRizeEditions
3 - View the record in staff and OPAC
4 - You should see editions tab pointing to the same record
5 - Apply patch
6 - Reload the record details, you should no longer see editions tab
7 - Add the second ISBN to another record
8 - Reload details for original record, you shoudl see editions linking to the record with second ISBN
9 - prove -v t/db_dependent/XISBN.t

NOTE: Current tests don't work under elasticsearch, but the code does, tests should be rewritten on another bug

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com>
Signed-off-by: Arthur Bousquet <arthur.bousquet@inlibro.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/XISBN.pm
catalogue/detail.pl
opac/opac-detail.pl
t/db_dependent/XISBN.t

index 22b4502..1b3a3bb 100644 (file)
@@ -72,14 +72,14 @@ sub _get_biblio_from_xisbn {
     return $biblio;
 }
 
-=head1 get_xisbns($isbn);
+=head1 get_xisbns($isbn, $biblionumber);
 
 =head2 $isbn is an ISBN string
 
 =cut
 
 sub get_xisbns {
-    my ( $isbn ) = @_;
+    my ( $isbn, $biblionumber ) = @_;
     my ($response,$thing_response,$syndetics_response,$errors);
     # THINGISBN
     if ( C4::Context->preference('ThingISBN') ) {
@@ -107,7 +107,7 @@ sub get_xisbns {
         next if $unique_xisbns->{ $response_data->{content} };
         $unique_xisbns->{ $response_data->{content} }++;
         my $xbiblio= _get_biblio_from_xisbn($response_data->{content});
-        push @xisbns, $xbiblio if $xbiblio;
+        push @xisbns, $xbiblio if $xbiblio && $xbiblio->{biblionumber} ne $biblionumber;
     }
     if ( wantarray ) {
         return (\@xisbns, $errors);
index 027ca52..b7e4d6e 100755 (executable)
@@ -461,7 +461,7 @@ if (C4::Context->preference("virtualshelves") ) {
 if (C4::Context->preference("FRBRizeEditions")==1) {
     eval {
         $template->param(
-            XISBNS => scalar get_xisbns($isbn)
+            XISBNS => scalar get_xisbns($isbn, $biblionumber)
         );
     };
     if ($@) { warn "XISBN Failed $@"; }
index 7767bfa..8f044f5 100755 (executable)
@@ -918,7 +918,7 @@ if (C4::Context->preference("virtualshelves") ) {
 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
     eval {
         $template->param(
-            XISBNS => scalar get_xisbns($isbn)
+            XISBNS => scalar get_xisbns($isbn, $biblionumber)
         );
     };
     if ($@) { warn "XISBN Failed $@"; }
index 803743a..500bb6d 100755 (executable)
@@ -5,7 +5,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 3;
+use Test::More tests => 5;
 use MARC::Record;
 use C4::Biblio;
 use C4::XISBN;
@@ -62,6 +62,24 @@ SKIP: {
         "Gets correct biblionumber from a book with a similar isbn using ThingISBN." );
 }
 
+eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber1); };
+SKIP: {
+    skip "Problem retrieving ThingISBN", 1
+        unless $@ eq '';
+    is( $results_thingisbn->[0]->{biblionumber},
+        $biblionumber3,
+        "Gets correct biblionumber from a different book with a similar isbn using ThingISBN." );
+}
+
+eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber3); };
+SKIP: {
+    skip "Problem retrieving ThingISBN", 1
+        unless $@ eq '';
+    is( $results_thingisbn->[0]->{biblionumber},
+        undef,
+        "Doesn't get biblionumber if the biblionumber matches the one passed to the sub." );
+}
+
 # Util subs
 
 # Add new biblio with isbn and return biblionumber