Bug 25570: Paginate results by default in objects->search
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 21 May 2020 21:23:01 +0000 (18:23 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 24 Jun 2020 12:31:36 +0000 (14:31 +0200)
This patch makes the helper paginate the resultsif no pagination
parameters are passed.

Page number defaults to 1, and the page size to the RESTdefaultPageSize
syspref value.

To test:
1. Apply the regression tests patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> FAIL: Pagination is not enforced by default
3. Apply this patch
4. Repeat 2
=> SUCCESS: Results are paginated
5. Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Koha/REST/Plugin/Objects.pm

index f4e8be2..c743e9d 100644 (file)
@@ -65,6 +65,10 @@ sub register {
                 }
             );
 
+            # If no pagination parameters are passed, default
+            $reserved_params->{_per_page} //= C4::Context->preference('RESTdefaultPageSize');
+            $reserved_params->{_page}     //= 1;
+
             # Merge pagination into query attributes
             $c->dbic_merge_pagination(
                 {