From 9f381f4c1903fca4f91384355e62b0a6d8c3adbe Mon Sep 17 00:00:00 2001 From: "[OXID-PS] Keywan Ghadami" Date: Fri, 20 Mar 2020 10:25:36 +0100 Subject: [PATCH] remove warnings and fix empty module export empty module values break config and show warnings in console taken from: https://github.com/OXIDprojects/oxid_modules_config/pull/39 --- Core/ConfigExport.php | 111 ++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/Core/ConfigExport.php b/Core/ConfigExport.php index 89afa25..48e664d 100644 --- a/Core/ConfigExport.php +++ b/Core/ConfigExport.php @@ -118,6 +118,11 @@ protected function getConfigValues($aConfigFields, $blIncludeMode) protected function filternestedExcludes($values){ $excludeDeep = $this->aConfiguration['excludeDeep']; $moduleValues = &$values['module']; + + if ($moduleValues === null) { + return $values; + } + foreach ($moduleValues as $moduleId => &$moduleSettings) { foreach ($moduleSettings as $sVarName => &$aVarValue) { if (is_array($aVarValue)) { @@ -194,71 +199,73 @@ protected function withoutDefaults(&$aGroupedValues) foreach ($aGroupedValues as $sShopId => &$aShopConfig) { $aGeneralConfig = &$aShopConfig[$this->sNameForGeneralShopSettings]; - if (isset($aShopConfig['module'])) { - $aModuleConfigs = &$aShopConfig['module']; + if (!isset($aShopConfig['module'])) { + $aShopConfig['module'] = []; + } + $aModuleConfigs = &$aShopConfig['module']; - /** @var \oxModule $oModule */ - $oModule = oxNew('oxModule'); + /** @var \oxModule $oModule */ + $oModule = oxNew('oxModule'); - foreach ($aModuleConfigs as $sModuleId => &$aModuleConfig) { + foreach ($aModuleConfigs as $sModuleId => &$aModuleConfig) { - if (!$oModule->load($sModuleId)) { - $this->handleModuleOnError($sModuleId); - unset ($aModuleConfigs[$sModuleId]); - continue; + if (!$oModule->load($sModuleId)) { + $this->handleModuleOnError($sModuleId); + unset ($aModuleConfigs[$sModuleId]); + continue; + } + $aDefaultModuleSettings = is_null($oModule->getInfo("settings")) ? array() : $oModule->getInfo( + "settings" + ); + $known = []; + foreach ($aDefaultModuleSettings as $aConfigValue) { + $sVarName = $aConfigValue['name']; + $known[$sVarName] = 1; + if (array_key_exists($sVarName, $aGeneralConfig)) { + //if a module safe a value twice once in module namespace and once in general namespace only export the value from the + //modulename space because it this happens only when the config table has some corrupted data + $this->output->writeLn( + "$sVarName from module $sModuleId is also configured in global namespace in shop $sShopId" + ); + unset($aGeneralConfig[$sVarName]); } - $aDefaultModuleSettings = is_null($oModule->getInfo("settings")) ? array() : $oModule->getInfo( - "settings" - ); - $known = []; - foreach ($aDefaultModuleSettings as $aConfigValue) { - $sVarName = $aConfigValue['name']; - $known[$sVarName] = 1; - if (array_key_exists($sVarName, $aGeneralConfig)) { - //if a module safe a value twice once in module namespace and once in general namespace only export the value from the - //modulename space because it this happens only when the config table has some corrupted data - $this->output->writeLn( - "$sVarName from module $sModuleId is also configured in global namespace in shop $sShopId" - ); - unset($aGeneralConfig[$sVarName]); - } - $sDefaultType = $aConfigValue['type']; - $mDefaultValue = $aConfigValue['value']; + $sDefaultType = $aConfigValue['type']; + $mDefaultValue = $aConfigValue['value']; - if ($sDefaultType == 'bool') { - $mDefaultValue = $this->convertToBool($mDefaultValue); - } - - if (! isset($aModuleConfig[$sVarName])) { - //TODO warning about not set module config value - //this happens if the module was installed fresh and config was never saved in admin - $mCurrentValue = $mDefaultValue; - } else { - $mCurrentValue = $aModuleConfig[$sVarName]; - } + if ($sDefaultType == 'bool') { + $mDefaultValue = $this->convertToBool($mDefaultValue); + } - if ($sDefaultType == 'bool') { - $mCurrentValue = $this->convertToBool($mCurrentValue); - } + if (! isset($aModuleConfig[$sVarName])) { + //TODO warning about not set module config value + //this happens if the module was installed fresh and config was never saved in admin + $mCurrentValue = $mDefaultValue; + } else { + $mCurrentValue = $aModuleConfig[$sVarName]; + } - if ($mCurrentValue === $mDefaultValue) { - unset($aModuleConfig[$sVarName]); - } + if ($sDefaultType == 'bool') { + $mCurrentValue = $this->convertToBool($mCurrentValue); } - foreach ($aModuleConfig as $aConfigKey => $Value) { - if (!isset($known[$aConfigKey])) { - $this->output->writeLn( - "$sVarName from module $sModuleId is ignored because it is not defined in metadata.php anymore" - ); - unset($aModuleConfig[$aConfigKey]); - } + + if ($mCurrentValue === $mDefaultValue) { + unset($aModuleConfig[$sVarName]); } - if (count($aModuleConfig) == 0) { - unset($aModuleConfigs[$sModuleId]); + } + foreach ($aModuleConfig as $aConfigKey => $Value) { + if (!isset($known[$aConfigKey])) { + $this->output->writeLn( + "$sVarName from module $sModuleId is ignored because it is not defined in metadata.php anymore" + ); + unset($aModuleConfig[$aConfigKey]); } } + if (count($aModuleConfig) == 0) { + unset($aModuleConfigs[$sModuleId]); + } } + $aDefaultGeneralConfig = $this->aDefaultConfig[$this->sNameForGeneralShopSettings]; foreach ($aGeneralConfig as $sVarName => $mCurrentValue) { $mDefaultValue = isset($aDefaultGeneralConfig[$sVarName]) ? $aDefaultGeneralConfig[$sVarName] : null;