Bugzilla – Attachment 96940 Details for
Bug 24321
Make objects.search use mappings from Koha::Object(s)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Bug-24321-Make-dbicmergesorting-accept-a-result-se.patch (text/plain), 4.71 KB, created by
Kyle M Hall (khall)
on 2020-01-07 18:50:03 UTC
(
hide
)
Description:
Bug 24321: Make dbic_merge_sorting accept a result set as parameter
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2020-01-07 18:50:03 UTC
Size:
4.71 KB
patch
obsolete
>From 4a8105c87955197451c16dc99e004290c5823e46 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 31 Dec 2019 09:48:54 -0300 >Subject: [PATCH] Bug 24321: Make dbic_merge_sorting accept a result set as > parameter > >This patch makes dbic_merge_sorting accept a result set as parameter and >solves a FIXME in _build_order_atom. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/Koha/REST/Plugin/Query.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/REST/Plugin/Query.pm | 18 +++++++++--------- > t/Koha/REST/Plugin/Query.t | 26 +++++++++++--------------- > 2 files changed, 20 insertions(+), 24 deletions(-) > >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index 14b3f5997e..f1402d95ba 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -81,17 +81,17 @@ Generates the DBIC order_by attributes based on I<$params>, and merges into I<$a > 'dbic_merge_sorting' => sub { > my ( $c, $args ) = @_; > my $attributes = $args->{attributes}; >- my $to_model = $args->{to_model}; >+ my $result_set = $args->{result_set}; > > if ( defined $args->{params}->{_order_by} ) { > my $order_by = $args->{params}->{_order_by}; > if ( reftype($order_by) and reftype($order_by) eq 'ARRAY' ) { >- my @order_by = map { _build_order_atom( $_, $to_model) } >+ my @order_by = map { _build_order_atom({ string => $_, result_set => $result_set }) } > @{ $args->{params}->{_order_by} }; > $attributes->{order_by} = \@order_by; > } > else { >- $attributes->{order_by} = _build_order_atom( $order_by, $to_model ); >+ $attributes->{order_by} = _build_order_atom({ string => $order_by, result_set => $result_set }); > } > } > >@@ -173,15 +173,15 @@ according to the following rules: > =cut > > sub _build_order_atom { >- my $string = shift; >- my $to_model = shift; >+ my ( $args ) = @_; >+ my $string = $args->{string}; >+ my $result_set = $args->{result_set}; > >- # FIXME: This should be done differently once 23893 is pushed >- # and we have access to the to_model_mapping hash > my $param = $string; > $param =~ s/^(\+|\-|\s)//; >- $param = (keys %{$to_model->({ $param => 1 })})[0] >- if $to_model; >+ if ( $result_set ) { >+ $param = (keys %{$result_set->attributes_from_api({ $param => 1 })})[0]; >+ } > > if ( $string =~ m/^\+/ or > $string =~ m/^\s/ ) { >diff --git a/t/Koha/REST/Plugin/Query.t b/t/Koha/REST/Plugin/Query.t >index 2fc027c149..f920af6705 100644 >--- a/t/Koha/REST/Plugin/Query.t >+++ b/t/Koha/REST/Plugin/Query.t >@@ -21,6 +21,8 @@ use Modern::Perl; > use Mojolicious::Lite; > use Try::Tiny; > >+use Koha::Cities; >+ > app->log->level('error'); > > plugin 'Koha::REST::Plugin::Query'; >@@ -92,14 +94,15 @@ get '/dbic_merge_sorting_single' => sub { > $c->render( json => $attributes, status => 200 ); > }; > >-get '/dbic_merge_sorting_to_model' => sub { >+get '/dbic_merge_sorting_result_set' => sub { > my $c = shift; > my $attributes = { a => 'a', b => 'b' }; >+ my $result_set = Koha::Cities->new; > $attributes = $c->dbic_merge_sorting( > { > attributes => $attributes, >- params => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] }, >- to_model => \&to_model >+ params => { _match => 'exact', _order_by => [ 'name', '-postal_code', '+country', ' state' ] }, >+ result_set => $result_set > } > ); > $c->render( json => $attributes, status => 200 ); >@@ -122,13 +125,6 @@ get '/build_query' => sub { > }; > }; > >-sub to_model { >- my ($args) = @_; >- $args->{three} = delete $args->{tres} >- if exists $args->{tres}; >- return $args; >-} >- > # The tests > > use Test::More tests => 3; >@@ -178,14 +174,14 @@ subtest 'dbic_merge_sorting() tests' => sub { > ] > ); > >- $t->get_ok('/dbic_merge_sorting_to_model')->status_is(200) >+ $t->get_ok('/dbic_merge_sorting_result_set')->status_is(200) > ->json_is( '/a' => 'a', 'Existing values are kept (a)' ) > ->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( > '/order_by' => [ >- 'uno', >- { -desc => 'dos' }, >- { -asc => 'three' }, >- { -asc => 'cuatro' } >+ 'city_name', >+ { -desc => 'city_zipcode' }, >+ { -asc => 'city_country' }, >+ { -asc => 'city_state' } > ] > ); > >-- >2.21.0 (Apple Git-122.2)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24321
:
96703
|
96704
|
96705
|
96706
|
96707
|
96708
|
96709
|
96710
|
96711
|
96712
|
96713
|
96714
|
96715
|
96716
|
96717
|
96718
|
96719
|
96720
|
96721
|
96722
|
96744
|
96840
|
96841
|
96842
|
96843
|
96844
|
96845
|
96846
|
96847
|
96848
|
96849
|
96850
|
96851
|
96852
|
96874
|
96875
|
96876
|
96877
|
96878
|
96879
|
96880
|
96881
|
96882
|
96883
|
96884
|
96885
|
96886
|
96887
|
96939
| 96940 |
96941
|
96942
|
96943
|
96944
|
96945
|
96946
|
96947
|
96948
|
96949
|
96950
|
96951
|
96952