Bugzilla – Attachment 97332 Details for
Bug 24366
Merging biblioitems should happen in Koha::Biblio->to_api
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24366: Make sure accessors are used on the right object
Bug-24366-Make-sure-accessors-are-used-on-the-righ.patch (text/plain), 2.38 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-01-13 19:48:22 UTC
(
hide
)
Description:
Bug 24366: Make sure accessors are used on the right object
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-01-13 19:48:22 UTC
Size:
2.38 KB
patch
obsolete
>From 0ab6fc984b1f742d02a0b3df85a27aca80dd40cc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 13 Jan 2020 16:45:58 -0300 >Subject: [PATCH] Bug 24366: Make sure accessors are used on the right object > >This patch makes the Koha::Biblio->to_api method try the accessors on >$self first, and fallback to $self->biblioitem on those he can't. > >This way it won't happen that (for example) ->holds will be tried >against ->biblioitem. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Biblio.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Biblio.pm | 10 +++++++++- > t/db_dependent/Koha/Biblio.t | 7 ++++++- > 2 files changed, 15 insertions(+), 2 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index e503bad718..a37330801f 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -737,8 +737,16 @@ on the API. > sub to_api { > my ($self, $args) = @_; > >+ my @embeds = keys %{ $args->{embed} }; >+ my $remaining_embeds = {}; >+ >+ foreach my $embed (@embeds) { >+ $remaining_embeds = delete $args->{embed}->{$embed} >+ unless $self->can($embed); >+ } >+ > my $response = $self->SUPER::to_api( $args ); >- my $biblioitem = $self->biblioitem->to_api( $args ); >+ my $biblioitem = $self->biblioitem->to_api({ embed => $remaining_embeds }); > > return { %$response, %$biblioitem }; > } >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index 45b375b369..91017eeaae 100644 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -440,14 +440,19 @@ subtest 'to_api() tests' => sub { > $schema->storage->txn_begin; > > my $biblio = $builder->build_sample_biblio(); >+ my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); >+ > my $biblioitem_api = $biblio->biblioitem->to_api; > my $biblio_api = $biblio->to_api; > >- plan tests => scalar keys %{ $biblioitem_api }; >+ plan tests => (scalar keys %{ $biblioitem_api }) + 1; > > foreach my $key ( keys %{ $biblioitem_api } ) { > is( $biblio_api->{$key}, $biblioitem_api->{$key}, "$key is added to the biblio object" ); > } > >+ $biblio_api = $biblio->to_api({ embed => { items => {} } }); >+ is_deeply( $biblio_api->{items}, [ $item->to_api ], 'Item correctly embedded' ); >+ > $schema->storage->txn_rollback; > }; >-- >2.24.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 24366
:
96914
|
96915
|
96958
|
96959
|
97312
|
97313
|
97314
| 97332