From 05bf35d717fda726e20260ff75c711b2670f0a63 Mon Sep 17 00:00:00 2001
From: Manuel Munz <munz@comuno.net>
Date: Tue, 25 Feb 2020 18:20:13 +0100
Subject: [PATCH] [BUGFIX] Fix Exception caused by empty staticPageArguments

When 'Index Records immediately when saved?' is enabled in indexing
configurations for records, then on saving the record the
string 'null' is used for this indexingconfiguration and passed to
SearchController::preparePageLink(), which expects an array and
therefore throws an exception.

This commit fixes this by checking if
$this->conf['staticPageArguments'] is an array and only then json_decode
that, else it sets the value to null.

Resolves: #89816
Related: #86994
Releases: master, 9.5
Change-Id: I96d3fb963ecb508bc536967afece064ad12bb989
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63414
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 typo3/sysext/indexed_search/Classes/Indexer.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/indexed_search/Classes/Indexer.php b/typo3/sysext/indexed_search/Classes/Indexer.php
index d771bb901ebd..c5bd05535cf7 100644
--- a/typo3/sysext/indexed_search/Classes/Indexer.php
+++ b/typo3/sysext/indexed_search/Classes/Indexer.php
@@ -1393,7 +1393,7 @@ class Indexer
         $fields = [
             'phash' => $this->hash['phash'],
             'phash_grouping' => $this->hash['phash_grouping'],
-            'static_page_arguments' => json_encode($this->conf['staticPageArguments']),
+            'static_page_arguments' => is_array($this->conf['staticPageArguments']) ? json_encode($this->conf['staticPageArguments']) : null,
             'contentHash' => $this->content_md5h,
             'data_page_id' => $this->conf['id'],
             'data_page_type' => $this->conf['type'],
@@ -2171,7 +2171,7 @@ class Indexer
             'type' => (int)$this->conf['type'],
             'sys_lang' => (int)$this->conf['sys_language_uid'],
             'MP' => (string)$this->conf['MP'],
-            'staticPageArguments' => $this->conf['staticPageArguments'],
+            'staticPageArguments' => is_array($this->conf['staticPageArguments']) ? json_encode($this->conf['staticPageArguments']) : null,
         ];
         // Set grouping hash (Identifies a "page" combined of id, type, language, mountpoint and cHash parameters):
         $this->hash['phash_grouping'] = IndexedSearchUtility::md5inthash(serialize($hArray));
-- 
GitLab