diff --git a/Core/ConfigExport.php b/Core/ConfigExport.php index 1c4c09d..e688167 100644 --- a/Core/ConfigExport.php +++ b/Core/ConfigExport.php @@ -26,6 +26,7 @@ namespace OxidProfessionalServices\ModulesConfig\Core; +use OxidEsales\Eshop\Core\DatabaseProvider; use Symfony\Component\Yaml\Yaml; /** @@ -252,10 +253,27 @@ protected function withoutDefaults(&$aGroupedValues) if (array_key_exists('theme', $aShopConfig)) { $aCurrentThemeConfigs = &$aShopConfig['theme']; $aDefaultThemeConfigs = $this->aDefaultConfig['theme']; + + $currentParentTheme = $aGeneralConfig['sTheme']; + $currentTheme = $aGeneralConfig['sCustomTheme']; + foreach ($aCurrentThemeConfigs as $sTheme => &$aThemeConfig) { + if ($sTheme != $currentParentTheme && $currentTheme != $sTheme) { + unset($aCurrentThemeConfigs[$sTheme]); + continue; + } + $aDefaultThemeConfig = $aDefaultThemeConfigs[$sTheme]; - if ($aDefaultThemeConfig != null) { - foreach ($aThemeConfig as $sVarName => $mCurrentValue) { + foreach ($aThemeConfig as $sVarName => $mCurrentValue) { + if (array_key_exists($sVarName,$aGeneralConfig)) { + $this->output->writeln("config '$sVarName' is in theme and in gerneral namespace use --force-cleanup to repair"); + if ($this->input->getOption('force-cleanup') ) { + $sSql = "DELETE FROM oxconfig WHERE oxmodule = '' AND oxvarname = ? AND oxshopid = ?"; + DatabaseProvider::getDb()->execute($sSql,[$sVarName,$sShopId]); + } + unset($aGeneralConfig[$sVarName]); + } + if ($aDefaultThemeConfig != null) { $mDefaultValue = $aDefaultThemeConfig[$sVarName]; if ($mCurrentValue === $mDefaultValue) { unset($aThemeConfig[$sVarName]); diff --git a/Core/ConfigImport.php b/Core/ConfigImport.php index b9701ce..3c9832b 100644 --- a/Core/ConfigImport.php +++ b/Core/ConfigImport.php @@ -26,6 +26,7 @@ namespace OxidProfessionalServices\ModulesConfig\Core; +use OxidEsales\Eshop\Core\DatabaseProvider; use OxidProfessionalServices\OxidConsole\Core\Module\ModuleStateFixer; use OxidProfessionalServices\OxidConsole\Core\ShopConfig; use OxidEsales\Eshop\Core\Registry; @@ -38,7 +39,7 @@ class ConfigImport extends CommandBase { /** - * @var \oxConfig $oConfig + * @var ShopConfig $oConfig */ protected $oConfig; @@ -55,6 +56,17 @@ class ConfigImport extends CommandBase */ protected $storedVarTypes = []; + protected $storedDisplayConfigHash = []; + + + public function init(){ + parent::init(); + $db = DatabaseProvider::getDb(); + $hashValues = $db->getCol("SELECT md5(CONCAT(oxcfgmodule,'#', oxcfgvarname,'#', oxgrouping,'#', oxvarconstraint,'#', oxpos)) FROM oxconfigdisplay"); + $this->storedDisplayConfigHash = array_fill_keys($hashValues, true); + + } + /* * executes all functionality which is necessary for a call of OXID console config:import * @@ -336,7 +348,7 @@ protected function importConfigValues($aConfigValues) } } } - $oConfig->saveShopConfVar('arr','aDisabledModules',$aDisabledModules); + $this->saveShopVar('aDisabledModules', $aDisabledModules, '','arr'); foreach ($aModuleVersions as $sModuleId => $sVersion) { if (!$oModule->load($sModuleId)) { @@ -532,42 +544,39 @@ protected function getStoredVarTypes() } return $map; } + public function getShopConfType($sVarName,$sSectionModule) { return $this->storedVarTypes[$sVarName.'+'.$sSectionModule]; } - protected function saveShopVar($sVarName, $mVarValue, $sSectionModule, $sVarType = null) + + protected function saveShopVarWithTypeInfo($sVarName, $mVarValue, $sSectionModule){ + list($sVarType, $mVarValue) = $this->getTypeAndValue($sVarName, $mVarValue); + $this->saveShopVar($sVarName, $mVarValue, $sSectionModule, $sVarType); + } + + + protected function saveShopVar($sVarName, $mVarValue, $sSectionModule, $sVarType) { $sShopId = $this->sShopId; $oConfig = $this->oConfig; - $value = $oConfig->getShopConfVar($sVarName, $sShopId, $sSectionModule); - $type = $this->getShopConfType($sVarName,$sSectionModule); - - if ($sVarType === null) { - list($sVarType, $mVarValue) = $this->getTypeAndValue($sVarName, $mVarValue); - if ($sVarType == 'bool') { - //internal representation of bool is 1 or '' - $value = $value ? '1' : ''; - } - } else { - if ($sVarType == 'bool') { - //cleanup for some modules that have all kinds of bool representations in metadata.php - //so we can compare that value - $mVarValue = (($mVarValue == 'true' || $mVarValue) && $mVarValue && strcasecmp($mVarValue, "false")); + if ($sShopId != 1) { + $aOnlyMainShopVars = array_fill_keys(['blMallUsers', 'aSerials', 'IMD', 'IMA', 'IMS'],true); + if ($aOnlyMainShopVars[$sVarName]){ + return; } } - if ($mVarValue !== $value || $sVarType !== $type) { - $oConfig->saveShopConfVar( - $sVarType, - $sVarName, - $mVarValue, - $sShopId, - $sSectionModule - ); - } + $oConfig->saveShopConfVar( + $sVarType, + $sVarName, + $mVarValue, + $sShopId, + $sSectionModule + ); + if(strpos($sSectionModule,'module') === 0) { if($existsAlsoInGlobalNameSpace = $this->getShopConfType($sVarName,'')) { $db = \oxDb::getDb(); @@ -594,15 +603,21 @@ protected function importThemeConfig($aThemes) if ($aThemes == null) { return; } + $parentTheme = $this->oConfig->getConfigParam('sTheme'); + $theme = $this->oConfig->getConfigParam('sCustomTheme'); foreach ($aThemes as $sThemeId => $aSettings) { + if ($sThemeId != $parentTheme && $theme != $sThemeId) { + $this->output->writeln("Theme $sThemeId from import from config file ignored because it is not active"); + return; + } $sSectionModule = "theme:$sThemeId"; foreach ($aSettings as $sVarName => $mVarValue) { if(isset($mVarValue['value'])) { - $this->saveShopVar($sVarName, $mVarValue['value'], $sSectionModule); + $this->saveShopVarWithTypeInfo($sVarName, $mVarValue['value'], $sSectionModule); $this->saveThemeDisplayVars($sVarName, $mVarValue, $sSectionModule); } else { - $this->saveShopVar($sVarName, $mVarValue, $sSectionModule); + $this->saveShopVarWithTypeInfo($sVarName, $mVarValue, $sSectionModule); } } } @@ -641,24 +656,29 @@ protected function restoreGeneralShopSettings($aConfigValues) } elseif ($sVarName == 'aModuleVersions') { $aModuleVersions = $mVarValue; } - $this->saveShopVar($sVarName, $mTypedVarValue, $sSectionModule); + $this->saveShopVarWithTypeInfo($sVarName, $mTypedVarValue, $sSectionModule); } return $aModuleVersions; } protected function saveThemeDisplayVars($sVarName, $mVarValue, $sModule) { - $oConfig = $this->oConfig; - $oDb = \oxDb::getDb(); $sModuleQuoted = $oDb->quote($sModule); $sVarNameQuoted = $oDb->quote($sVarName); - $sVarConstraintsQuoted = isset($mVarValue['constraints']) ? $oDb->quote($mVarValue['constraints']) : '\'\''; - $sVarGroupingQuoted = isset($mVarValue['grouping']) ? $oDb->quote($mVarValue['grouping']) : '\'\''; - $sVarPosQuoted = isset($mVarValue['pos']) ? $oDb->quote($mVarValue['pos']) : '\'\''; + $constraints = $mVarValue['constraints']; + $sVarConstraintsQuoted = isset($constraints) ? $oDb->quote($constraints) : '\'\''; + $grouping = $mVarValue['grouping']; + $sVarGroupingQuoted = isset($grouping) ? $oDb->quote($grouping) : '\'\''; + $pos = $mVarValue['pos']; + $sVarPosQuoted = isset($pos) ? $oDb->quote($pos) : '\'\''; $sNewOXIDdQuoted = $oDb->quote(\oxUtilsObject::getInstance()->generateUID()); + if (isset($this->storedDisplayConfigHash[md5($sModule . '#' . $sVarName . '#' . $grouping. '#'. $constraints .'#'. $pos)])){ + return; + } + $sQ = "delete from oxconfigdisplay WHERE OXCFGVARNAME = $sVarNameQuoted and OXCFGMODULE = $sModuleQuoted"; $oDb->execute($sQ); @@ -666,7 +686,6 @@ protected function saveThemeDisplayVars($sVarName, $mVarValue, $sModule) values($sNewOXIDdQuoted, $sModuleQuoted, $sVarNameQuoted, $sVarGroupingQuoted, $sVarConstraintsQuoted, $sVarPosQuoted)"; $oDb->execute($sQ); - $oConfig->executeDependencyEvent($sVarName); }