From ca2dd193fccc4514970f9e5e9ac5e978120958d2 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 26 Nov 2021 13:40:15 +0000 Subject: [PATCH] Bug 29523: (QA follow-up) Catch remaining SUPER::to_api cases Koha::Object->to_api can now return undefined.. we should be catching that cases in all post manipulation cases. Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Basket.pm | 7 ++++--- Koha/Acquisition/Fund.pm | 2 ++ Koha/Acquisition/Invoice.pm | 7 ++++--- Koha/Biblio.pm | 8 +++++--- Koha/SMTP/Server.pm | 7 ++++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Koha/Acquisition/Basket.pm b/Koha/Acquisition/Basket.pm index 556fa326b0..f22673ef9f 100644 --- a/Koha/Acquisition/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -250,13 +250,14 @@ suitable for API output. sub to_api { my ( $self, $params ) = @_; - my $json = $self->SUPER::to_api( $params ); + my $json_basket = $self->SUPER::to_api( $params ); + return unless $json_basket; - $json->{closed} = ( $self->closedate ) + $json_basket->{closed} = ( $self->closedate ) ? Mojo::JSON->true : Mojo::JSON->false; - return $json; + return $json_basket; } =head3 to_api_mapping diff --git a/Koha/Acquisition/Fund.pm b/Koha/Acquisition/Fund.pm index 80ef0b2f4a..3acc8f99ba 100644 --- a/Koha/Acquisition/Fund.pm +++ b/Koha/Acquisition/Fund.pm @@ -62,6 +62,8 @@ sub to_api { my $budget_period_id = $self->budget_period_id; my $json_fund = $self->SUPER::to_api($args); + return unless $json_fund; + $json_fund->{fund_id} = $budget_id; $json_fund->{budget_id} = $budget_period_id; diff --git a/Koha/Acquisition/Invoice.pm b/Koha/Acquisition/Invoice.pm index be36b5d718..ae1bf38cb1 100644 --- a/Koha/Acquisition/Invoice.pm +++ b/Koha/Acquisition/Invoice.pm @@ -41,13 +41,14 @@ suitable for API output. sub to_api { my ( $self, $params ) = @_; - my $json = $self->SUPER::to_api( $params ); + my $json_invoice = $self->SUPER::to_api( $params ); + return unless $json_invoice; - $json->{closed} = ( $self->closedate ) + $json_invoice->{closed} = ( $self->closedate ) ? Mojo::JSON->true : Mojo::JSON->false; - return $json; + return $json_invoice; } =head3 to_api_mapping diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 9e2386ae98..406031fb9f 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -1424,14 +1424,16 @@ on the API. sub to_api { my ($self, $args) = @_; - my $response = $self->SUPER::to_api( $args ); + my $json_biblio = $self->SUPER::to_api( $args ); + return unless $json_biblio; $args = defined $args ? {%$args} : {}; delete $args->{embed}; - my $biblioitem = $self->biblioitem->to_api( $args ); + my $json_biblioitem = $self->biblioitem->to_api( $args ); + return unless $json_biblioitem; - return { %$response, %$biblioitem }; + return { %$json_biblio, %$json_biblioitem }; } =head3 to_api_mapping diff --git a/Koha/SMTP/Server.pm b/Koha/SMTP/Server.pm index f85b34e3d7..42b641b9f2 100644 --- a/Koha/SMTP/Server.pm +++ b/Koha/SMTP/Server.pm @@ -135,10 +135,11 @@ suitable for API output. sub to_api { my ( $self, $params ) = @_; - my $json = $self->SUPER::to_api( $params ); - delete $json->{password}; + my $json_smtp = $self->SUPER::to_api( $params ); + return unless $json_smtp; + delete $json_smtp->{password}; - return $json; + return $json_smtp; } =head3 to_api_mapping -- 2.39.5