From 9cffa62bdb868257ce5bf8e447c47e39086d28aa Mon Sep 17 00:00:00 2001 From: Milan Mertens Date: Thu, 24 Oct 2024 15:58:26 +0200 Subject: [PATCH] tweak(Tinebase/Config): deep merge conf.d config files --- tine20/Tinebase/Config/Abstract.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tine20/Tinebase/Config/Abstract.php b/tine20/Tinebase/Config/Abstract.php index 90ef3f85cf..ba583016b0 100644 --- a/tine20/Tinebase/Config/Abstract.php +++ b/tine20/Tinebase/Config/Abstract.php @@ -507,7 +507,7 @@ protected function _doCreateCachedConfig($cachedConfigData) $cachedConfigData['ttlstamp'] < time() || (defined('TINE20_BUILDTYPE') && (TINE20_BUILDTYPE === 'DEVELOPMENT' || TINE20_BUILDTYPE === 'DEBUG')); } - + /** * composes config files from conf.d and saves array to tmp file */ @@ -542,9 +542,7 @@ protected function _createCachedConfig() } if (false !== $tmpArray && is_array($tmpArray)) { - foreach ($tmpArray as $key => $value) { - self::$_configFileData[$key] = $value; - } + self::$_configFileData = self::_array_merge_recursive_distinct(self::$_configFileData, $tmpArray); } } @@ -663,6 +661,26 @@ protected function _getConfdFileDataJson($filename) return false; } + /** + * Merges arrays recursively. Overwrites non-array keys, unlike array_merge_recursive. Array2 takes precedence. + * @param $array1 + * @param $array2 + * @return array + */ + static function _array_merge_recursive_distinct(&$array1, &$array2) { + $merged = $array1; + + foreach ($array2 as $key => &$value) { + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { + $merged[$key] = self::_array_merge_recursive_distinct($merged[$key], $value); + } else { + $merged[$key] = $value; + } + } + + return $merged; + } + /** * returns data from application specific config.inc.php file *