From b5f2bf3cd8734ca35df7fe43940140a4afec2aae Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Date: Wed, 16 Oct 2024 10:11:24 +0200
Subject: [PATCH] Bug 38177: Do not use stash to retrieve parameters

The pagination for EBSCO's titles, packages and resources is broken. We
shouldn't rely on $c->stash but use params from the request instead.

Test plan:
1) Setup all the system preferences in ERM:
<staff_url>/cgi-bin/koha/admin/preferences.pl?tab=erm
2) Enable EBSCO in ERMProviders. Set the ERMProviderEbscoApiKey and ERMProviderEbscoCustomerID prefs.
3) Do a search that returns more than 20 records. Click on a page other than 1. Notice the records do not change (Page is the same).
4) Apply patch. Repeat. Notice pagination now works.

Search titles, packages and resources
Use the pagination and modify the number of results per page

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
---
 Koha/ERM/Providers/EBSCO.pm                   | 4 ++--
 Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm  | 7 +------
 Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm | 7 +------
 Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm    | 7 +------
 4 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/Koha/ERM/Providers/EBSCO.pm b/Koha/ERM/Providers/EBSCO.pm
index c0904cb225..5e3aa377ef 100644
--- a/Koha/ERM/Providers/EBSCO.pm
+++ b/Koha/ERM/Providers/EBSCO.pm
@@ -210,10 +210,10 @@ sub embed {
 
 sub build_query_pagination {
     my ( $self, $params ) = @_;
-    my $per_page = $params->{per_page}
+    my $per_page = $params->{_per_page}
       // C4::Context->preference('RESTdefaultPageSize') // 20;
     if ( $per_page == -1 || $per_page > 100 ) { $per_page = 100; }
-    my $page = $params->{page} || 1;
+    my $page = $params->{_page} || 1;
 
     return ( $per_page, $page );
 }
diff --git a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm
index b4a59c4128..5f92ba2a6a 100644
--- a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm
+++ b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm
@@ -35,12 +35,7 @@ sub list {
         my $result     = $ebsco->request( GET => '/packages' . $params );
         my $base_total = $result->{totalResults};
 
-        my ( $per_page, $page ) = $ebsco->build_query_pagination(
-            {
-                per_page => $c->stash('koha.pagination.per_page'),
-                page     => $c->stash('koha.pagination.page'),
-            }
-        );
+        my ( $per_page, $page ) = $ebsco->build_query_pagination( $c->req->params->to_hash );
         my $additional_params =
           $ebsco->build_additional_params( $c->req->params->to_hash );
 
diff --git a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm
index 39ba226752..e8f3c44d20 100644
--- a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm
+++ b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm
@@ -73,12 +73,7 @@ sub list {
 
         my $base_total = $result->{totalResults};
 
-        my ( $per_page, $page ) = $ebsco->build_query_pagination(
-            {
-                per_page => $c->stash('koha.pagination.per_page'),
-                page     => $c->stash('koha.pagination.page'),
-            }
-        );
+        my ( $per_page, $page ) = $ebsco->build_query_pagination( $c->req->params->to_hash );
 
         my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash );
         my $searchfield = 'titlename';
diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm
index cacc1c84b5..d569e75ddc 100644
--- a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm
+++ b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm
@@ -41,12 +41,7 @@ sub list {
         my $ebsco = Koha::ERM::Providers::EBSCO->new;
 
         # We cannot get base_total as a search kw is required by the API
-        my ( $per_page, $page ) = $ebsco->build_query_pagination(
-            {
-                per_page => $c->stash('koha.pagination.per_page'),
-                page     => $c->stash('koha.pagination.page'),
-            }
-        );
+        my ( $per_page, $page ) = $ebsco->build_query_pagination( $c->req->params->to_hash );
 
         my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash );
 
-- 
2.39.5