Bugzilla – Attachment 96646 Details for
Bug 24228
Add a parameter to recursively embed objects in Koha::Object(s)->to_api
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24228: (follow-up) Check wether each child or children can('to_api') and throw exception otherwise
Bug-24228-follow-up-Check-wether-each-child-or-chi.patch (text/plain), 2.55 KB, created by
Agustín Moyano
on 2019-12-26 22:31:36 UTC
(
hide
)
Description:
Bug 24228: (follow-up) Check wether each child or children can('to_api') and throw exception otherwise
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2019-12-26 22:31:36 UTC
Size:
2.55 KB
patch
obsolete
>From fc6b63afa762b00970657e1e1950352af11fc7ab Mon Sep 17 00:00:00 2001 >From: Agustin Moyano <agustinmoyano@theke.io> >Date: Thu, 26 Dec 2019 19:31:04 -0300 >Subject: [PATCH] Bug 24228: (follow-up) Check wether each child or children > can('to_api') and throw exception otherwise > >--- > Koha/Object.pm | 30 +++++++++++++++++++++++------- > 1 file changed, 23 insertions(+), 7 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index c55016a800..1dc4bf9ce8 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -26,6 +26,7 @@ use Scalar::Util qw( looks_like_number ); > use Try::Tiny; > > use Koha::Database; >+use Koha::Exceptions; > use Koha::Exceptions::Object; > use Koha::DateUtils; > >@@ -429,21 +430,36 @@ sub to_api { > my $next = $embeds->{$curr}->{children}; > > my $children = $self->$curr; >+ >+ my $res; > if ( ref $children eq 'ARRAY' ) { >+ #when $self->$curr returns an array of Koha::Object > my @list; >- my $pos = 0; > foreach my $child (@$children) { >- my $res = $child->to_api({ embed => $next }); >- $res = { $json_object->{$curr}->[$pos], $res } >+ Koha::Exceptions::BadParameter->throw($curr." is not a valid embeddable option.") unless $child->can('to_api'); >+ my $r = $child->to_api({ embed => $next }); >+ push @list, $r; >+ } >+ $res = \@list; >+ } >+ else { >+ #when $self->$curr returns a single Koha::Object or Koha::Objects >+ Koha::Exceptions::BadParameter->throw($curr." is not a valid embeddable option.") unless $children->can('to_api'); >+ $res = $children->to_api({ embed => $next }); >+ } >+ >+ if(ref $res eq 'ARRAY') { >+ my @list; >+ my $pos = 0; >+ foreach my $r (@$res) { >+ $r = { $json_object->{$curr}->[$pos], $r } > if defined $json_object->{$curr} > && defined $json_object->{$curr}->[$pos]; >- push @list, $res; >+ push @list, $r; > $pos++; > } > $json_object->{$curr} = \@list; >- } >- else { >- my $res = $children->to_api({ embed => $next }); >+ } else { > $res = { $json_object->{$curr}, $res } > if defined $json_object->{$curr}; > $json_object->{$curr} = $res; >-- >2.17.1
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 24228
:
96543
|
96612
|
96613
|
96615
|
96622
|
96644
|
96645
|
96646
|
96685
|
96686
|
96687
|
96954
|
96955