Bug 19278: Make the pagination plugin use RESTdefaultPageSize

This bug introduces a new syspref RESTdefaultPageSize that is used on
the Koha::REST::Plugin::Pagination plugin to default to a valid value
for the page size if the param is not present on the query.

This patch also considers the situation in which no 'page' param is
passed, and no header should be added.

To test:
- Run:
  $ sudo koha-shell kohadev
 k$ cd kohaclone
 k$ prove t/Koha/REST/Plugin/Pagination.t
=> FAIL: Tests fail because the plugin doesn't behave as the tests
expect.
- Apply this patch
- Run:
 k$ prove t/Koha/REST/Plugin/Pagination.t
=> SUCCESS: Tests pass!
- Sign off :-D

Sponsored-by: Camden County
Sponsored-by: ByWater Solutions

Signed-off-by: Lari Taskula <lari.taskula@jns.fi>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2017-09-08 12:20:20 -03:00 committed by Jonathan Druart
parent a7d333f3cd
commit 54880b1a4e
1 changed files with 5 additions and 1 deletions

View File

@ -60,7 +60,11 @@ It also adds X-Total-Count, containing the total results count.
my $total = $args->{total};
my $req_page = $args->{params}->{_page};
my $per_page = $args->{params}->{_per_page};
my $per_page = $args->{params}->{_per_page} //
C4::Context->preference('RESTdefaultPageSize');
# do we need to paginate?
return $c unless $req_page;
my $pages = int $total / $per_page;
$pages++