From a2e62e6262b2f3b17329b8a79f21106e72ed03f4 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 20 Feb 2019 14:59:07 +0100 Subject: [PATCH] Revert "simpler way to un-reference the rows and some docu why we have to" This reverts commit e791a50098e50f738626574367aec7ab7ed37c9a. --- api/src/Etemplate.php | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/api/src/Etemplate.php b/api/src/Etemplate.php index eeb52c1083..4b804248d3 100644 --- a/api/src/Etemplate.php +++ b/api/src/Etemplate.php @@ -202,12 +202,9 @@ class Etemplate extends Etemplate\Widget\Template if($data['content']['nm']['rows'] && is_array($data['content']['nm']['rows'])) { - // Api\Storage::search() returns (historically) a reference! - // We need to un-reference the rows here, so they are not lost, - // if we have to set self::$request=null; to force the destructor. - $rows = $data['content']['nm']; - unset($data['content']['nm']); - $data['content']['nm'] = $rows; + // Deep copy rows so we don't lose them when request is set to null + // (some content by reference) + $data['content']['nm'] = self::deep_copy($data['content']['nm']); } // Info required to load the etemplate client-side @@ -253,8 +250,7 @@ class Etemplate extends Etemplate\Widget\Template // Really important to run this or weird things happen // See https://help.egroupware.org/t/nextmatch-wert-im-header-ausgeben/73412/11 - // this forces the constructor to run immediatly, while it otherwise would run to late by the garbadge collector - self::$request = null; + self::$request=null; return; } // let framework know, if we are a popup or not ('popup' not true, which is allways used by index.php!) @@ -638,6 +634,36 @@ class Etemplate extends Etemplate\Widget\Template return $old; } + /** + * Deep copy array to make sure there are no references + * + * @param Array $array + * @return Array + */ + public static function deep_copy($source) + { + $arr = array(); + + foreach ($source as $key => $element) + { + if (is_array($element)) + { + $arr[$key] = static::deep_copy($element); + } + else if (is_object($element)) + { + // make an object copy + $arr[$key] = clone $element; + } + else + { + $arr[$key] = $element; + } + } + return $arr; + } + + /** * Debug callback just outputting content *