From 60337e6a5274a402c45a2c8fc420fa4d9c482fe0 Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Thu, 12 May 2022 08:38:15 +0000
Subject: [PATCH] Bug 30734: Fix BackgroundJob.t
Content-Type: text/plain; charset=utf-8

Added test for empty string or undefined. We could still consider
evaling the json operations.

Test plan:
Run t/db_dependent/Koha/BackgroundJob.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
---
 Koha/BackgroundJob.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm
index a84ca42c58..517c54f010 100644
--- a/Koha/BackgroundJob.pm
+++ b/Koha/BackgroundJob.pm
@@ -245,7 +245,7 @@ Returns the decoded JSON contents from $self->data.
 sub decoded_data {
     my ($self) = @_;
 
-    return decode_json($self->data);
+    return $self->data ? decode_json( $self->data ) : undef;
 }
 
 =head3 set_encoded_data
@@ -259,7 +259,7 @@ Serializes I<$data> as a JSON string and sets the I<data> attribute with it.
 sub set_encoded_data {
     my ( $self, $data ) = @_;
 
-    return $self->data( encode_json($data) );
+    return $self->data( $data ? encode_json($data) : undef );
 }
 
 =head3 job_type
-- 
2.20.1