From 7b6af9ceedeebf42db1a11b0002d7953260f935c Mon Sep 17 00:00:00 2001
From: Josef Moravec <josef.moravec@gmail.com>
Date: Wed, 13 Mar 2019 07:10:13 +0000
Subject: [PATCH] Bug 8995: (follow-up) Move GetOpenURLResolverURL to
 Koha::Biblio->get_openurl

---
 C4/Biblio.pm            | 29 -----------------------------
 C4/XSLT.pm              |  3 +--
 Koha/Biblio.pm          | 29 +++++++++++++++++++++++++++++
 t/db_dependent/Biblio.t |  6 +++---
 4 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index ab929eab9d..38508a5a16 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -1397,35 +1397,6 @@ sub GetCOinSBiblio {
     return $coins_value;
 }
 
-=head2 GetOpenURLResolverURL
-
-    my $url = C4::Biblio::GetOpenURLResolverURL($record);
-
-    Takes MARC::Record and return url for OpenURL resolver set in OpenURLResolverURL
-
-=cut
-
-sub GetOpenURLResolverURL {
-    my ($record) = @_;
-
-    my $coins = GetCOinSBiblio($record);
-    my $OpenURLResolverURL = C4::Context->preference('OpenURLResolverURL');
-
-    if ($OpenURLResolverURL) {
-        my $uri = URI->new($OpenURLResolverURL);
-
-        if (not defined $uri->query) {
-            $OpenURLResolverURL .= '?';
-        } else {
-            $OpenURLResolverURL .= '&amp;';
-        }
-        $OpenURLResolverURL .= $coins;
-    }
-
-    return $OpenURLResolverURL;
-}
-
-
 =head2 GetMarcPrice
 
 return the prices in accordance with the Marc format.
diff --git a/C4/XSLT.pm b/C4/XSLT.pm
index d4deee009b..b18ccda9a1 100644
--- a/C4/XSLT.pm
+++ b/C4/XSLT.pm
@@ -251,8 +251,7 @@ sub XSLTParse4Display {
         my $biblio = $biblio_object->biblioitem->unblessed;
         my @itypes = split( /\s/, C4::Context->preference('OPACOpenURLItemTypes') );
         if (grep /^$biblio->{itemtype}$/, @itypes) {
-            $variables->{OpenURLResolverURL} =
-              C4::Biblio::GetOpenURLResolverURL($orig_record);
+            $variables->{OpenURLResolverURL} = $biblio_object->get_openurl;
         }
     }
     my $varxml = "<variables>\n";
diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm
index d2e4d4d321..4ec405c49a 100644
--- a/Koha/Biblio.pm
+++ b/Koha/Biblio.pm
@@ -442,6 +442,35 @@ sub has_items_waiting_or_intransit {
     return 0;
 }
 
+=head2 get_openurl
+
+    my $biblio = Koha::Biblios->find( $biblionumber );
+    my $url = $biblio->get_openurl;
+
+    Takes MARC::Record and return url for OpenURL resolver set in OpenURLResolverURL
+
+=cut
+
+sub get_openurl {
+    my ( $self ) = @_;
+
+    my $coins = C4::Biblio::GetCOinSBiblio( $self->metadata->record);
+    my $OpenURLResolverURL = C4::Context->preference('OpenURLResolverURL');
+
+    if ($OpenURLResolverURL) {
+        my $uri = URI->new($OpenURLResolverURL);
+
+        if (not defined $uri->query) {
+            $OpenURLResolverURL .= '?';
+        } else {
+            $OpenURLResolverURL .= '&amp;';
+        }
+        $OpenURLResolverURL .= $coins;
+    }
+
+    return $OpenURLResolverURL;
+}
+
 =head3 type
 
 =cut
diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t
index bf37fac840..82f14b2f7c 100755
--- a/t/db_dependent/Biblio.t
+++ b/t/db_dependent/Biblio.t
@@ -574,7 +574,7 @@ subtest 'MarcFieldForCreatorAndModifier' => sub {
 Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
 $schema->storage->txn_rollback;
 
-subtest 'GetCOinSBiblio and GetOpenURLResolverURL' => sub {
+subtest 'GetCOinSBiblio and get_openurl' => sub {
     plan tests => 2;
 
     $schema->storage->txn_begin;
@@ -595,9 +595,9 @@ subtest 'GetCOinSBiblio and GetOpenURLResolverURL' => sub {
     );
 
     is(
-        C4::Biblio::GetOpenURLResolverURL($record),
+        $biblio->get_openurl,
         'https://koha.example.com/?ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Title%201&amp;rft.au=Author%201',
-        'GetOpenURLResolverURL returned right URL'
+        'Koha::Biblio->get_openurl returned right URL'
     );
 
     $schema->storage->txn_rollback;
-- 
2.11.0