From cf9004f62aec262ce96e789ec8db428528a8ca1c Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sun, 29 Dec 2024 13:16:50 +0100
Subject: [PATCH 01/53] fix: set cache when env loader overrides data
---
.../Core/Helper/EnvironmentConfigLoader.php | 31 +++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 4f4da0e088a..4ede22dd8fb 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -70,15 +70,32 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
case static::CONFIG_KEY_DEFAULT:
[$unused1, $unused2, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
- $xmlConfig->setNode($this->buildNodePath($scope, $path), $value);
+ $nodePath = $this->buildNodePath($scope, $path);
+ $xmlConfig->setNode($nodePath, $value);
+ try {
+ $store = Mage::app()->getStore(0);
+ $this->setCache($store, $value, $path);
+ } catch (Throwable $exception) {
+ Mage::logException($exception);
+ }
break;
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
[$unused1, $unused2, $code, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
- $nodePath = sprintf('%s/%s/%s', strtolower($scope), strtolower($code), $path);
+ $storeCode = strtolower($storeCode);
+ $scope = strtolower($scope);
+ $nodePath = sprintf('%s/%s/%s', $scope, $storeCode, $path);
$xmlConfig->setNode($nodePath, $value);
+ try {
+ if (!str_contains($nodePath, 'websites')) {
+ $store = Mage::app()->getStore($storeCode);
+ $this->setCache($store, $value, $path);
+ }
+ } catch (Throwable $exception) {
+ Mage::logException($exception);
+ }
break;
}
}
@@ -101,6 +118,16 @@ public function getEnv(): array
return $this->envStore;
}
+ protected function setCache(Mage_Core_Model_Store $store, $value, string $path): void
+ {
+ $refObject = new ReflectionObject($store);
+ $refProperty = $refObject->getProperty('_configCache');
+ $refProperty->setAccessible(true);
+ $configCache = $refProperty->getValue($store);
+ $configCache[$path] = $value;
+ $refProperty->setValue($store, $configCache);
+ }
+
protected function getConfigKey(string $configKey): array
{
$configKeyParts = array_filter(
From 4d7b3baf958089e2abffe4c06e556755a1eee0a0 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sat, 8 Feb 2025 15:11:59 +0100
Subject: [PATCH 02/53] feat?: call env helper on config get
---
.../Mage/Core/Helper/EnvironmentConfigLoader.php | 12 ++++++++----
app/code/core/Mage/Core/Model/Store.php | 3 +++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 4ede22dd8fb..7464116a8bd 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -73,8 +73,10 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
$nodePath = $this->buildNodePath($scope, $path);
$xmlConfig->setNode($nodePath, $value);
try {
- $store = Mage::app()->getStore(0);
- $this->setCache($store, $value, $path);
+ foreach (['0', 'admin'] as $store) {
+ $store = Mage::app()->getStore($store);
+ $this->setCache($store, $value, $path);
+ }
} catch (Throwable $exception) {
Mage::logException($exception);
}
@@ -90,8 +92,10 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
$xmlConfig->setNode($nodePath, $value);
try {
if (!str_contains($nodePath, 'websites')) {
- $store = Mage::app()->getStore($storeCode);
- $this->setCache($store, $value, $path);
+ foreach ([$storeCode, 'admin'] as $store) {
+ $store = Mage::app()->getStore($store);
+ $this->setCache($store, $value, $path);
+ }
}
} catch (Throwable $exception) {
Mage::logException($exception);
diff --git a/app/code/core/Mage/Core/Model/Store.php b/app/code/core/Mage/Core/Model/Store.php
index cef474600e5..346203bddbd 100644
--- a/app/code/core/Mage/Core/Model/Store.php
+++ b/app/code/core/Mage/Core/Model/Store.php
@@ -365,6 +365,9 @@ public function getConfig($path)
}
$config = Mage::getConfig();
+ /** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
+ $environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
+ $environmentConfigLoaderHelper->overrideEnvironment($config);
$fullPath = 'stores/' . $this->getCode() . '/' . $path;
$data = $config->getNode($fullPath);
From 523c4849b2108e4301ba3810429965fd83ca90bc Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sat, 8 Feb 2025 15:47:53 +0100
Subject: [PATCH 03/53] feat?: backend: show data from env
---
.../core/Mage/Adminhtml/Model/Config/Data.php | 6 ++++
.../Core/Helper/EnvironmentConfigLoader.php | 36 +++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
index dd1248c4fb1..ce2790874f2 100644
--- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php
+++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
@@ -355,6 +355,12 @@ protected function _getPathConfig($path, $full = true)
}
}
+ if (!$full) {
+ /** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
+ $environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
+ $envConfig = $environmentConfigLoaderHelper->getAsArray($scope = $this->getScope());
+ $config = array_merge($config, $envConfig);
+ }
return $config;
}
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 7464116a8bd..5c5465cdb16 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -105,6 +105,42 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
}
}
+ public function getAsArray(string $wantedScope): array
+ {
+ $env = $this->getEnv();
+ $config = [];
+
+ foreach ($env as $configKey => $value) {
+ if (!$this->isConfigKeyValid($configKey)) {
+ continue;
+ }
+
+ list($configKeyParts, $scope) = $this->getConfigKey($configKey);
+ if (strtolower($scope) !== strtolower($wantedScope)) {
+ continue;
+ }
+
+ switch ($scope) {
+ case static::CONFIG_KEY_DEFAULT:
+ list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
+ $path = $this->buildPath($section, $group, $field);
+ $config[$path] = $value;
+ break;
+
+ case static::CONFIG_KEY_WEBSITES:
+ case static::CONFIG_KEY_STORES:
+ list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
+ $path = $this->buildPath($section, $group, $field);
+ $storeCode = strtolower($storeCode);
+ $scope = strtolower($scope);
+ $config[$path] = $value;
+ break;
+ }
+ }
+
+ return $config;
+ }
+
/**
* @internal method mostly for mocking
*/
From 66c48424cb9768488210407452613f9449f6d06b Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sat, 8 Feb 2025 16:07:00 +0100
Subject: [PATCH 04/53] feat?: backend: disable field when ENV data is
available
---
.../Adminhtml/Block/System/Config/Form.php | 15 ++++++++
.../Core/Helper/EnvironmentConfigLoader.php | 35 +++++++++++++++++--
2 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index f835ef9f533..488f836921e 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -384,6 +384,7 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
'name' => $name,
'label' => $label,
'comment' => $comment,
+ 'disabled' => $this->isDisabled($path),
'tooltip' => $tooltip,
'hint' => $hint,
'value' => $data,
@@ -645,6 +646,20 @@ public function getScope()
return $scope;
}
+ /**
+ * Render element as disabled, if overwritten by ENV variable
+ *
+ * @param string $data
+ * @return bool
+ */
+ public function isDisabled($path): bool
+ {
+ /** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
+ $environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
+ $path = $this->getScope() . '/' . $path;
+ return $environmentConfigLoaderHelper->hasPath($path);
+ }
+
/**
* Retrieve label for scope
*
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 5c5465cdb16..bdb27220224 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -105,6 +105,39 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
}
}
+ public function hasPath(string $wantedPath): bool
+ {
+ $env = $this->getEnv();
+ $config = [];
+
+ foreach ($env as $configKey => $value) {
+ if (!$this->isConfigKeyValid($configKey)) {
+ continue;
+ }
+
+ list($configKeyParts, $scope) = $this->getConfigKey($configKey);
+
+ switch ($scope) {
+ case static::CONFIG_KEY_DEFAULT:
+ list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
+ $path = $this->buildPath($section, $group, $field);
+ $nodePath = $this->buildNodePath($scope, $path);
+ $config[$nodePath] = $value;
+ break;
+
+ case static::CONFIG_KEY_WEBSITES:
+ case static::CONFIG_KEY_STORES:
+ list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
+ $path = $this->buildPath($section, $group, $field);
+ $nodePath = $this->buildNodePath($scope, $path);
+ $config[$nodePath] = $value;
+ break;
+ }
+ }
+ $hasConfig = array_key_exists($wantedPath, $config);
+ return $hasConfig;
+ }
+
public function getAsArray(string $wantedScope): array
{
$env = $this->getEnv();
@@ -131,8 +164,6 @@ public function getAsArray(string $wantedScope): array
case static::CONFIG_KEY_STORES:
list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
- $storeCode = strtolower($storeCode);
- $scope = strtolower($scope);
$config[$path] = $value;
break;
}
From 8de843809988ab71a65ae2844561f57f7452458f Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Sat, 8 Feb 2025 23:49:03 +0100
Subject: [PATCH 05/53] Update
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
---
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 488f836921e..53eade1d61d 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -648,11 +648,8 @@ public function getScope()
/**
* Render element as disabled, if overwritten by ENV variable
- *
- * @param string $data
- * @return bool
*/
- public function isDisabled($path): bool
+ public function isDisabled(string $path): bool
{
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
From 64d66f1099034c19205bb02e8cd0dfeb0b06fdc0 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Sun, 9 Feb 2025 00:00:40 +0100
Subject: [PATCH 06/53] Update
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
---
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index bdb27220224..16803f57d03 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -134,8 +134,7 @@ public function hasPath(string $wantedPath): bool
break;
}
}
- $hasConfig = array_key_exists($wantedPath, $config);
- return $hasConfig;
+ return array_key_exists($wantedPath, $config);
}
public function getAsArray(string $wantedScope): array
From 7163a29f718ab8f9a7faeeec2e8d8db0cf0fe741 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sun, 9 Feb 2025 09:03:44 +0100
Subject: [PATCH 07/53] feat?: backend: do not log on invalid stores - creates
infinite loop
---
.../Core/Helper/EnvironmentConfigLoader.php | 23 +++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 16803f57d03..d68a359c81c 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -57,6 +57,10 @@ class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
*/
public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
{
+ $data = Mage::registry('current_env_config');
+ if ($data) {
+ return;
+ }
$env = $this->getEnv();
foreach ($env as $configKey => $value) {
@@ -78,7 +82,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
$this->setCache($store, $value, $path);
}
} catch (Throwable $exception) {
- Mage::logException($exception);
+ // invalid store, intentionally empty
}
break;
@@ -98,15 +102,20 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
}
}
} catch (Throwable $exception) {
- Mage::logException($exception);
+ // invalid store, intentionally empty
}
break;
}
}
+ Mage::register("current_env_config", true, true);
}
public function hasPath(string $wantedPath): bool
{
+ $data = Mage::registry("config_env_has_path_$wantedPath");
+ if ($data !== null) {
+ return $data;
+ }
$env = $this->getEnv();
$config = [];
@@ -134,11 +143,17 @@ public function hasPath(string $wantedPath): bool
break;
}
}
- return array_key_exists($wantedPath, $config);
+ $hasConfig = array_key_exists($wantedPath, $config);
+ Mage::register("config_env_has_path_$wantedPath", $hasConfig);
+ return $hasConfig;
}
public function getAsArray(string $wantedScope): array
{
+ $data = Mage::registry("config_env_array_$wantedScope");
+ if ($data !== null) {
+ return $data;
+ }
$env = $this->getEnv();
$config = [];
@@ -167,7 +182,7 @@ public function getAsArray(string $wantedScope): array
break;
}
}
-
+ Mage::register("config_env_array_$wantedScope", $config);
return $config;
}
From d8630beb7b571de03934ce25adf6da1ef88ebc18 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 17 Feb 2025 21:08:31 +0100
Subject: [PATCH 08/53] feat: move env variables "str_starts_with"
---
.../core/Mage/Core/Helper/EnvironmentConfigLoader.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index d68a359c81c..f6b0f73c31b 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -197,7 +197,11 @@ public function setEnvStore(array $envStorage): void
public function getEnv(): array
{
if (empty($this->envStore)) {
- $this->envStore = getenv();
+ $env = getenv();
+ $env = array_filter($env, function ($key) {
+ return str_starts_with($key, static::ENV_STARTS_WITH);
+ }, ARRAY_FILTER_USE_KEY);
+ $this->envStore = $env;
}
return $this->envStore;
@@ -228,10 +232,6 @@ protected function getConfigKey(string $configKey): array
protected function isConfigKeyValid(string $configKey): bool
{
- if (!str_starts_with($configKey, static::ENV_STARTS_WITH)) {
- return false;
- }
-
$sectionGroupFieldRegexp = sprintf('([%s]*)', implode('', static::ALLOWED_CHARS));
$allowedChars = sprintf('[%s]', implode('', static::ALLOWED_CHARS));
$regexp = '/' . static::ENV_STARTS_WITH . static::ENV_KEY_SEPARATOR . '(WEBSITES' . static::ENV_KEY_SEPARATOR
From c9256b479a9e42caaff925319038aa33eb8d8ab2 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 17 Feb 2025 22:06:02 +0100
Subject: [PATCH 09/53] feat: add env flag to disable/enable feature
---
.../Core/Helper/EnvironmentConfigLoader.php | 7 +++--
.../Helper/EnvironmentConfigLoaderTest.php | 29 ++++++++++++++++++-
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index f6b0f73c31b..037a0f13eb8 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -15,7 +15,7 @@
class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
{
protected const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
-
+ protected const ENV_FEATURE_ENABLED = 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED';
protected const ENV_KEY_SEPARATOR = '__';
protected const CONFIG_KEY_DEFAULT = 'DEFAULT';
@@ -203,7 +203,10 @@ public function getEnv(): array
}, ARRAY_FILTER_USE_KEY);
$this->envStore = $env;
}
-
+ if (!isset($this->envStore[static::ENV_FEATURE_ENABLED])) {
+ $this->envStore = [];
+ return $this->envStore;
+ }
return $this->envStore;
}
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 2981c4cb182..c38bf6df912 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -18,7 +18,10 @@
use OpenMage\Tests\Unit\OpenMageTest;
use Varien_Simplexml_Config;
-final class EnvironmentConfigLoaderTest extends OpenMageTest
+/**
+ * @group Mage_Core_EnvLoader
+ */
+class EnvironmentConfigLoaderTest extends OpenMageTest
{
public const XML_PATH_GENERAL = 'general/store_information/name';
@@ -49,6 +52,30 @@ public function testBuildPath(): void
/**
* @group Helper
*/
+ public function testEnvFilter(): void
+ {
+ $environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
+ $environmentConfigLoaderHelper->setEnvStore([
+ 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value"
+ ]);
+ // empty because env flag is not set
+ $env = $environmentConfigLoaderHelper->getEnv();
+ $this->assertIsArray($env);
+ $this->assertEmpty($env);
+ $environmentConfigLoaderHelper->setEnvStore([
+ 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value",
+ 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1 // enable feature
+ ]);
+ // flag is set => feature is enabled
+ $env = $environmentConfigLoaderHelper->getEnv();
+ $this->assertIsArray($env);
+ $this->assertNotEmpty($env);
+ }
+
+ /**
+ * @group Mage_Core
+ * @group Mage_Core_Helper
+ */
public function testBuildNodePath(): void
{
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
From 53ae4e7728314a95de3851ff5dd51cffd44be115 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 17 Feb 2025 22:15:10 +0100
Subject: [PATCH 10/53] fix: fix tests
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index c38bf6df912..71c9a26fd97 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -97,6 +97,7 @@ public function testXmlHasTestStrings(): void
}
/**
+ * @runInSeparateProcess
* @dataProvider envOverridesCorrectConfigKeysDataProvider
* @group Helper
*
@@ -115,6 +116,7 @@ public function testEnvOverridesForValidConfigKeys(array $config): void
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
/** @phpstan-ignore method.internal */
$loader->setEnvStore([
+ 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['env_path'] => $config['value'],
]);
$loader->overrideEnvironment($xml);
@@ -198,6 +200,7 @@ public function envOverridesCorrectConfigKeysDataProvider(): Generator
}
/**
+ * @runInSeparateProcess
* @dataProvider envDoesNotOverrideOnWrongConfigKeysDataProvider
* @group Helper
*
@@ -223,6 +226,7 @@ public function testEnvDoesNotOverrideForInvalidConfigKeys(array $config): void
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
/** @phpstan-ignore method.internal */
$loader->setEnvStore([
+ 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['path'] => $config['value'],
]);
$loader->overrideEnvironment($xml);
From 8ddd602c76b733fca79d7d574ebfe2078a9ffe78 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 17 Feb 2025 23:13:25 +0100
Subject: [PATCH 11/53] feat: set disabled, set scope label
---
.../Adminhtml/Block/System/Config/Form.php | 21 ++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 53eade1d61d..aee44a11df8 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -19,6 +19,7 @@ class Mage_Adminhtml_Block_System_Config_Form extends Mage_Adminhtml_Block_Widge
public const SCOPE_WEBSITES = 'websites';
public const SCOPE_STORES = 'stores';
+ public const SCOPE_ENV = 'env';
/**
* Config data array
@@ -73,6 +74,7 @@ public function __construct()
self::SCOPE_DEFAULT => Mage::helper('adminhtml')->__('[GLOBAL]'),
self::SCOPE_WEBSITES => Mage::helper('adminhtml')->__('[WEBSITE]'),
self::SCOPE_STORES => Mage::helper('adminhtml')->__('[STORE VIEW]'),
+ self::SCOPE_ENV => Mage::helper('adminhtml')->__('[ENV]'),
];
}
@@ -380,11 +382,10 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
}
}
- $field = $fieldset->addField($id, $fieldType, [
+ $elementFieldData = [
'name' => $name,
'label' => $label,
'comment' => $comment,
- 'disabled' => $this->isDisabled($path),
'tooltip' => $tooltip,
'hint' => $hint,
'value' => $data,
@@ -395,9 +396,14 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
'scope' => $this->getScope(),
'scope_id' => $this->getScopeId(),
'scope_label' => $this->getScopeLabel($element),
- 'can_use_default_value' => $this->canUseDefaultValue((int) $element->show_in_default),
- 'can_use_website_value' => $this->canUseWebsiteValue((int) $element->show_in_website),
- ]);
+ 'can_use_default_value' => $this->canUseDefaultValue((int)$element->show_in_default),
+ 'can_use_website_value' => $this->canUseWebsiteValue((int)$element->show_in_website),
+ ];
+ if ($this->isOverwrittenByEnvVariable($path)) {
+ $elementFieldData['scope_label'] = $this->_scopeLabels[static::SCOPE_ENV];
+ $elementFieldData['disabled'] = 1;
+ }
+ $field = $fieldset->addField($id, $fieldType, $elementFieldData);
$this->_prepareFieldOriginalData($field, $element);
if (isset($element->validate)) {
@@ -647,9 +653,10 @@ public function getScope()
}
/**
- * Render element as disabled, if overwritten by ENV variable
+ * Returns true if element was overwritten by ENV variable
+ * @return bool
*/
- public function isDisabled(string $path): bool
+ public function isOverwrittenByEnvVariable(string $path): bool
{
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
From a390c50bebcaf4c02dd7d4292bb740efda688ecd Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 17 Feb 2025 23:15:41 +0100
Subject: [PATCH 12/53] feat: remove checkbox to override
---
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index aee44a11df8..5845e76fdc5 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -402,6 +402,8 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
if ($this->isOverwrittenByEnvVariable($path)) {
$elementFieldData['scope_label'] = $this->_scopeLabels[static::SCOPE_ENV];
$elementFieldData['disabled'] = 1;
+ $elementFieldData['can_use_default_value'] = 0;
+ $elementFieldData['can_use_website_value'] = 0;
}
$field = $fieldset->addField($id, $fieldType, $elementFieldData);
$this->_prepareFieldOriginalData($field, $element);
From 234a77da8e72d8f2b8b7091bfe61e5ee6403941d Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 17 Feb 2025 23:35:56 +0100
Subject: [PATCH 13/53] chore: remove inline helper variable name
---
app/code/core/Mage/Adminhtml/Model/Config/Data.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
index ce2790874f2..204569b8bd3 100644
--- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php
+++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
@@ -358,7 +358,7 @@ protected function _getPathConfig($path, $full = true)
if (!$full) {
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
- $envConfig = $environmentConfigLoaderHelper->getAsArray($scope = $this->getScope());
+ $envConfig = $environmentConfigLoaderHelper->getAsArray($this->getScope());
$config = array_merge($config, $envConfig);
}
return $config;
From 0a82291bf42426cd7b9f1772f2504d4a6c5e5624 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 00:19:35 +0100
Subject: [PATCH 14/53] Update
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
Co-authored-by: Sven Reichel
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 71c9a26fd97..d3eab1d8ef7 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -56,7 +56,7 @@ public function testEnvFilter(): void
{
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
$environmentConfigLoaderHelper->setEnvStore([
- 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value"
+ 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value'
]);
// empty because env flag is not set
$env = $environmentConfigLoaderHelper->getEnv();
From 0e9588a99f7a3baf2c34ce78f56739bc61a82c39 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 00:19:56 +0100
Subject: [PATCH 15/53] Update
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
Co-authored-by: Sven Reichel
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index d3eab1d8ef7..31199b87754 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -63,8 +63,8 @@ public function testEnvFilter(): void
$this->assertIsArray($env);
$this->assertEmpty($env);
$environmentConfigLoaderHelper->setEnvStore([
- 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value",
- 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1 // enable feature
+ 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value',
+ 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1, // enable feature
]);
// flag is set => feature is enabled
$env = $environmentConfigLoaderHelper->getEnv();
From cd342908c9f463bf82e227df61c06ebdb5afe779 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 00:20:38 +0100
Subject: [PATCH 16/53] Update
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
Co-authored-by: Sven Reichel
---
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 037a0f13eb8..b13109066c0 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -107,7 +107,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
break;
}
}
- Mage::register("current_env_config", true, true);
+ Mage::register('current_env_config', true, true);
}
public function hasPath(string $wantedPath): bool
From 95c67a064366572a40a9b814507a385e45bfa270 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 00:20:53 +0100
Subject: [PATCH 17/53] Update
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
Co-authored-by: Sven Reichel
---
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 5845e76fdc5..7d64e5fb29e 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -396,8 +396,8 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
'scope' => $this->getScope(),
'scope_id' => $this->getScopeId(),
'scope_label' => $this->getScopeLabel($element),
- 'can_use_default_value' => $this->canUseDefaultValue((int)$element->show_in_default),
- 'can_use_website_value' => $this->canUseWebsiteValue((int)$element->show_in_website),
+ 'can_use_default_value' => $this->canUseDefaultValue((int) $element->show_in_default),
+ 'can_use_website_value' => $this->canUseWebsiteValue((int) $element->show_in_website),
];
if ($this->isOverwrittenByEnvVariable($path)) {
$elementFieldData['scope_label'] = $this->_scopeLabels[static::SCOPE_ENV];
From 2980da6213ffd42b9f85c7ca942c51c1acaf1788 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 00:28:07 +0100
Subject: [PATCH 18/53] Update
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
Co-authored-by: Sven Reichel
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 31199b87754..963ace12336 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -56,7 +56,7 @@ public function testEnvFilter(): void
{
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
$environmentConfigLoaderHelper->setEnvStore([
- 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value'
+ 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value',
]);
// empty because env flag is not set
$env = $environmentConfigLoaderHelper->getEnv();
From a44450d3302acd78fff3c4a5a7700cb3949d844f Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 21:55:20 +0100
Subject: [PATCH 19/53] Update
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
Co-authored-by: Sven Reichel
---
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 7d64e5fb29e..183988b17e9 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -656,7 +656,6 @@ public function getScope()
/**
* Returns true if element was overwritten by ENV variable
- * @return bool
*/
public function isOverwrittenByEnvVariable(string $path): bool
{
From b18ab18b4dd41e7726da37c004e177634b7c40df Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 23:19:24 +0100
Subject: [PATCH 20/53] feat: add "hasPath" test
---
.../Helper/EnvironmentConfigLoaderTest.php | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 963ace12336..28aa98f6e88 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -199,6 +199,44 @@ public function envOverridesCorrectConfigKeysDataProvider(): Generator
]];
}
+ /**
+ * @runInSeparateProcess
+ * @dataProvider envHasPathDataProvider
+ * @group Mage_Core
+ *
+ * @param array $config
+ */
+ public function testHasPath(array $config): void
+ {
+ // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
+ $loader = new Mage_Core_Helper_EnvironmentConfigLoader();
+ $loader->setEnvStore([
+ 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
+ $config['env_path'] => 1,
+ ]);
+ $actual = $loader->hasPath($config['xml_path']);
+ $expected = $config['expected'];
+ $this->assertSame($expected, $actual);
+ }
+
+ public function envHasPathDataProvider(): Generator
+ {
+ yield 'hasPath' => [
+ [
+ 'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
+ 'xml_path' => 'default/general/store_information/name',
+ 'expected' => true,
+ ]
+ ];
+ yield 'hasNotPath' => [
+ [
+ 'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
+ 'xml_path' => 'foo/foo/foo',
+ 'expected' => false,
+ ]
+ ];
+ }
+
/**
* @runInSeparateProcess
* @dataProvider envDoesNotOverrideOnWrongConfigKeysDataProvider
From d4b19fc4ea7ceb51ca4a65024f7abe6bb16f9386 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 23:24:32 +0100
Subject: [PATCH 21/53] feat: add "asArray" test
---
.../Helper/EnvironmentConfigLoaderTest.php | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 28aa98f6e88..482c8404963 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -199,6 +199,46 @@ public function envOverridesCorrectConfigKeysDataProvider(): Generator
]];
}
+ /**
+ * @runInSeparateProcess
+ * @dataProvider envAsArrayDataProvider
+ * @group Mage_Core
+ *
+ * @param array $config
+ */
+ public function testAsArray(array $config): void
+ {
+ // phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
+ $loader = new Mage_Core_Helper_EnvironmentConfigLoader();
+ $loader->setEnvStore([
+ 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
+ $config['env_path'] => 1,
+ ]);
+ $actual = $loader->getAsArray($config['scope']);
+ $expected = $config['expected'];
+ $this->assertSame($expected, $actual);
+ }
+
+ public function envAsArrayDataProvider(): Generator
+ {
+ yield 'defaultScope' => [
+ [
+ 'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
+ 'scope' => 'default',
+ 'expected' => [
+ 'general/store_information/name' => 1,
+ ],
+ ]
+ ];
+ yield 'invalidScope' => [
+ [
+ 'env_path' => '',
+ 'scope' => 'foo',
+ 'expected' => [],
+ ]
+ ];
+ }
+
/**
* @runInSeparateProcess
* @dataProvider envHasPathDataProvider
From 5bdea32b81ecec2e7e16510599450c5a006d2382 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Tue, 18 Feb 2025 23:39:28 +0100
Subject: [PATCH 22/53] tests: add test cases
---
.../Helper/EnvironmentConfigLoaderTest.php | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 482c8404963..19e67a5c77b 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -230,6 +230,15 @@ public function envAsArrayDataProvider(): Generator
],
]
];
+ yield 'storeScope' => [
+ [
+ 'env_path' => 'OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME',
+ 'scope' => 'stores',
+ 'expected' => [
+ 'general/store_information/name' => 1,
+ ],
+ ]
+ ];
yield 'invalidScope' => [
[
'env_path' => '',
@@ -261,13 +270,20 @@ public function testHasPath(array $config): void
public function envHasPathDataProvider(): Generator
{
- yield 'hasPath' => [
+ yield 'hasPath default' => [
[
'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
'xml_path' => 'default/general/store_information/name',
'expected' => true,
]
];
+ yield 'hasPath store' => [
+ [
+ 'env_path' => 'OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME',
+ 'xml_path' => 'stores/general/store_information/name',
+ 'expected' => true,
+ ]
+ ];
yield 'hasNotPath' => [
[
'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
From 5db0883daab641618d943bd31619dd1175cf8441 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sun, 9 Mar 2025 11:07:22 +0100
Subject: [PATCH 23/53] Update
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
Co-authored-by: Sven Reichel
---
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index b13109066c0..3bb94054fc6 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -203,7 +203,9 @@ public function getEnv(): array
}, ARRAY_FILTER_USE_KEY);
$this->envStore = $env;
}
- if (!isset($this->envStore[static::ENV_FEATURE_ENABLED])) {
+ if (!isset($this->envStore[static::ENV_FEATURE_ENABLED]) ||
+ (bool) $this->envStore[static::ENV_FEATURE_ENABLED] === false
+ ) {
$this->envStore = [];
return $this->envStore;
}
From bc8a222841fd577cd60ec1840dff4046c35f5345 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sun, 9 Mar 2025 22:54:58 +0100
Subject: [PATCH 24/53] fix: onStore(re)init the env vars would be lost
---
app/code/core/Mage/Core/Model/App.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/code/core/Mage/Core/Model/App.php b/app/code/core/Mage/Core/Model/App.php
index 7a6ba001d29..1ee74c67386 100644
--- a/app/code/core/Mage/Core/Model/App.php
+++ b/app/code/core/Mage/Core/Model/App.php
@@ -634,6 +634,7 @@ public function reinitStores()
*/
protected function _initStores()
{
+ Mage::unregister('current_env_config');
$this->_stores = [];
$this->_groups = [];
$this->_website = null;
From 85cb4ff8c5988d53c4bff36278533665162c1ef6 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 16 Jun 2025 18:13:36 +0200
Subject: [PATCH 25/53] envLoader: fix loading from scopes
---
.../Adminhtml/Block/System/Config/Form.php | 4 ++-
.../core/Mage/Adminhtml/Model/Config/Data.php | 3 +-
.../Core/Helper/EnvironmentConfigLoader.php | 33 +++++++++----------
3 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 183988b17e9..5a1f39f66d4 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -661,7 +661,9 @@ public function isOverwrittenByEnvVariable(string $path): bool
{
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
- $path = $this->getScope() . '/' . $path;
+ $store = Mage::app()->getRequest()->getParam('store');
+ $scope = $this->getScope();
+ $path = "$scope/$store/$path";
return $environmentConfigLoaderHelper->hasPath($path);
}
diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
index 204569b8bd3..d66f223148f 100644
--- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php
+++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
@@ -358,7 +358,8 @@ protected function _getPathConfig($path, $full = true)
if (!$full) {
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
- $envConfig = $environmentConfigLoaderHelper->getAsArray($this->getScope());
+ $store = $this->getStore();
+ $envConfig = $environmentConfigLoaderHelper->getAsArray($store);
$config = array_merge($config, $envConfig);
}
return $config;
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 3bb94054fc6..cd28a7b8b05 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -88,7 +88,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
- [$unused1, $unused2, $code, $section, $group, $field] = $configKeyParts;
+ [$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$storeCode = strtolower($storeCode);
$scope = strtolower($scope);
@@ -136,9 +136,11 @@ public function hasPath(string $wantedPath): bool
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
- list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
+ [$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
- $nodePath = $this->buildNodePath($scope, $path);
+ $storeCode = strtolower($storeCode);
+ $scope = strtolower($scope);
+ $nodePath = sprintf('%s/%s/%s', $scope, $storeCode, $path);
$config[$nodePath] = $value;
break;
}
@@ -148,9 +150,9 @@ public function hasPath(string $wantedPath): bool
return $hasConfig;
}
- public function getAsArray(string $wantedScope): array
+ public function getAsArray(string $wantedStore): array
{
- $data = Mage::registry("config_env_array_$wantedScope");
+ $data = Mage::registry("config_env_array_$wantedStore");
if ($data !== null) {
return $data;
}
@@ -163,26 +165,20 @@ public function getAsArray(string $wantedScope): array
}
list($configKeyParts, $scope) = $this->getConfigKey($configKey);
- if (strtolower($scope) !== strtolower($wantedScope)) {
- continue;
- }
switch ($scope) {
- case static::CONFIG_KEY_DEFAULT:
- list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
- $path = $this->buildPath($section, $group, $field);
- $config[$path] = $value;
- break;
-
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
- list($unused1, $unused2, $storeCode, $section, $group, $field) = $configKeyParts;
+ [$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
+ if (strtolower($storeCode) !== strtolower($wantedStore)) {
+ break;
+ }
$path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
}
}
- Mage::register("config_env_array_$wantedScope", $config);
+ Mage::register("config_env_array_$wantedStore", $config);
return $config;
}
@@ -218,8 +214,11 @@ protected function setCache(Mage_Core_Model_Store $store, $value, string $path):
$refProperty = $refObject->getProperty('_configCache');
$refProperty->setAccessible(true);
$configCache = $refProperty->getValue($store);
+ if (!is_array($configCache)) {
+ $configCache = [];
+ }
$configCache[$path] = $value;
- $refProperty->setValue($store, $configCache);
+ $store->setConfigCache($configCache);
}
protected function getConfigKey(string $configKey): array
From 4e70ac78f6dd89285711b246594cf8a55397c74f Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 16 Jun 2025 18:17:21 +0200
Subject: [PATCH 26/53] chore: run phpcs
---
.../Helper/EnvironmentConfigLoaderTest.php | 30 +++++++++----------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 19e67a5c77b..a9c7273ca55 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -60,16 +60,16 @@ public function testEnvFilter(): void
]);
// empty because env flag is not set
$env = $environmentConfigLoaderHelper->getEnv();
- $this->assertIsArray($env);
- $this->assertEmpty($env);
+ static::assertIsArray($env);
+ static::assertEmpty($env);
$environmentConfigLoaderHelper->setEnvStore([
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value',
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1, // enable feature
]);
// flag is set => feature is enabled
$env = $environmentConfigLoaderHelper->getEnv();
- $this->assertIsArray($env);
- $this->assertNotEmpty($env);
+ static::assertIsArray($env);
+ static::assertNotEmpty($env);
}
/**
@@ -216,7 +216,7 @@ public function testAsArray(array $config): void
]);
$actual = $loader->getAsArray($config['scope']);
$expected = $config['expected'];
- $this->assertSame($expected, $actual);
+ static::assertSame($expected, $actual);
}
public function envAsArrayDataProvider(): Generator
@@ -228,7 +228,7 @@ public function envAsArrayDataProvider(): Generator
'expected' => [
'general/store_information/name' => 1,
],
- ]
+ ],
];
yield 'storeScope' => [
[
@@ -237,14 +237,14 @@ public function envAsArrayDataProvider(): Generator
'expected' => [
'general/store_information/name' => 1,
],
- ]
+ ],
];
yield 'invalidScope' => [
[
'env_path' => '',
'scope' => 'foo',
'expected' => [],
- ]
+ ],
];
}
@@ -265,31 +265,31 @@ public function testHasPath(array $config): void
]);
$actual = $loader->hasPath($config['xml_path']);
$expected = $config['expected'];
- $this->assertSame($expected, $actual);
+ static::assertSame($expected, $actual);
}
public function envHasPathDataProvider(): Generator
{
yield 'hasPath default' => [
[
- 'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
- 'xml_path' => 'default/general/store_information/name',
- 'expected' => true,
- ]
+ 'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
+ 'xml_path' => 'default/general/store_information/name',
+ 'expected' => true,
+ ],
];
yield 'hasPath store' => [
[
'env_path' => 'OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME',
'xml_path' => 'stores/general/store_information/name',
'expected' => true,
- ]
+ ],
];
yield 'hasNotPath' => [
[
'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
'xml_path' => 'foo/foo/foo',
'expected' => false,
- ]
+ ],
];
}
From df2e785a26a4d122265b39a2baeea5210c47d30e Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 16 Jun 2025 18:33:53 +0200
Subject: [PATCH 27/53] chore: phptan: add ignore line comment about internal
method
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index a9c7273ca55..42900f3fdb2 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -55,6 +55,7 @@ public function testBuildPath(): void
public function testEnvFilter(): void
{
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
+ /** @phpstan-ignore method.internal */
$environmentConfigLoaderHelper->setEnvStore([
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value',
]);
@@ -62,6 +63,7 @@ public function testEnvFilter(): void
$env = $environmentConfigLoaderHelper->getEnv();
static::assertIsArray($env);
static::assertEmpty($env);
+ /** @phpstan-ignore method.internal */
$environmentConfigLoaderHelper->setEnvStore([
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value',
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1, // enable feature
@@ -210,6 +212,7 @@ public function testAsArray(array $config): void
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
+ /** @phpstan-ignore method.internal */
$loader->setEnvStore([
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['env_path'] => 1,
@@ -259,6 +262,7 @@ public function testHasPath(array $config): void
{
// phpcs:ignore Ecg.Classes.ObjectInstantiation.DirectInstantiation
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
+ /** @phpstan-ignore method.internal */
$loader->setEnvStore([
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['env_path'] => 1,
From d004ce726b4d4d71ccf2dffddc0785a513334163 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 16 Jun 2025 19:23:40 +0200
Subject: [PATCH 28/53] envLoader: fix tests, fix scope default
---
.../Adminhtml/Block/System/Config/Form.php | 8 +++--
.../Core/Helper/EnvironmentConfigLoader.php | 8 +++++
.../Helper/EnvironmentConfigLoaderTest.php | 32 ++++++++++++-------
3 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 5a1f39f66d4..5c48a55da63 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -662,8 +662,12 @@ public function isOverwrittenByEnvVariable(string $path): bool
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
$store = Mage::app()->getRequest()->getParam('store');
- $scope = $this->getScope();
- $path = "$scope/$store/$path";
+ if ($store) {
+ $scope = $this->getScope();
+ $path = "$scope/$store/$path";
+ return $environmentConfigLoaderHelper->hasPath($path);
+ }
+ $path = "default/$path";
return $environmentConfigLoaderHelper->hasPath($path);
}
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index cd28a7b8b05..70298714d8c 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -152,6 +152,9 @@ public function hasPath(string $wantedPath): bool
public function getAsArray(string $wantedStore): array
{
+ if (empty($wantedStore)) {
+ $wantedStore = 'default';
+ }
$data = Mage::registry("config_env_array_$wantedStore");
if ($data !== null) {
return $data;
@@ -167,6 +170,11 @@ public function getAsArray(string $wantedStore): array
list($configKeyParts, $scope) = $this->getConfigKey($configKey);
switch ($scope) {
+ case static::CONFIG_KEY_DEFAULT:
+ list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
+ $path = $this->buildPath($section, $group, $field);
+ $config[$path] = $value;
+ break;
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
[$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 42900f3fdb2..33b68a15c26 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -115,12 +115,14 @@ public function testEnvOverridesForValidConfigKeys(array $config): void
$xml = new Varien_Simplexml_Config();
$xml->loadString($xmlStruct);
+
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
/** @phpstan-ignore method.internal */
$loader->setEnvStore([
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['env_path'] => $config['value'],
]);
+ Mage::unregister('current_env_config');
$loader->overrideEnvironment($xml);
$configPath = $config['xml_path'];
@@ -128,7 +130,9 @@ public function testEnvOverridesForValidConfigKeys(array $config): void
$valueAfterOverride = $xml->getNode($configPath);
// assert
- self::assertNotSame((string) $defaultValue, (string) $valueAfterOverride, 'Default value was not overridden.');
+ $expected = (string) $defaultValue;
+ $actual = (string) $valueAfterOverride;
+ static::assertNotSame($expected, $actual, 'Default value was not overridden.');
}
public function envOverridesCorrectConfigKeysDataProvider(): Generator
@@ -217,35 +221,36 @@ public function testAsArray(array $config): void
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['env_path'] => 1,
]);
- $actual = $loader->getAsArray($config['scope']);
+ $store = $config['store'];
+ $actual = $loader->getAsArray($store);
$expected = $config['expected'];
static::assertSame($expected, $actual);
}
public function envAsArrayDataProvider(): Generator
{
- yield 'defaultScope' => [
+ yield 'default' => [
[
'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
- 'scope' => 'default',
+ 'store' => '', // or 'default', which will be used internally, but this is how \Mage_Adminhtml_Model_Config_Data::_validate defines it
'expected' => [
'general/store_information/name' => 1,
],
],
];
- yield 'storeScope' => [
+ yield 'store' => [
[
'env_path' => 'OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME',
- 'scope' => 'stores',
+ 'store' => 'german',
'expected' => [
'general/store_information/name' => 1,
],
],
];
- yield 'invalidScope' => [
+ yield 'invalidStore' => [
[
'env_path' => '',
- 'scope' => 'foo',
+ 'store' => 'foo',
'expected' => [],
],
];
@@ -284,7 +289,7 @@ public function envHasPathDataProvider(): Generator
yield 'hasPath store' => [
[
'env_path' => 'OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME',
- 'xml_path' => 'stores/general/store_information/name',
+ 'xml_path' => 'stores/german/general/store_information/name',
'expected' => true,
],
];
@@ -315,11 +320,14 @@ public function testEnvDoesNotOverrideForInvalidConfigKeys(array $config): void
$xml->loadString($xmlStruct);
$defaultValue = 'test_default';
- self::assertSame($defaultValue, (string) $xml->getNode(self::XML_PATH_DEFAULT));
+ $actual = (string) $xml->getNode(self::XML_PATH_DEFAULT);
+ static::assertSame($defaultValue, $actual);
$defaultWebsiteValue = 'test_website';
- self::assertSame($defaultWebsiteValue, (string) $xml->getNode(self::XML_PATH_WEBSITE));
+ $actual = (string) $xml->getNode(self::XML_PATH_WEBSITE);
+ static::assertSame($defaultWebsiteValue, $actual);
$defaultStoreValue = 'test_store';
- self::assertSame($defaultStoreValue, (string) $xml->getNode(self::XML_PATH_STORE));
+ $actual = (string) $xml->getNode(self::XML_PATH_STORE);
+ static::assertSame($defaultStoreValue, $actual);
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
/** @phpstan-ignore method.internal */
From 3706ce5eb241dbf93ce783fa57120e1b64a32098 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Mon, 16 Jun 2025 20:29:22 +0200
Subject: [PATCH 29/53] chore: run rector:fix
---
.../core/Mage/Core/Helper/EnvironmentConfigLoader.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 70298714d8c..8495ba7ea9a 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -124,11 +124,11 @@ public function hasPath(string $wantedPath): bool
continue;
}
- list($configKeyParts, $scope) = $this->getConfigKey($configKey);
+ [$configKeyParts, $scope] = $this->getConfigKey($configKey);
switch ($scope) {
case static::CONFIG_KEY_DEFAULT:
- list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
+ [$unused1, $unused2, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$nodePath = $this->buildNodePath($scope, $path);
$config[$nodePath] = $value;
@@ -167,11 +167,11 @@ public function getAsArray(string $wantedStore): array
continue;
}
- list($configKeyParts, $scope) = $this->getConfigKey($configKey);
+ [$configKeyParts, $scope] = $this->getConfigKey($configKey);
switch ($scope) {
case static::CONFIG_KEY_DEFAULT:
- list($unused1, $unused2, $section, $group, $field) = $configKeyParts;
+ [$unused1, $unused2, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
From 18a9f22697b1f1b29645fccf38132509ce4cf0a6 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 19 Jun 2025 20:16:14 +0200
Subject: [PATCH 30/53] Update
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 33b68a15c26..8023679def7 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -243,7 +243,7 @@ public function envAsArrayDataProvider(): Generator
'env_path' => 'OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME',
'store' => 'german',
'expected' => [
- 'general/store_information/name' => 1,
+ self::XML_PATH_GENERAL => 1,
],
],
];
From 52bfe3f54fbbd716f607f941c72c57fad5cc0753 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 19 Jun 2025 20:16:26 +0200
Subject: [PATCH 31/53] Update
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
---
tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 8023679def7..52c201a26a3 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -234,7 +234,7 @@ public function envAsArrayDataProvider(): Generator
'env_path' => 'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME',
'store' => '', // or 'default', which will be used internally, but this is how \Mage_Adminhtml_Model_Config_Data::_validate defines it
'expected' => [
- 'general/store_information/name' => 1,
+ self::XML_PATH_GENERAL => 1,
],
],
];
From 1fb4b43f265946a60ef683c1ae3c8c79a2bef986 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 19 Jun 2025 20:20:44 +0200
Subject: [PATCH 32/53] sonar update
---
.../Core/Helper/EnvironmentConfigLoader.php | 26 ++++++++++++-------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 8495ba7ea9a..d5d0bf59eb8 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -72,7 +72,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
switch ($scope) {
case static::CONFIG_KEY_DEFAULT:
- [$unused1, $unused2, $section, $group, $field] = $configKeyParts;
+ [$section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$nodePath = $this->buildNodePath($scope, $path);
$xmlConfig->setNode($nodePath, $value);
@@ -81,14 +81,14 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
$store = Mage::app()->getStore($store);
$this->setCache($store, $value, $path);
}
- } catch (Throwable $exception) {
+ } catch (Throwable) {
// invalid store, intentionally empty
}
break;
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
- [$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
+ [$storeCode, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$storeCode = strtolower($storeCode);
$scope = strtolower($scope);
@@ -101,7 +101,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
$this->setCache($store, $value, $path);
}
}
- } catch (Throwable $exception) {
+ } catch (Throwable) {
// invalid store, intentionally empty
}
break;
@@ -110,6 +110,9 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
Mage::register('current_env_config', true, true);
}
+ /**
+ * @throws Mage_Core_Exception
+ */
public function hasPath(string $wantedPath): bool
{
$data = Mage::registry("config_env_has_path_$wantedPath");
@@ -128,7 +131,7 @@ public function hasPath(string $wantedPath): bool
switch ($scope) {
case static::CONFIG_KEY_DEFAULT:
- [$unused1, $unused2, $section, $group, $field] = $configKeyParts;
+ [$section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$nodePath = $this->buildNodePath($scope, $path);
$config[$nodePath] = $value;
@@ -136,7 +139,7 @@ public function hasPath(string $wantedPath): bool
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
- [$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
+ [$storeCode, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$storeCode = strtolower($storeCode);
$scope = strtolower($scope);
@@ -150,6 +153,9 @@ public function hasPath(string $wantedPath): bool
return $hasConfig;
}
+ /**
+ * @throws Mage_Core_Exception
+ */
public function getAsArray(string $wantedStore): array
{
if (empty($wantedStore)) {
@@ -171,13 +177,13 @@ public function getAsArray(string $wantedStore): array
switch ($scope) {
case static::CONFIG_KEY_DEFAULT:
- [$unused1, $unused2, $section, $group, $field] = $configKeyParts;
+ [$section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
- [$unused1, $unused2, $storeCode, $section, $group, $field] = $configKeyParts;
+ [$storeCode, $section, $group, $field] = $configKeyParts;
if (strtolower($storeCode) !== strtolower($wantedStore)) {
break;
}
@@ -238,7 +244,9 @@ protected function getConfigKey(string $configKey): array
),
'trim',
);
- [$unused, $scope] = $configKeyParts;
+
+ array_shift($configKeyParts);
+ $scope = array_shift($configKeyParts);
return [$configKeyParts, $scope];
}
From e940eacbbadb83f0f97b40368302458f78ad7491 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 19 Jun 2025 21:06:32 +0200
Subject: [PATCH 33/53] fix
---
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index d5d0bf59eb8..49811421f96 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -245,7 +245,7 @@ protected function getConfigKey(string $configKey): array
'trim',
);
- array_shift($configKeyParts);
+ unset($configKeyParts[0]);
$scope = array_shift($configKeyParts);
return [$configKeyParts, $scope];
}
From 99794bae1c6f9c131cce3b7a5a2ab27b49e5cf49 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Fri, 20 Jun 2025 17:40:01 +0200
Subject: [PATCH 34/53] phpstan L10
---
.../Core/Helper/EnvironmentConfigLoader.php | 106 ++++++++++++------
1 file changed, 70 insertions(+), 36 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 49811421f96..de02909b803 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -14,16 +14,13 @@
*/
class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
{
- protected const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
- protected const ENV_FEATURE_ENABLED = 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED';
- protected const ENV_KEY_SEPARATOR = '__';
-
- protected const CONFIG_KEY_DEFAULT = 'DEFAULT';
-
- protected const CONFIG_KEY_WEBSITES = 'WEBSITES';
-
- protected const CONFIG_KEY_STORES = 'STORES';
-
+ public const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
+ public const ENV_FEATURE_ENABLED = 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED';
+ public const ENV_KEY_SEPARATOR = '__';
+ public const CONFIG_KEY_DEFAULT = 'DEFAULT';
+ public const CONFIG_KEY_WEBSITES = 'WEBSITES';
+ public const CONFIG_KEY_STORES = 'STORES';
+ public const REGISTRY_KEY = 'current_env_config';
/**
* To be used as regex condition
*/
@@ -31,6 +28,9 @@ class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
protected $_moduleName = 'Mage_Core';
+ /**
+ * @var array
+ */
protected array $envStore = [];
/**
@@ -54,10 +54,11 @@ class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
* @example OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME=store_german
*
* @return void
+ * @throws Mage_Core_Exception
*/
public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
{
- $data = Mage::registry('current_env_config');
+ $data = Mage::registry(self::REGISTRY_KEY);
if ($data) {
return;
}
@@ -71,7 +72,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
[$configKeyParts, $scope] = $this->getConfigKey($configKey);
switch ($scope) {
- case static::CONFIG_KEY_DEFAULT:
+ case self::CONFIG_KEY_DEFAULT:
[$section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$nodePath = $this->buildNodePath($scope, $path);
@@ -79,15 +80,17 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
try {
foreach (['0', 'admin'] as $store) {
$store = Mage::app()->getStore($store);
- $this->setCache($store, $value, $path);
+ if ($store instanceof Mage_Core_Model_Store) {
+ $this->setCache($store, $value, $path);
+ }
}
} catch (Throwable) {
// invalid store, intentionally empty
}
break;
- case static::CONFIG_KEY_WEBSITES:
- case static::CONFIG_KEY_STORES:
+ case self::CONFIG_KEY_WEBSITES:
+ case self::CONFIG_KEY_STORES:
[$storeCode, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$storeCode = strtolower($storeCode);
@@ -98,7 +101,9 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
if (!str_contains($nodePath, 'websites')) {
foreach ([$storeCode, 'admin'] as $store) {
$store = Mage::app()->getStore($store);
- $this->setCache($store, $value, $path);
+ if ($store instanceof Mage_Core_Model_Store) {
+ $this->setCache($store, $value, $path);
+ }
}
}
} catch (Throwable) {
@@ -107,7 +112,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
break;
}
}
- Mage::register('current_env_config', true, true);
+ Mage::register(self::REGISTRY_KEY, true, true);
}
/**
@@ -115,6 +120,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
*/
public function hasPath(string $wantedPath): bool
{
+ /** @var bool|null $data */
$data = Mage::registry("config_env_has_path_$wantedPath");
if ($data !== null) {
return $data;
@@ -130,15 +136,15 @@ public function hasPath(string $wantedPath): bool
[$configKeyParts, $scope] = $this->getConfigKey($configKey);
switch ($scope) {
- case static::CONFIG_KEY_DEFAULT:
+ case self::CONFIG_KEY_DEFAULT:
[$section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$nodePath = $this->buildNodePath($scope, $path);
$config[$nodePath] = $value;
break;
- case static::CONFIG_KEY_WEBSITES:
- case static::CONFIG_KEY_STORES:
+ case self::CONFIG_KEY_WEBSITES:
+ case self::CONFIG_KEY_STORES:
[$storeCode, $section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$storeCode = strtolower($storeCode);
@@ -154,6 +160,7 @@ public function hasPath(string $wantedPath): bool
}
/**
+ * @return array
* @throws Mage_Core_Exception
*/
public function getAsArray(string $wantedStore): array
@@ -161,6 +168,8 @@ public function getAsArray(string $wantedStore): array
if (empty($wantedStore)) {
$wantedStore = 'default';
}
+
+ /** @var array|null $data */
$data = Mage::registry("config_env_array_$wantedStore");
if ($data !== null) {
return $data;
@@ -176,13 +185,13 @@ public function getAsArray(string $wantedStore): array
[$configKeyParts, $scope] = $this->getConfigKey($configKey);
switch ($scope) {
- case static::CONFIG_KEY_DEFAULT:
+ case self::CONFIG_KEY_DEFAULT:
[$section, $group, $field] = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
- case static::CONFIG_KEY_WEBSITES:
- case static::CONFIG_KEY_STORES:
+ case self::CONFIG_KEY_WEBSITES:
+ case self::CONFIG_KEY_STORES:
[$storeCode, $section, $group, $field] = $configKeyParts;
if (strtolower($storeCode) !== strtolower($wantedStore)) {
break;
@@ -197,6 +206,7 @@ public function getAsArray(string $wantedStore): array
}
/**
+ * @param array $envStorage
* @internal method mostly for mocking
*/
public function setEnvStore(array $envStorage): void
@@ -204,17 +214,20 @@ public function setEnvStore(array $envStorage): void
$this->envStore = $envStorage;
}
+ /**
+ * @return array
+ */
public function getEnv(): array
{
if (empty($this->envStore)) {
$env = getenv();
$env = array_filter($env, function ($key) {
- return str_starts_with($key, static::ENV_STARTS_WITH);
+ return str_starts_with($key, self::ENV_STARTS_WITH);
}, ARRAY_FILTER_USE_KEY);
$this->envStore = $env;
}
- if (!isset($this->envStore[static::ENV_FEATURE_ENABLED]) ||
- (bool) $this->envStore[static::ENV_FEATURE_ENABLED] === false
+ if (!isset($this->envStore[self::ENV_FEATURE_ENABLED]) ||
+ (bool) $this->envStore[self::ENV_FEATURE_ENABLED] === false
) {
$this->envStore = [];
return $this->envStore;
@@ -222,7 +235,7 @@ public function getEnv(): array
return $this->envStore;
}
- protected function setCache(Mage_Core_Model_Store $store, $value, string $path): void
+ protected function setCache(Mage_Core_Model_Store $store, string $value, string $path): void
{
$refObject = new ReflectionObject($store);
$refProperty = $refObject->getProperty('_configCache');
@@ -235,33 +248,54 @@ protected function setCache(Mage_Core_Model_Store $store, $value, string $path):
$store->setConfigCache($configCache);
}
+ /**
+ * @return array{array, string}
+ * @throws Mage_Core_Exception
+ */
protected function getConfigKey(string $configKey): array
{
$configKeyParts = array_filter(
explode(
- static::ENV_KEY_SEPARATOR,
+ self::ENV_KEY_SEPARATOR,
$configKey,
),
'trim',
);
unset($configKeyParts[0]);
+
$scope = array_shift($configKeyParts);
+ if (!is_string($scope)) {
+ throw new Mage_Core_Exception(
+ 'Invalid configuration key: ' . $configKey . '. Scope is not a string.',
+ );
+ }
+
return [$configKeyParts, $scope];
}
+ /**
+ * @throws Mage_Core_Exception
+ */
protected function isConfigKeyValid(string $configKey): bool
{
- $sectionGroupFieldRegexp = sprintf('([%s]*)', implode('', static::ALLOWED_CHARS));
- $allowedChars = sprintf('[%s]', implode('', static::ALLOWED_CHARS));
- $regexp = '/' . static::ENV_STARTS_WITH . static::ENV_KEY_SEPARATOR . '(WEBSITES' . static::ENV_KEY_SEPARATOR
- . $allowedChars . '+|DEFAULT|STORES' . static::ENV_KEY_SEPARATOR . $allowedChars . '+)'
- . static::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp
- . static::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp
- . static::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp . '/';
+ $sectionGroupFieldRegexp = sprintf('([%s]*)', implode('', self::ALLOWED_CHARS));
+ $allowedChars = sprintf('[%s]', implode('', self::ALLOWED_CHARS));
+ $regexp = '/' . self::ENV_STARTS_WITH . self::ENV_KEY_SEPARATOR . '(WEBSITES' . self::ENV_KEY_SEPARATOR
+ . $allowedChars . '+|DEFAULT|STORES' . self::ENV_KEY_SEPARATOR . $allowedChars . '+)'
+ . self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp
+ . self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp
+ . self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp . '/';
// /OPENMAGE_CONFIG__(WEBSITES__[A-Z-_]+|DEFAULT|STORES__[A-Z-_]+)__([A-Z-_]*)__([A-Z-_]*)__([A-Z-_]*)/
- return preg_match($regexp, $configKey);
+ $validatedConfigKey = preg_match($regexp, $configKey);
+ if ($validatedConfigKey === false) {
+ throw new Mage_Core_Exception(
+ 'Invalid configuration key: ' . $configKey . '. Regex match failed.',
+ );
+ }
+
+ return (bool) $validatedConfigKey;
}
/**
From 8a9cc9a09a9fb48e33ee47c8df370eb76acb5f7c Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Mon, 7 Jul 2025 05:06:05 +0200
Subject: [PATCH 35/53] update
---
.../Mage/Core/Helper/EnvironmentConfigLoader.php | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index de02909b803..bb2558ac763 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -264,12 +264,8 @@ protected function getConfigKey(string $configKey): array
unset($configKeyParts[0]);
+ /** @var string $scope */
$scope = array_shift($configKeyParts);
- if (!is_string($scope)) {
- throw new Mage_Core_Exception(
- 'Invalid configuration key: ' . $configKey . '. Scope is not a string.',
- );
- }
return [$configKeyParts, $scope];
}
@@ -288,14 +284,7 @@ protected function isConfigKeyValid(string $configKey): bool
. self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp . '/';
// /OPENMAGE_CONFIG__(WEBSITES__[A-Z-_]+|DEFAULT|STORES__[A-Z-_]+)__([A-Z-_]*)__([A-Z-_]*)__([A-Z-_]*)/
- $validatedConfigKey = preg_match($regexp, $configKey);
- if ($validatedConfigKey === false) {
- throw new Mage_Core_Exception(
- 'Invalid configuration key: ' . $configKey . '. Regex match failed.',
- );
- }
-
- return (bool) $validatedConfigKey;
+ return (bool) preg_match($regexp, $configKey);
}
/**
From d176292b0bfbddef2b9b55b18902375e775b71f6 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Thu, 23 Oct 2025 08:31:27 +0200
Subject: [PATCH 36/53] fix: run php-cs-fixer
---
.../Helper/EnvironmentConfigLoaderTest.php | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 52c201a26a3..503988e31b9 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -61,8 +61,8 @@ public function testEnvFilter(): void
]);
// empty because env flag is not set
$env = $environmentConfigLoaderHelper->getEnv();
- static::assertIsArray($env);
- static::assertEmpty($env);
+ self::assertIsArray($env);
+ self::assertEmpty($env);
/** @phpstan-ignore method.internal */
$environmentConfigLoaderHelper->setEnvStore([
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => 'some_value',
@@ -70,8 +70,8 @@ public function testEnvFilter(): void
]);
// flag is set => feature is enabled
$env = $environmentConfigLoaderHelper->getEnv();
- static::assertIsArray($env);
- static::assertNotEmpty($env);
+ self::assertIsArray($env);
+ self::assertNotEmpty($env);
}
/**
@@ -132,7 +132,7 @@ public function testEnvOverridesForValidConfigKeys(array $config): void
// assert
$expected = (string) $defaultValue;
$actual = (string) $valueAfterOverride;
- static::assertNotSame($expected, $actual, 'Default value was not overridden.');
+ self::assertNotSame($expected, $actual, 'Default value was not overridden.');
}
public function envOverridesCorrectConfigKeysDataProvider(): Generator
@@ -224,7 +224,7 @@ public function testAsArray(array $config): void
$store = $config['store'];
$actual = $loader->getAsArray($store);
$expected = $config['expected'];
- static::assertSame($expected, $actual);
+ self::assertSame($expected, $actual);
}
public function envAsArrayDataProvider(): Generator
@@ -274,7 +274,7 @@ public function testHasPath(array $config): void
]);
$actual = $loader->hasPath($config['xml_path']);
$expected = $config['expected'];
- static::assertSame($expected, $actual);
+ self::assertSame($expected, $actual);
}
public function envHasPathDataProvider(): Generator
@@ -321,13 +321,13 @@ public function testEnvDoesNotOverrideForInvalidConfigKeys(array $config): void
$defaultValue = 'test_default';
$actual = (string) $xml->getNode(self::XML_PATH_DEFAULT);
- static::assertSame($defaultValue, $actual);
+ self::assertSame($defaultValue, $actual);
$defaultWebsiteValue = 'test_website';
$actual = (string) $xml->getNode(self::XML_PATH_WEBSITE);
- static::assertSame($defaultWebsiteValue, $actual);
+ self::assertSame($defaultWebsiteValue, $actual);
$defaultStoreValue = 'test_store';
$actual = (string) $xml->getNode(self::XML_PATH_STORE);
- static::assertSame($defaultStoreValue, $actual);
+ self::assertSame($defaultStoreValue, $actual);
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
/** @phpstan-ignore method.internal */
From a03fd9edc0278aea2adc3c1dd6550c654ba698d7 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Thu, 23 Oct 2025 08:37:22 +0200
Subject: [PATCH 37/53] fix? phpstan?
---
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index bb2558ac763..1bb2c5e01c1 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -206,7 +206,7 @@ public function getAsArray(string $wantedStore): array
}
/**
- * @param array $envStorage
+ * @param array $envStorage
* @internal method mostly for mocking
*/
public function setEnvStore(array $envStorage): void
@@ -215,7 +215,7 @@ public function setEnvStore(array $envStorage): void
}
/**
- * @return array
+ * @return array
*/
public function getEnv(): array
{
From 9b03b4aae13d2db8c01b0f9db56716a534e45156 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Sun, 26 Oct 2025 19:46:10 +0100
Subject: [PATCH 38/53] chore: run rector fix
---
.../Adminhtml/Block/System/Config/Form.php | 3 +++
.../core/Mage/Adminhtml/Model/Config/Data.php | 1 +
.../Core/Helper/EnvironmentConfigLoader.php | 20 +++++++++++++++++++
.../Helper/EnvironmentConfigLoaderTest.php | 2 +-
4 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 5c48a55da63..92edfcc7a90 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -19,6 +19,7 @@ class Mage_Adminhtml_Block_System_Config_Form extends Mage_Adminhtml_Block_Widge
public const SCOPE_WEBSITES = 'websites';
public const SCOPE_STORES = 'stores';
+
public const SCOPE_ENV = 'env';
/**
@@ -405,6 +406,7 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
$elementFieldData['can_use_default_value'] = 0;
$elementFieldData['can_use_website_value'] = 0;
}
+
$field = $fieldset->addField($id, $fieldType, $elementFieldData);
$this->_prepareFieldOriginalData($field, $element);
@@ -667,6 +669,7 @@ public function isOverwrittenByEnvVariable(string $path): bool
$path = "$scope/$store/$path";
return $environmentConfigLoaderHelper->hasPath($path);
}
+
$path = "default/$path";
return $environmentConfigLoaderHelper->hasPath($path);
}
diff --git a/app/code/core/Mage/Adminhtml/Model/Config/Data.php b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
index d66f223148f..a09e91bc686 100644
--- a/app/code/core/Mage/Adminhtml/Model/Config/Data.php
+++ b/app/code/core/Mage/Adminhtml/Model/Config/Data.php
@@ -362,6 +362,7 @@ protected function _getPathConfig($path, $full = true)
$envConfig = $environmentConfigLoaderHelper->getAsArray($store);
$config = array_merge($config, $envConfig);
}
+
return $config;
}
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 1bb2c5e01c1..19dcbb78829 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -15,12 +15,19 @@
class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
{
public const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
+
public const ENV_FEATURE_ENABLED = 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED';
+
public const ENV_KEY_SEPARATOR = '__';
+
public const CONFIG_KEY_DEFAULT = 'DEFAULT';
+
public const CONFIG_KEY_WEBSITES = 'WEBSITES';
+
public const CONFIG_KEY_STORES = 'STORES';
+
public const REGISTRY_KEY = 'current_env_config';
+
/**
* To be used as regex condition
*/
@@ -62,6 +69,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
if ($data) {
return;
}
+
$env = $this->getEnv();
foreach ($env as $configKey => $value) {
@@ -87,6 +95,7 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
} catch (Throwable) {
// invalid store, intentionally empty
}
+
break;
case self::CONFIG_KEY_WEBSITES:
@@ -109,9 +118,11 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
} catch (Throwable) {
// invalid store, intentionally empty
}
+
break;
}
}
+
Mage::register(self::REGISTRY_KEY, true, true);
}
@@ -125,6 +136,7 @@ public function hasPath(string $wantedPath): bool
if ($data !== null) {
return $data;
}
+
$env = $this->getEnv();
$config = [];
@@ -154,6 +166,7 @@ public function hasPath(string $wantedPath): bool
break;
}
}
+
$hasConfig = array_key_exists($wantedPath, $config);
Mage::register("config_env_has_path_$wantedPath", $hasConfig);
return $hasConfig;
@@ -174,6 +187,7 @@ public function getAsArray(string $wantedStore): array
if ($data !== null) {
return $data;
}
+
$env = $this->getEnv();
$config = [];
@@ -196,11 +210,13 @@ public function getAsArray(string $wantedStore): array
if (strtolower($storeCode) !== strtolower($wantedStore)) {
break;
}
+
$path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
}
}
+
Mage::register("config_env_array_$wantedStore", $config);
return $config;
}
@@ -226,12 +242,14 @@ public function getEnv(): array
}, ARRAY_FILTER_USE_KEY);
$this->envStore = $env;
}
+
if (!isset($this->envStore[self::ENV_FEATURE_ENABLED]) ||
(bool) $this->envStore[self::ENV_FEATURE_ENABLED] === false
) {
$this->envStore = [];
return $this->envStore;
}
+
return $this->envStore;
}
@@ -240,10 +258,12 @@ protected function setCache(Mage_Core_Model_Store $store, string $value, string
$refObject = new ReflectionObject($store);
$refProperty = $refObject->getProperty('_configCache');
$refProperty->setAccessible(true);
+
$configCache = $refProperty->getValue($store);
if (!is_array($configCache)) {
$configCache = [];
}
+
$configCache[$path] = $value;
$store->setConfigCache($configCache);
}
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 503988e31b9..fa7a8ffabcd 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -21,7 +21,7 @@
/**
* @group Mage_Core_EnvLoader
*/
-class EnvironmentConfigLoaderTest extends OpenMageTest
+final class EnvironmentConfigLoaderTest extends OpenMageTest
{
public const XML_PATH_GENERAL = 'general/store_information/name';
From ee8e69bb9db9128c1390f4bf2b7571437e889253 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Tue, 28 Oct 2025 22:19:16 +0100
Subject: [PATCH 39/53] fix config
---
.../Adminhtml/Block/System/Config/Form.php | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 92edfcc7a90..6181877c200 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -20,7 +20,7 @@ class Mage_Adminhtml_Block_System_Config_Form extends Mage_Adminhtml_Block_Widge
public const SCOPE_STORES = 'stores';
- public const SCOPE_ENV = 'env';
+ public const SCOPE_ENV = 'env';
/**
* Config data array
@@ -663,14 +663,22 @@ public function isOverwrittenByEnvVariable(string $path): bool
{
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
- $store = Mage::app()->getRequest()->getParam('store');
- if ($store) {
- $scope = $this->getScope();
+
+ $scope = $this->getScope();
+ $store = Mage::app()->getRequest()->getParam('store');
+ $website = Mage::app()->getRequest()->getParam('website');
+
+ if ($store && $website) {
$path = "$scope/$store/$path";
return $environmentConfigLoaderHelper->hasPath($path);
}
- $path = "default/$path";
+ if ($website) {
+ $path = "$scope/$website/$path";
+ return $environmentConfigLoaderHelper->hasPath($path);
+ }
+
+ $path = "$scope/$path";
return $environmentConfigLoaderHelper->hasPath($path);
}
From eb5376c3020954e9ae3d18c22cb7df53b1046845 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Tue, 28 Oct 2025 22:19:43 +0100
Subject: [PATCH 40/53] refactor
---
.../Core/Helper/EnvironmentConfigLoader.php | 179 ++++++++++++------
.../EnvironmentConfigLoader/Override.php | 95 ++++++++++
2 files changed, 217 insertions(+), 57 deletions(-)
create mode 100644 app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 158cf9cd905..57976709fe1 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -77,20 +77,27 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
continue;
}
- [$configKeyParts, $scope] = $this->getConfigKey($configKey);
+ $override = $this->getConfigKey($configKey);
+ $scope = $override->getScope();
+ $storeCode = $override->getStoreCode();
+
+ $path = $this->buildPath($override->getSection(), $override->getGroup(), $override->getField());
switch ($scope) {
case self::CONFIG_KEY_DEFAULT:
- [$section, $group, $field] = $configKeyParts;
- $path = $this->buildPath($section, $group, $field);
- $nodePath = $this->buildNodePath($scope, $path);
- $xmlConfig->setNode($nodePath, $value);
try {
- foreach (['0', 'admin'] as $store) {
- $store = Mage::app()->getStore($store);
- if ($store instanceof Mage_Core_Model_Store) {
- $this->setCache($store, $value, $path);
- }
+ $store = Mage::app()->getStore(Mage_Core_Model_Store::ADMIN_CODE);
+ if ($store instanceof Mage_Core_Model_Store) {
+ $nodePath = $this->buildNodePath($scope, $path, $storeCode);
+ $xmlConfig->setNode($nodePath, $value);
+ $this->setCache($store, $value, $path);
+ }
+
+ $stores = Mage::app()->getStores(withDefault: true);
+ foreach ($stores as $store) {
+ $nodePath = $this->buildNodePath(self::CONFIG_KEY_STORES, $path, $store->getCode());
+ $xmlConfig->setNode($nodePath, $value);
+ $this->setCache($store, $value, $path);
}
} catch (Throwable) {
// invalid store, intentionally empty
@@ -99,18 +106,21 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
break;
case self::CONFIG_KEY_WEBSITES:
- case self::CONFIG_KEY_STORES:
- [$storeCode, $section, $group, $field] = $configKeyParts;
- $path = $this->buildPath($section, $group, $field);
- $storeCode = strtolower($storeCode);
- $scope = strtolower($scope);
- $nodePath = sprintf('%s/%s/%s', $scope, $storeCode, $path);
- $xmlConfig->setNode($nodePath, $value);
try {
- if (!str_contains($nodePath, 'websites')) {
- foreach ([$storeCode, 'admin'] as $store) {
- $store = Mage::app()->getStore($store);
- if ($store instanceof Mage_Core_Model_Store) {
+ $websites = Mage::app()->getWebsites();
+ foreach ($websites as $website) {
+ if (strtolower($website->getCode()) !== strtolower($storeCode)) {
+ continue;
+ }
+
+ $nodePath = $this->buildNodePath($scope, $path, $storeCode);
+ $xmlConfig->setNode($nodePath, $value);
+
+ $stores = $website->getStores();
+ foreach ($stores as $store) {
+ if ($store instanceof Mage_Core_Model_Store && $store->getId()) {
+ $nodePath = $this->buildNodePath(self::CONFIG_KEY_STORES, $path, $store->getCode());
+ $xmlConfig->setNode($nodePath, $value);
$this->setCache($store, $value, $path);
}
}
@@ -119,6 +129,24 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
// invalid store, intentionally empty
}
+ break;
+
+ case self::CONFIG_KEY_STORES:
+ try {
+ $stores = Mage::app()->getStores();
+ foreach ($stores as $store) {
+ if (strtolower($store->getCode()) !== strtolower($storeCode)) {
+ continue;
+ }
+
+ $nodePath = $this->buildNodePath($scope, $path, $store->getCode());
+ $xmlConfig->setNode($nodePath, $value);
+ $this->setCache($store, $value, $path);
+ }
+ } catch (Throwable) {
+ // invalid store, intentionally empty
+ }
+
break;
}
}
@@ -126,9 +154,6 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
Mage::register(self::REGISTRY_KEY, true, true);
}
- /**
- * @throws Mage_Core_Exception
- */
public function hasPath(string $wantedPath): bool
{
/** @var bool|null $data */
@@ -145,30 +170,73 @@ public function hasPath(string $wantedPath): bool
continue;
}
- [$configKeyParts, $scope] = $this->getConfigKey($configKey);
+ $override = $this->getConfigKey($configKey);
+ $scope = $override->getScope();
+ $path = $this->buildPath($override->getSection(), $override->getGroup(), $override->getField());
switch ($scope) {
case self::CONFIG_KEY_DEFAULT:
- [$section, $group, $field] = $configKeyParts;
- $path = $this->buildPath($section, $group, $field);
$nodePath = $this->buildNodePath($scope, $path);
$config[$nodePath] = $value;
+
+ try {
+ $websites = Mage::app()->getWebsites();
+ foreach ($websites as $website) {
+ $nodePath = $this->buildNodePath(self::CONFIG_KEY_WEBSITES, $path, $website->getCode());
+ $config[$nodePath] = $value;
+ }
+
+ $stores = Mage::app()->getStores(withDefault: true);
+ foreach ($stores as $store) {
+ $nodePath = $this->buildNodePath(self::CONFIG_KEY_STORES, $path, $store->getCode());
+ $config[$nodePath] = $value;
+ }
+ } catch (Throwable) {
+ // invalid store, intentionally empty
+ }
+
break;
case self::CONFIG_KEY_WEBSITES:
+ try {
+ $websites = Mage::app()->getWebsites();
+ foreach ($websites as $website) {
+ if (strtolower($website->getCode()) !== strtolower($override->getStoreCode())) {
+ continue;
+ }
+
+ $nodePath = $this->buildNodePath($scope, $path, $website->getCode());
+ $config[$nodePath] = $value;
+
+ $stores = $website->getStores();
+ foreach ($stores as $store) {
+ if ($store instanceof Mage_Core_Model_Store && $store->getId()) {
+ $nodePath = $this->buildNodePath(self::CONFIG_KEY_STORES, $path, $store->getCode());
+ $config[$nodePath] = $value;
+ }
+ }
+ }
+ } catch (Throwable) {
+ // invalid store, intentionally empty
+ }
+
+ break;
case self::CONFIG_KEY_STORES:
- [$storeCode, $section, $group, $field] = $configKeyParts;
- $path = $this->buildPath($section, $group, $field);
- $storeCode = strtolower($storeCode);
- $scope = strtolower($scope);
- $nodePath = sprintf('%s/%s/%s', $scope, $storeCode, $path);
+ $nodePath = $this->buildNodePath($scope, $path, $override->getStoreCode());
$config[$nodePath] = $value;
+
break;
}
}
$hasConfig = array_key_exists($wantedPath, $config);
- Mage::register("config_env_has_path_$wantedPath", $hasConfig);
+
+ try {
+ Mage::register("config_env_has_path_$wantedPath", $hasConfig);
+ } catch (Mage_Core_Exception $mageCoreException) {
+ Mage::logException($mageCoreException);
+ }
+
return $hasConfig;
}
@@ -196,22 +264,19 @@ public function getAsArray(string $wantedStore): array
continue;
}
- [$configKeyParts, $scope] = $this->getConfigKey($configKey);
+ $override = $this->getConfigKey($configKey);
+ $path = $this->buildPath($override->getSection(), $override->getGroup(), $override->getField());
- switch ($scope) {
+ switch ($override->getScope()) {
case self::CONFIG_KEY_DEFAULT:
- [$section, $group, $field] = $configKeyParts;
- $path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
case self::CONFIG_KEY_WEBSITES:
case self::CONFIG_KEY_STORES:
- [$storeCode, $section, $group, $field] = $configKeyParts;
- if (strtolower($storeCode) !== strtolower($wantedStore)) {
+ if (strtolower($override->getStoreCode()) !== strtolower($wantedStore)) {
break;
}
- $path = $this->buildPath($section, $group, $field);
$config[$path] = $value;
break;
}
@@ -257,7 +322,6 @@ protected function setCache(Mage_Core_Model_Store $store, string $value, string
{
$refObject = new ReflectionObject($store);
$refProperty = $refObject->getProperty('_configCache');
- $refProperty->setAccessible(true);
$configCache = $refProperty->getValue($store);
if (!is_array($configCache)) {
@@ -268,11 +332,7 @@ protected function setCache(Mage_Core_Model_Store $store, string $value, string
$store->setConfigCache($configCache);
}
- /**
- * @return array{array, string}
- * @throws Mage_Core_Exception
- */
- protected function getConfigKey(string $configKey): array
+ protected function getConfigKey(string $configKey): Mage_Core_Helper_EnvironmentConfigLoader_Override
{
$configKeyParts = array_filter(
explode(
@@ -282,17 +342,22 @@ protected function getConfigKey(string $configKey): array
trim(...),
);
- unset($configKeyParts[0]);
-
- /** @var string $scope */
- $scope = array_shift($configKeyParts);
-
- return [$configKeyParts, $scope];
+ $scope = $configKeyParts[1];
+ $isDefault = $scope === self::CONFIG_KEY_DEFAULT;
+ $storeCode = $isDefault ? '' : $configKeyParts[2];
+ $section = $isDefault ? $configKeyParts[2] : $configKeyParts[3];
+ $group = $isDefault ? $configKeyParts[3] : $configKeyParts[4];
+ $field = $isDefault ? $configKeyParts[4] : $configKeyParts[5];
+
+ return new Mage_Core_Helper_EnvironmentConfigLoader_Override(
+ scope: $scope,
+ section: $section,
+ group: $group,
+ field: $field,
+ storeCode: $storeCode,
+ );
}
- /**
- * @throws Mage_Core_Exception
- */
protected function isConfigKeyValid(string $configKey): bool
{
$sectionGroupFieldRegexp = sprintf('([%s]*)', implode('', self::ALLOWED_CHARS));
@@ -318,8 +383,8 @@ protected function buildPath(string $section, string $group, string $field): str
/**
* Build configuration node path.
*/
- protected function buildNodePath(string $scope, string $path): string
+ protected function buildNodePath(string $scope, string $path, string $storeCode = ''): string
{
- return strtolower($scope) . '/' . $path;
+ return strtolower($scope) . ($storeCode ? '/' . strtolower($storeCode) : '') . '/' . $path;
}
}
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php
new file mode 100644
index 00000000000..5c58a80fd99
--- /dev/null
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php
@@ -0,0 +1,95 @@
+scope = $scope;
+ $this->section = $section;
+ $this->group = $group;
+ $this->field = $field;
+ $this->storeCode = $storeCode;
+ }
+
+ public function setScope(string $scope): self
+ {
+ $this->scope = $scope;
+ return $this;
+ }
+
+ public function getScope(): string
+ {
+ return $this->scope;
+ }
+
+ public function setStoreCode(string $storeCode): self
+ {
+ $this->storeCode = $storeCode;
+ return $this;
+ }
+
+ public function getStoreCode(): string
+ {
+ return $this->storeCode;
+ }
+
+ public function setSection(string $section): self
+ {
+ $this->section = $section;
+ return $this;
+ }
+
+ public function getSection(): string
+ {
+ return $this->section;
+ }
+
+ public function setGroup(string $group): self
+ {
+ $this->group = $group;
+ return $this;
+ }
+
+ public function getGroup(): string
+ {
+ return $this->group;
+ }
+
+ public function setField(string $field): self
+ {
+ $this->field = $field;
+ return $this;
+ }
+
+ public function getField(): string
+ {
+ return $this->field;
+ }
+}
From f63fd1cf2d5c23080385f3b243221db72f15e57d Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Wed, 29 Oct 2025 02:09:33 +0100
Subject: [PATCH 41/53] update
---
.github/workflows/cypress.yml | 12 +++++++++++-
.../Core/Helper/EnvironmentConfigLoader/Override.php | 2 ++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml
index bd50d791a55..dfaef519fe7 100644
--- a/.github/workflows/cypress.yml
+++ b/.github/workflows/cypress.yml
@@ -21,7 +21,17 @@ jobs:
autostart: false
# install DDEV configuration
- - run: ddev config --project-type=magento --php-version=8.1 --webserver-type=${{ matrix.webserver }} --web-environment="MAGE_IS_DEVELOPER_MODE=1"
+ - run: ddev config \
+ --project-type=magento \
+ --php-version=8.1 \
+ --webserver-type=${{ matrix.webserver }} \
+ --web-environment="\
+ MAGE_IS_DEVELOPER_MODE=1,\
+ OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1,\
+ OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=ENV name default,\
+ OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__PHONE=ENV phone website,\
+ OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__ADDRESS=ENV address store\
+ "
# install composer dependencies
- run: ddev composer install
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php
index 5c58a80fd99..653669e1eae 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php
@@ -1,5 +1,7 @@
Date: Wed, 29 Oct 2025 02:20:50 +0100
Subject: [PATCH 42/53] update
---
.../Core/Helper/EnvironmentConfigLoader.php | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 57976709fe1..5f2dc79c754 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -59,11 +59,8 @@ class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
* @example OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__NAME=website
* Override the store 'german' configuration:
* @example OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME=store_german
- *
- * @return void
- * @throws Mage_Core_Exception
*/
- public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
+ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig): void
{
$data = Mage::registry(self::REGISTRY_KEY);
if ($data) {
@@ -151,7 +148,11 @@ public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
}
}
- Mage::register(self::REGISTRY_KEY, true, true);
+ try {
+ Mage::register(self::REGISTRY_KEY, true, true);
+ } catch (Mage_Core_Exception $mageCoreException) {
+ Mage::logException($mageCoreException);
+ }
}
public function hasPath(string $wantedPath): bool
@@ -242,7 +243,6 @@ public function hasPath(string $wantedPath): bool
/**
* @return array
- * @throws Mage_Core_Exception
*/
public function getAsArray(string $wantedStore): array
{
@@ -282,7 +282,12 @@ public function getAsArray(string $wantedStore): array
}
}
- Mage::register("config_env_array_$wantedStore", $config);
+ try {
+ Mage::register("config_env_array_$wantedStore", $config);
+ } catch (Mage_Core_Exception $mageCoreException) {
+ Mage::logException($mageCoreException);
+ }
+
return $config;
}
From 29f6d1594a2726145a81aa9ff74821e20b610fd2 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Wed, 29 Oct 2025 04:11:15 +0100
Subject: [PATCH 43/53] added cypress test
---
.../system/config/general/general.cy.js | 70 +++++++++++++++++++
cypress/support/e2e.js | 1 +
cypress/support/openmage/_utils/admin.js | 7 ++
cypress/support/openmage/_utils/test.js | 2 +
cypress/support/openmage/_utils/validation.js | 11 +--
.../backend/system/config/general/general.js | 50 +++++++++++++
6 files changed, 137 insertions(+), 4 deletions(-)
create mode 100644 cypress/e2e/openmage/backend/system/config/general/general.cy.js
create mode 100644 cypress/support/openmage/backend/system/config/general/general.js
diff --git a/cypress/e2e/openmage/backend/system/config/general/general.cy.js b/cypress/e2e/openmage/backend/system/config/general/general.cy.js
new file mode 100644
index 00000000000..f6439f401c1
--- /dev/null
+++ b/cypress/e2e/openmage/backend/system/config/general/general.cy.js
@@ -0,0 +1,70 @@
+const test = cy.openmage.test.backend.system.config.general.general.config;
+const validation = cy.openmage.validation;
+
+describe(`Checks admin system "${test.section.title}" settings`, () => {
+ beforeEach('Log in the user', () => {
+ cy.openmage.admin.login();
+ cy.openmage.admin.goToPage(test, test.section);
+ cy.openmage.admin.goToSection(test.section);
+ });
+
+ const fields = test.section.storeInformation.__fields;
+ const labelEnv = '[ENV]';
+ const labelStoreView = '[STORE VIEW]';
+
+ it(`tests ENV overide`, () => {
+ // test overrides in default config scope
+ cy.get(fields.name._).should('have.value', 'ENV name default');
+ cy.get(fields.name.label).should('have.text', labelEnv);
+
+ cy.get(fields.phone._).should('have.value', '');
+ cy.get(fields.phone.label).should('have.text', labelStoreView);
+
+ cy.get(fields.address._).should('have.value', '');
+ cy.get(fields.address.label).should('have.text', labelStoreView);
+
+ // test overrides in website scope
+ cy.openmage.admin.goToConfigScope(test.section, 'website_base');
+ cy.get(fields.name._).should('have.value', 'ENV name default');
+ cy.get(fields.name.label).should('have.text', labelEnv);
+
+ cy.get(fields.phone._).should('have.value', 'ENV phone website');
+ cy.get(fields.phone.label).should('have.text', labelEnv);
+
+ cy.get(fields.address._).should('have.value', '');
+ cy.get(fields.address.label).should('have.text', labelStoreView);
+
+ // test overrides in English/default store view
+ cy.openmage.admin.goToConfigScope(test.section, 'store_default');
+ cy.get(fields.name._).should('have.value', 'ENV name default');
+ cy.get(fields.name.label).should('have.text', labelEnv);
+
+ cy.get(fields.phone._).should('have.value', 'ENV phone website');
+ cy.get(fields.phone.label).should('have.text', labelEnv);
+
+ cy.get(fields.address._).should('have.value', '');
+ cy.get(fields.address.label).should('have.text', labelStoreView);
+
+ // test overrides in French store view
+ cy.openmage.admin.goToConfigScope(test.section, 'store_french');
+ cy.get(fields.name._).should('have.value', 'ENV name default');
+ cy.get(fields.name.label).should('have.text', labelEnv);
+
+ cy.get(fields.phone._).should('have.value', 'ENV phone website');
+ cy.get(fields.phone.label).should('have.text', labelEnv);
+
+ cy.get(fields.address._).should('have.value', '');
+ cy.get(fields.address.label).should('have.text', labelStoreView);
+
+ // test overrides in German store view
+ cy.openmage.admin.goToConfigScope(test.section, 'store_german');
+ cy.get(fields.name._).should('have.value', 'ENV name default');
+ cy.get(fields.name.label).should('have.text', labelEnv);
+
+ cy.get(fields.phone._).should('have.value', 'ENV phone website');
+ cy.get(fields.phone.label).should('have.text', labelEnv);
+
+ cy.get(fields.address._).should('have.value', 'ENV address store');
+ cy.get(fields.address.label).should('have.text', labelEnv);
+ });
+});
\ No newline at end of file
diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js
index f5ac2ca454f..aabf07d5eaa 100644
--- a/cypress/support/e2e.js
+++ b/cypress/support/e2e.js
@@ -52,6 +52,7 @@ import './openmage/backend/system/cache'
import './openmage/backend/system/config/catalog/configswatches'
import './openmage/backend/system/config/catalog/sitemap'
import './openmage/backend/system/config/customer/promo'
+import './openmage/backend/system/config/general/general'
import './openmage/backend/system/currency'
import './openmage/backend/system/design'
import './openmage/backend/system/email'
diff --git a/cypress/support/openmage/_utils/admin.js b/cypress/support/openmage/_utils/admin.js
index 32c1d4cae78..d3f31832fe2 100644
--- a/cypress/support/openmage/_utils/admin.js
+++ b/cypress/support/openmage/_utils/admin.js
@@ -41,6 +41,13 @@ cy.openmage.admin = {
cy.get(section._).click({force: true});
cy.url().should('include', section.url);
},
+ goToConfigScope: (section, value) =>{
+ cy.log('Go to store switcher config scope');
+ cy.log(`Clicking on "${value}" menu`);
+ const selector = 'select#store_switcher';
+ cy.get(selector).select(value); // acts like clicking
+ cy.url().should('include', section.url);
+ },
}
cy.openmage.admin.username = {
diff --git a/cypress/support/openmage/_utils/test.js b/cypress/support/openmage/_utils/test.js
index 1f1d48ce150..597889f4d18 100644
--- a/cypress/support/openmage/_utils/test.js
+++ b/cypress/support/openmage/_utils/test.js
@@ -287,6 +287,8 @@ cy.openmage.test.backend.system.config.catalog.configswatches = {};
cy.openmage.test.backend.system.config.catalog.sitemap = {};
cy.openmage.test.backend.system.config.customer = {};
cy.openmage.test.backend.system.config.customer.promo = {};
+cy.openmage.test.backend.system.config.general = {};
+cy.openmage.test.backend.system.config.general.general = {};
cy.openmage.test.backend.system.currency = {};
cy.openmage.test.backend.system.design = {};
cy.openmage.test.backend.system.email = {};
diff --git a/cypress/support/openmage/_utils/validation.js b/cypress/support/openmage/_utils/validation.js
index d542153be5d..1dd361a0f7c 100644
--- a/cypress/support/openmage/_utils/validation.js
+++ b/cypress/support/openmage/_utils/validation.js
@@ -20,10 +20,13 @@ cy.openmage.validation = {
cy.log('Filling fields with invalid values');
Object.keys(path.__fields).forEach(field => {
const selector = path.__fields[field]._;
- cy
- .get(selector)
- .clear({ force: true })
- .should('have.class', validation.css);
+
+ if (validation.css !== undefined) {
+ cy
+ .get(selector)
+ .clear({ force: true })
+ .should('have.class', validation.css);
+ }
if (value !== '') {
cy
diff --git a/cypress/support/openmage/backend/system/config/general/general.js b/cypress/support/openmage/backend/system/config/general/general.js
new file mode 100644
index 00000000000..e6e7cd037e6
--- /dev/null
+++ b/cypress/support/openmage/backend/system/config/general/general.js
@@ -0,0 +1,50 @@
+const base = cy.openmage.test.backend.__base;
+const test = cy.openmage.test.backend.system.config.general.general;
+
+/**
+ * Configuration for admin system "Google Sitemap" settings
+ * @type {{_: string, _nav: string, _title: string, url: string, section: {}}}
+ */
+test.config = {
+ _: '#nav-admin-system-config',
+ _nav: '#nav-admin-system',
+ _title: base._title,
+ url: 'system_config/index',
+ section: {},
+}
+
+/**
+ * Section "General"
+ * @type {{_: string, title: string, url: string}}
+ */
+test.config.section = {
+ _: '#section-general',
+ title: 'General',
+ url: 'system_config/edit/section/general',
+}
+
+/**
+ * Fields for "Store information" group
+ * @type {{__fields: {name: {_: string}, phone: {_: string}, hours: {_: string}, address: {_: string}}}}
+ */
+test.config.section.storeInformation = {
+ _: '#general_store_information-head',
+ __fields: {
+ name: {
+ _: '#general_store_information_name',
+ label: '#row_general_store_information_name .scope-label',
+ },
+ phone: {
+ _: '#general_store_information_phone',
+ label: '#row_general_store_information_phone .scope-label',
+ },
+ hours: {
+ _: '#general_store_information_hours',
+ label: '#row_general_store_information_hours .scope-label',
+ },
+ address: {
+ _: '#general_store_information_address',
+ label: '#row_general_store_information_address .scope-label',
+ },
+ }
+};
From fd19a2e78ae78fc66f6b1a237651b35e3e0df098 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 30 Oct 2025 00:22:31 +0100
Subject: [PATCH 44/53] Refactor web environment configuration in cypress.yml
---
.github/workflows/cypress.yml | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml
index dfaef519fe7..805ebeff0b3 100644
--- a/.github/workflows/cypress.yml
+++ b/.github/workflows/cypress.yml
@@ -25,13 +25,7 @@ jobs:
--project-type=magento \
--php-version=8.1 \
--webserver-type=${{ matrix.webserver }} \
- --web-environment="\
- MAGE_IS_DEVELOPER_MODE=1,\
- OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1,\
- OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=ENV name default,\
- OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__PHONE=ENV phone website,\
- OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__ADDRESS=ENV address store\
- "
+ --web-environment="MAGE_IS_DEVELOPER_MODE=1,OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1,OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=ENV name default,OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__PHONE=ENV phone website,OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__ADDRESS=ENV address store"
# install composer dependencies
- run: ddev composer install
From c130005239143e29dd5212790e5c626f1641ce05 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 30 Oct 2025 00:54:39 +0100
Subject: [PATCH 45/53] Simplify ddev config command in workflow
---
.github/workflows/cypress.yml | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml
index 805ebeff0b3..6b15d105912 100644
--- a/.github/workflows/cypress.yml
+++ b/.github/workflows/cypress.yml
@@ -21,11 +21,7 @@ jobs:
autostart: false
# install DDEV configuration
- - run: ddev config \
- --project-type=magento \
- --php-version=8.1 \
- --webserver-type=${{ matrix.webserver }} \
- --web-environment="MAGE_IS_DEVELOPER_MODE=1,OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1,OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=ENV name default,OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__PHONE=ENV phone website,OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__ADDRESS=ENV address store"
+ - run: ddev config --project-type=magento --php-version=8.1 --webserver-type=${{ matrix.webserver }} --web-environment="MAGE_IS_DEVELOPER_MODE=1,OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1,OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=ENV name default,OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__PHONE=ENV phone website,OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__ADDRESS=ENV address store"
# install composer dependencies
- run: ddev composer install
From ff3793dd00c8cae99399b6173c008d3dbe215859 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 30 Oct 2025 01:18:59 +0100
Subject: [PATCH 46/53] Update registration success message in tests
---
cypress/e2e/openmage/frontend/customer/account.cy.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/cypress/e2e/openmage/frontend/customer/account.cy.js b/cypress/e2e/openmage/frontend/customer/account.cy.js
index 5f3de042e87..2fbf105621a 100644
--- a/cypress/e2e/openmage/frontend/customer/account.cy.js
+++ b/cypress/e2e/openmage/frontend/customer/account.cy.js
@@ -48,7 +48,9 @@ describe('Checks customer account create', () => {
const lastname = 'Doe';
const password = '12345678';
- const message = 'Thank you for registering with Madison Island.';
+ // see PR: https://github.com/OpenMage/magento-lts/pull/4617
+ // const message = 'Thank you for registering with Madison Island.';
+ const message = 'Thank you for registering with ENV name default.';
const filename = 'message.customer.account.create.success';
cy.get(test.create.__fields.firstname._).type(firstname).should('have.value', firstname);
cy.get(test.create.__fields.lastname._).type(lastname).should('have.value', lastname);
From 75d9a3174275c7977fd01a4167d5d5cf9780f62e Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 30 Oct 2025 02:36:46 +0100
Subject: [PATCH 47/53] Update
cypress/e2e/openmage/backend/system/config/general/general.cy.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
.../e2e/openmage/backend/system/config/general/general.cy.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cypress/e2e/openmage/backend/system/config/general/general.cy.js b/cypress/e2e/openmage/backend/system/config/general/general.cy.js
index f6439f401c1..b04a627cb8b 100644
--- a/cypress/e2e/openmage/backend/system/config/general/general.cy.js
+++ b/cypress/e2e/openmage/backend/system/config/general/general.cy.js
@@ -12,7 +12,7 @@ describe(`Checks admin system "${test.section.title}" settings`, () => {
const labelEnv = '[ENV]';
const labelStoreView = '[STORE VIEW]';
- it(`tests ENV overide`, () => {
+ it(`tests ENV override`, () => {
// test overrides in default config scope
cy.get(fields.name._).should('have.value', 'ENV name default');
cy.get(fields.name.label).should('have.text', labelEnv);
From 491bac56cff3cc46ef0a28cc043a485e7a8b2c27 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 30 Oct 2025 02:37:17 +0100
Subject: [PATCH 48/53] Update
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
app/code/core/Mage/Adminhtml/Block/System/Config/Form.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
index 6181877c200..b13db6fa277 100644
--- a/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
+++ b/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php
@@ -401,7 +401,7 @@ public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labe
'can_use_website_value' => $this->canUseWebsiteValue((int) $element->show_in_website),
];
if ($this->isOverwrittenByEnvVariable($path)) {
- $elementFieldData['scope_label'] = $this->_scopeLabels[static::SCOPE_ENV];
+ $elementFieldData['scope_label'] = $this->_scopeLabels[self::SCOPE_ENV];
$elementFieldData['disabled'] = 1;
$elementFieldData['can_use_default_value'] = 0;
$elementFieldData['can_use_website_value'] = 0;
From ebc05f238949bb8dae528dee9a1188e01d3d4653 Mon Sep 17 00:00:00 2001
From: Sven Reichel
Date: Thu, 30 Oct 2025 02:37:42 +0100
Subject: [PATCH 49/53] Update
cypress/support/openmage/backend/system/config/general/general.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
.../support/openmage/backend/system/config/general/general.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cypress/support/openmage/backend/system/config/general/general.js b/cypress/support/openmage/backend/system/config/general/general.js
index e6e7cd037e6..68e2936a3f3 100644
--- a/cypress/support/openmage/backend/system/config/general/general.js
+++ b/cypress/support/openmage/backend/system/config/general/general.js
@@ -2,7 +2,7 @@ const base = cy.openmage.test.backend.__base;
const test = cy.openmage.test.backend.system.config.general.general;
/**
- * Configuration for admin system "Google Sitemap" settings
+ * Configuration for admin system "General" settings
* @type {{_: string, _nav: string, _title: string, url: string, section: {}}}
*/
test.config = {
From 8a887d11264cc13de2ef59de4318294988f1e5cd Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Thu, 30 Oct 2025 12:05:05 +0100
Subject: [PATCH 50/53] fix: websites do not allow "-" character, but A-Z0-9_,
starting with letter
---
app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
index 5f2dc79c754..f0c6ac61ad0 100644
--- a/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
+++ b/app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
@@ -368,11 +368,11 @@ protected function isConfigKeyValid(string $configKey): bool
$sectionGroupFieldRegexp = sprintf('([%s]*)', implode('', self::ALLOWED_CHARS));
$allowedChars = sprintf('[%s]', implode('', self::ALLOWED_CHARS));
$regexp = '/' . self::ENV_STARTS_WITH . self::ENV_KEY_SEPARATOR . '(WEBSITES' . self::ENV_KEY_SEPARATOR
- . $allowedChars . '+|DEFAULT|STORES' . self::ENV_KEY_SEPARATOR . $allowedChars . '+)'
+ . '[A-Z][A-Z0-9]' . '+|DEFAULT|STORES' . self::ENV_KEY_SEPARATOR . $allowedChars . '+)'
. self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp
. self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp
. self::ENV_KEY_SEPARATOR . $sectionGroupFieldRegexp . '/';
- // /OPENMAGE_CONFIG__(WEBSITES__[A-Z-_]+|DEFAULT|STORES__[A-Z-_]+)__([A-Z-_]*)__([A-Z-_]*)__([A-Z-_]*)/
+ // /OPENMAGE_CONFIG__(WEBSITES__[A-Z][A-Z0-9]+|DEFAULT|STORES__[A-Z-_]+)__([A-Z-_]*)__([A-Z-_]*)__([A-Z-_]*)/
return (bool) preg_match($regexp, $configKey);
}
From 29700dcefc628e411bb10f9bda9010a3603acda8 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Thu, 30 Oct 2025 12:08:08 +0100
Subject: [PATCH 51/53] fix: superflous website tests and testing suite
bootstrap
Websites may not have a "-" character so this test is removed
Removed website test for "base_ch", as its the same as "base", so superflous.
Add testing stores if not existing and remove afterwards.
---
.../Helper/EnvironmentConfigLoaderTest.php | 120 ++++++++++++++----
1 file changed, 93 insertions(+), 27 deletions(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index fa7a8ffabcd..d3756f75523 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -30,6 +30,15 @@ final class EnvironmentConfigLoaderTest extends OpenMageTest
public const XML_PATH_WEBSITE = 'websites/base/general/store_information/name';
public const XML_PATH_STORE = 'stores/german/general/store_information/name';
+ private const ENV_TEST_STORES = ['german_ch', 'german', 'german-at'];
+
+ private string $testXml;
+
+ private const WEBSITES = [
+ 'base' => self::ENV_TEST_STORES,
+ ];
+
+ private static array $storeData = [];
/**
* @throws Mage_Core_Exception
@@ -37,6 +46,38 @@ final class EnvironmentConfigLoaderTest extends OpenMageTest
public function setup(): void
{
Mage::setRoot();
+ $this->testXml = $this->getTestXml();
+ Mage::unregister(Mage_Core_Helper_EnvironmentConfigLoader::REGISTRY_KEY);
+ }
+
+ public static function setUpBeforeClass(): void
+ {
+ Mage::app('admin');
+ foreach (self::WEBSITES as $websiteCode => $stores) {
+ foreach ($stores as $storeCode) {
+ self::$storeData[$websiteCode][$storeCode] =
+ self::bootstrapTestStore($websiteCode, $storeCode);
+ }
+ }
+ }
+
+ public static function tearDownAfterClass(): void
+ {
+ foreach (array_keys(self::WEBSITES) as $websiteCode) {
+ self::cleanupTestWebsite($websiteCode);
+ }
+ }
+
+ public function testStoresAreCreated(): void
+ {
+ foreach (self::$storeData as $websiteCode => $stores) {
+ foreach ($stores as $storeCode => $data) {
+ $store = Mage::app()->getStore($data['store_id']);
+ $this->assertTrue((bool)$store->getIsActive(), "$storeCode is not active");
+ $this->assertEquals($data['store_id'], (int)$store->getId());
+ $this->assertEquals($data['website_id'], (int)$store->getWebsiteId());
+ }
+ }
}
/**
@@ -90,9 +131,8 @@ public function testBuildNodePath(): void
*/
public function testXmlHasTestStrings(): void
{
- $xmlStruct = $this->getTestXml();
$xml = new Varien_Simplexml_Config();
- $xml->loadString($xmlStruct);
+ $xml->loadString($this->testXml);
self::assertSame('test_default', (string) $xml->getNode(self::XML_PATH_DEFAULT));
self::assertSame('test_website', (string) $xml->getNode(self::XML_PATH_WEBSITE));
self::assertSame('test_store', (string) $xml->getNode(self::XML_PATH_STORE));
@@ -107,13 +147,11 @@ public function testXmlHasTestStrings(): void
*/
public function testEnvOverridesForValidConfigKeys(array $config): void
{
- $xmlStruct = $this->getTestXml();
-
$xmlDefault = new Varien_Simplexml_Config();
- $xmlDefault->loadString($xmlStruct);
+ $xmlDefault->loadString($this->testXml);
$xml = new Varien_Simplexml_Config();
- $xml->loadString($xmlStruct);
+ $xml->loadString($this->testXml);
$loader = new Mage_Core_Helper_EnvironmentConfigLoader();
@@ -122,7 +160,6 @@ public function testEnvOverridesForValidConfigKeys(array $config): void
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1,
$config['env_path'] => $config['value'],
]);
- Mage::unregister('current_env_config');
$loader->overrideEnvironment($xml);
$configPath = $config['xml_path'];
@@ -142,7 +179,6 @@ public function envOverridesCorrectConfigKeysDataProvider(): Generator
$defaultPathWithUnderscore = 'OPENMAGE_CONFIG__DEFAULT__GENERAL__FOO_BAR__NAME';
$websitePath = 'OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__NAME';
- $websiteWithDashPath = 'OPENMAGE_CONFIG__WEBSITES__BASE-AT__GENERAL__STORE_INFORMATION__NAME';
$websiteWithUnderscorePath = 'OPENMAGE_CONFIG__WEBSITES__BASE_CH__GENERAL__STORE_INFORMATION__NAME';
$storeWithDashPath = 'OPENMAGE_CONFIG__STORES__GERMAN-AT__GENERAL__STORE_INFORMATION__NAME';
@@ -191,18 +227,6 @@ public function envOverridesCorrectConfigKeysDataProvider(): Generator
'env_path' => $websitePath,
'value' => 'website_new_value',
]];
- yield 'Case WEBSITE overrides #2.' => [[
- 'case' => 'WEBSITE',
- 'xml_path' => 'websites/base_ch/general/store_information/name',
- 'env_path' => $websiteWithUnderscorePath,
- 'value' => 'website_new_value',
- ]];
- yield 'Case WEBSITE overrides #3.' => [[
- 'case' => 'WEBSITE',
- 'xml_path' => 'websites/base-at/general/store_information/name',
- 'env_path' => $websiteWithDashPath,
- 'value' => 'website_new_value',
- ]];
}
/**
@@ -404,13 +428,6 @@ public function getTestXml(): string
-
-
-
- test_website
-
-
-
@@ -445,4 +462,53 @@ public function getTestXml(): string
XML;
}
+
+ private static function bootstrapTestStore(string $websiteCode, string $storeCode): array
+ {
+ $website = Mage::getModel('core/website')->load($websiteCode, 'code');
+ if (!$website->getId()) {
+ $website->setCode($websiteCode)
+ ->setName(ucfirst($websiteCode) . ' Website')
+ ->save();
+ }
+
+ $storeGroup = Mage::getModel('core/store_group')
+ ->getCollection()
+ ->addFieldToFilter('website_id', $website->getId())
+ ->getFirstItem();
+
+ $store = Mage::getModel('core/store')->load($storeCode, 'code');
+ if (!$store->getId()) {
+ $store->setCode($storeCode)
+ ->setWebsiteId((int)$website->getId())
+ ->setGroupId((int)$storeGroup->getId())
+ ->setName(ucfirst($storeCode) . ' Store -- ENVTEST')
+ ->setIsActive(1)
+ ->save();
+ }
+
+ Mage::app()->cleanCache();
+ Mage::app()->reinitStores();
+ return [
+ 'website_id' => (int)$website->getId(),
+ 'store_group_id' => (int)$storeGroup->getId(),
+ 'store_id' => (int)$store->getId(),
+ ];
+ }
+
+ private static function cleanupTestWebsite(string $websiteCode): void
+ {
+ $website = Mage::getModel('core/website')->load($websiteCode, 'code');
+ $stores = Mage::getModel('core/store')
+ ->getCollection()
+ ->addFieldToFilter('website_id', $website->getId())
+ ->addFieldToFilter('code', [
+ 'in' => self::ENV_TEST_STORES,
+ ]);
+ foreach ($stores as $store) {
+ $store->delete();
+ }
+ Mage::app()->cleanCache();
+ Mage::app()->reinitStores();
+ }
}
From 188b270379e4abd4916d38470b6d560b93e1ff40 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Thu, 30 Oct 2025 12:10:29 +0100
Subject: [PATCH 52/53] chore: linter fixes
---
.../Core/Helper/EnvironmentConfigLoaderTest.php | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index d3756f75523..1f5625c6fa4 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -73,9 +73,9 @@ public function testStoresAreCreated(): void
foreach (self::$storeData as $websiteCode => $stores) {
foreach ($stores as $storeCode => $data) {
$store = Mage::app()->getStore($data['store_id']);
- $this->assertTrue((bool)$store->getIsActive(), "$storeCode is not active");
- $this->assertEquals($data['store_id'], (int)$store->getId());
- $this->assertEquals($data['website_id'], (int)$store->getWebsiteId());
+ self::assertTrue((bool) $store->getIsActive(), "$storeCode is not active");
+ self::assertEquals($data['store_id'], (int) $store->getId());
+ self::assertEquals($data['website_id'], (int) $store->getWebsiteId());
}
}
}
@@ -480,8 +480,8 @@ private static function bootstrapTestStore(string $websiteCode, string $storeCod
$store = Mage::getModel('core/store')->load($storeCode, 'code');
if (!$store->getId()) {
$store->setCode($storeCode)
- ->setWebsiteId((int)$website->getId())
- ->setGroupId((int)$storeGroup->getId())
+ ->setWebsiteId((int) $website->getId())
+ ->setGroupId((int) $storeGroup->getId())
->setName(ucfirst($storeCode) . ' Store -- ENVTEST')
->setIsActive(1)
->save();
@@ -490,9 +490,9 @@ private static function bootstrapTestStore(string $websiteCode, string $storeCod
Mage::app()->cleanCache();
Mage::app()->reinitStores();
return [
- 'website_id' => (int)$website->getId(),
- 'store_group_id' => (int)$storeGroup->getId(),
- 'store_id' => (int)$store->getId(),
+ 'website_id' => (int) $website->getId(),
+ 'store_group_id' => (int) $storeGroup->getId(),
+ 'store_id' => (int) $store->getId(),
];
}
From 2ccce2381b380f75f7943dc6f58e9b8ef3fefe19 Mon Sep 17 00:00:00 2001
From: Pascal Querner
Date: Thu, 30 Oct 2025 12:26:45 +0100
Subject: [PATCH 53/53] chore: run rector:fix
---
.../unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
index 1f5625c6fa4..4f74a820788 100644
--- a/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
+++ b/tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php
@@ -30,6 +30,7 @@ final class EnvironmentConfigLoaderTest extends OpenMageTest
public const XML_PATH_WEBSITE = 'websites/base/general/store_information/name';
public const XML_PATH_STORE = 'stores/german/general/store_information/name';
+
private const ENV_TEST_STORES = ['german_ch', 'german', 'german-at'];
private string $testXml;
@@ -70,9 +71,10 @@ public static function tearDownAfterClass(): void
public function testStoresAreCreated(): void
{
- foreach (self::$storeData as $websiteCode => $stores) {
+ foreach (self::$storeData as $stores) {
foreach ($stores as $storeCode => $data) {
$store = Mage::app()->getStore($data['store_id']);
+ self::assertInstanceOf(\Mage_Core_Model_Store::class, $store);
self::assertTrue((bool) $store->getIsActive(), "$storeCode is not active");
self::assertEquals($data['store_id'], (int) $store->getId());
self::assertEquals($data['website_id'], (int) $store->getWebsiteId());
@@ -419,7 +421,7 @@ public function getTestXml(): string
-
+
@@ -508,6 +510,7 @@ private static function cleanupTestWebsite(string $websiteCode): void
foreach ($stores as $store) {
$store->delete();
}
+
Mage::app()->cleanCache();
Mage::app()->reinitStores();
}