Skip to content

Commit 1c874bd

Browse files
authored
Merge pull request #8052 from magento-l3/ACP2E-1451
ACP2E-1451: Non-default configurations added as env variables break config import
2 parents 8e488b6 + feb3c26 commit 1c874bd

File tree

2 files changed

+61
-15
lines changed
  • app/code/Magento/Config/App/Config/Type
  • dev/tests/integration/testsuite/Magento/Config/App/Config/Type

2 files changed

+61
-15
lines changed

Diff for: app/code/Magento/Config/App/Config/Type/System.php

+40-15
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ class System implements ConfigTypeInterface
3636
/**
3737
* Config cache tag.
3838
*/
39-
const CACHE_TAG = 'config_scopes';
39+
public const CACHE_TAG = 'config_scopes';
4040

4141
/**
4242
* System config type.
4343
*/
44-
const CONFIG_TYPE = 'system';
44+
public const CONFIG_TYPE = 'system';
4545

4646
/**
4747
* @var string
@@ -173,8 +173,7 @@ public function __construct(
173173
public function get($path = '')
174174
{
175175
if ($path === '') {
176-
$this->data = array_replace_recursive($this->loadAllData(), $this->data);
177-
176+
$this->data = $this->loadAllData();
178177
return $this->data;
179178
}
180179

@@ -193,8 +192,7 @@ private function getWithParts($path)
193192

194193
if (count($pathParts) === 1 && $pathParts[0] !== ScopeInterface::SCOPE_DEFAULT) {
195194
if (!isset($this->data[$pathParts[0]])) {
196-
$data = $this->readData();
197-
$this->data = array_replace_recursive($data, $this->data);
195+
$this->readData();
198196
}
199197

200198
return $this->data[$pathParts[0]];
@@ -204,7 +202,8 @@ private function getWithParts($path)
204202

205203
if ($scopeType === ScopeInterface::SCOPE_DEFAULT) {
206204
if (!isset($this->data[$scopeType])) {
207-
$this->data = array_replace_recursive($this->loadDefaultScopeData($scopeType), $this->data);
205+
$scopeData = $this->loadDefaultScopeData() ?? [];
206+
$this->setDataByScopeType($scopeType, $scopeData);
208207
}
209208

210209
return $this->getDataByPathParts($this->data[$scopeType], $pathParts);
@@ -213,11 +212,8 @@ private function getWithParts($path)
213212
$scopeId = array_shift($pathParts);
214213

215214
if (!isset($this->data[$scopeType][$scopeId])) {
216-
$scopeData = $this->loadScopeData($scopeType, $scopeId);
217-
218-
if (!isset($this->data[$scopeType][$scopeId])) {
219-
$this->data = array_replace_recursive($scopeData, $this->data);
220-
}
215+
$scopeData = $this->loadScopeData($scopeType, $scopeId) ?? [];
216+
$this->setDataByScopeId($scopeType, $scopeId, $scopeData);
221217
}
222218

223219
return isset($this->data[$scopeType][$scopeId])
@@ -256,16 +252,16 @@ private function loadAllData()
256252
/**
257253
* Load configuration data for default scope.
258254
*
259-
* @param string $scopeType
260255
* @return array
261256
*/
262-
private function loadDefaultScopeData($scopeType)
257+
private function loadDefaultScopeData()
263258
{
264259
if (!$this->cacheState->isEnabled(Config::TYPE_IDENTIFIER)) {
265260
return $this->readData();
266261
}
267262

268-
$loadAction = function () use ($scopeType) {
263+
$loadAction = function () {
264+
$scopeType = ScopeInterface::SCOPE_DEFAULT;
269265
$cachedData = $this->cache->load($this->configType . '_' . $scopeType);
270266
$scopeData = false;
271267
if ($cachedData !== false) {
@@ -325,6 +321,35 @@ private function loadScopeData($scopeType, $scopeId)
325321
);
326322
}
327323

324+
/**
325+
* Sets data according to scope type.
326+
*
327+
* @param string|null $scopeType
328+
* @param array $scopeData
329+
* @return void
330+
*/
331+
private function setDataByScopeType(?string $scopeType, array $scopeData): void
332+
{
333+
if (!isset($this->data[$scopeType]) && isset($scopeData[$scopeType])) {
334+
$this->data[$scopeType] = $scopeData[$scopeType];
335+
}
336+
}
337+
338+
/**
339+
* Sets data according to scope type and id.
340+
*
341+
* @param string|null $scopeType
342+
* @param string|null $scopeId
343+
* @param array $scopeData
344+
* @return void
345+
*/
346+
private function setDataByScopeId(?string $scopeType, ?string $scopeId, array $scopeData): void
347+
{
348+
if (!isset($this->data[$scopeType][$scopeId]) && isset($scopeData[$scopeType][$scopeId])) {
349+
$this->data[$scopeType][$scopeId] = $scopeData[$scopeType][$scopeId];
350+
}
351+
}
352+
328353
/**
329354
* Cache configuration data.
330355
*

Diff for: dev/tests/integration/testsuite/Magento/Config/App/Config/Type/SystemTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,25 @@ public function testGetValueDefaultScope()
4747
$this->system->get('stores/default/web/test/test_value_1')
4848
);
4949
}
50+
51+
/**
52+
* Tests that configurations added as env variables don't cause the error 'Recursion detected'
53+
* after cleaning the cache.
54+
*
55+
* @return void
56+
*/
57+
public function testEnvGetValueStoreScope()
58+
{
59+
$this->system->clean();
60+
$_ENV['CONFIG__STORES__DEFAULT__ABC__QRS__XYZ'] = 'test_env_value';
61+
62+
$this->assertEquals(
63+
'value1.db.default.test',
64+
$this->system->get('default/web/test/test_value_1')
65+
);
66+
$this->assertEquals(
67+
'test_env_value',
68+
$this->system->get('stores/default/abc/qrs/xyz')
69+
);
70+
}
5071
}

0 commit comments

Comments
 (0)