From dd8b3c3da77562569b397c208d112107c4490bf2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 21 Jul 2023 16:35:05 +0200 Subject: [PATCH] Bug 34339: Avoid relying on $c->validation - ERM Signed-off-by: Tomas Cohen Arazi Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Providers/EBSCO.pm | 4 ++-- Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm | 13 +++++++----- Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm | 21 +++++++++++-------- Koha/REST/V1/ERM/EHoldings/Resources/Local.pm | 2 +- Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm | 11 +++++----- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Koha/ERM/Providers/EBSCO.pm b/Koha/ERM/Providers/EBSCO.pm index df2a525ba6..b39ddbba4f 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 1d7dfc7cbc..b4a59c4128 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages/EBSCO.pm @@ -30,13 +30,17 @@ sub list { return try { - my $args = $c->validation->output; my $params = '?orderby=packagename&offset=1&count=1'; my $ebsco = Koha::ERM::Providers::EBSCO->new; my $result = $ebsco->request( GET => '/packages' . $params ); my $base_total = $result->{totalResults}; - my ( $per_page, $page ) = $ebsco->build_query_pagination($args); + my ( $per_page, $page ) = $ebsco->build_query_pagination( + { + per_page => $c->stash('koha.pagination.per_page'), + page => $c->stash('koha.pagination.page'), + } + ); my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash ); @@ -61,9 +65,8 @@ sub list { $c->add_pagination_headers( { base_total => $base_total, - page => $args->{_page}, - per_page => $args->{_per_page}, - query_params => $args, + page => $page, + per_page => $per_page, total => $total, } ); diff --git a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm index a404c03998..39ba226752 100644 --- a/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Resources/EBSCO.pm @@ -38,13 +38,12 @@ sub list { return try { - my $args = $c->validation->output; - my $ebsco = Koha::ERM::Providers::EBSCO->new; + my $ebsco = Koha::ERM::Providers::EBSCO->new; # FIXME Do we need more validation here? Don't think so we have the API specs. my ( $vendor_id, $package_id ) = split '-', - $c->validation->param('package_id') || q{}; - my $title_id = $c->validation->param('title_id') || q{}; + $c->param('package_id') || q{}; + my $title_id = $c->param('title_id') || q{}; my $url = $title_id @@ -74,7 +73,12 @@ sub list { my $base_total = $result->{totalResults}; - my ( $per_page, $page ) = $ebsco->build_query_pagination($args); + my ( $per_page, $page ) = $ebsco->build_query_pagination( + { + per_page => $c->stash('koha.pagination.per_page'), + page => $c->stash('koha.pagination.page'), + } + ); my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash ); my $searchfield = 'titlename'; @@ -107,7 +111,6 @@ sub list { base_total => $base_total, page => $page, per_page => $per_page, - query_params => $args, total => $total, } ); @@ -127,7 +130,7 @@ sub get { return try { my ( $vendor_id, $package_id, $resource_id ) = split '-', - $c->validation->param('resource_id'); + $c->param('resource_id'); my $ebsco = Koha::ERM::Providers::EBSCO->new; my $t = try { return $ebsco->request( GET => '/vendors/' @@ -182,10 +185,10 @@ sub edit { my $c = shift or return; return try { - my $body = $c->validation->param('body'); + my $body = $c->req->json; my $is_selected = $body->{is_selected}; my ( $vendor_id, $package_id, $resource_id ) = split '-', - $c->validation->param('resource_id'); + $c->param('resource_id'); my $ebsco = Koha::ERM::Providers::EBSCO->new; my $t = try { diff --git a/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm b/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm index 40741f691d..96323c339c 100644 --- a/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Resources/Local.pm @@ -60,7 +60,7 @@ sub get { my $c = shift or return; return try { - my $resource_id = $c->validation->param('resource_id'); + my $resource_id = $c->param('resource_id'); my $resource = $c->objects->find( Koha::ERM::EHoldings::Resources->search, $resource_id ); unless ($resource ) { diff --git a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm index ca8743e57b..cacc1c84b5 100644 --- a/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm +++ b/Koha/REST/V1/ERM/EHoldings/Titles/EBSCO.pm @@ -38,13 +38,15 @@ sub list { return try { - my $args = $c->validation->output; - 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($args); + my ( $per_page, $page ) = $ebsco->build_query_pagination( + { + per_page => $c->stash('koha.pagination.per_page'), + page => $c->stash('koha.pagination.page'), + } + ); my $additional_params = $ebsco->build_additional_params( $c->req->params->to_hash ); @@ -86,7 +88,6 @@ sub list { #base_total => $base_total, page => $page, per_page => $per_page, - query_params => $args, total => $total, } ); -- 2.39.5