Skip to content

Commit bbf59f3

Browse files
Merge MAGETWO-81469 into 2.3-bugfixes-161018
2 parents 3eda046 + b56aa55 commit bbf59f3

File tree

3 files changed

+27
-195
lines changed

3 files changed

+27
-195
lines changed

app/code/Magento/Config/App/Config/Type/System.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function __construct(
101101
}
102102

103103
/**
104+
* Get config value by path.
105+
*
104106
* System configuration is separated by scopes (default, websites, stores). Configuration of a scope is inherited
105107
* from its parent scope (store inherits website).
106108
*
@@ -121,7 +123,7 @@ public function __construct(
121123
public function get($path = '')
122124
{
123125
if ($path === '') {
124-
$this->data = array_replace_recursive($this->loadAllData(), $this->data);
126+
$this->data = array_replace_recursive($this->data, $this->loadAllData());
125127

126128
return $this->data;
127129
}
@@ -142,7 +144,7 @@ private function getWithParts($path)
142144
if (count($pathParts) === 1 && $pathParts[0] !== ScopeInterface::SCOPE_DEFAULT) {
143145
if (!isset($this->data[$pathParts[0]])) {
144146
$data = $this->readData();
145-
$this->data = array_replace_recursive($data, $this->data);
147+
$this->data = array_replace_recursive($this->data, $this->postProcessor->process($data));
146148
}
147149

148150
return $this->data[$pathParts[0]];
@@ -152,7 +154,12 @@ private function getWithParts($path)
152154

153155
if ($scopeType === ScopeInterface::SCOPE_DEFAULT) {
154156
if (!isset($this->data[$scopeType])) {
155-
$this->data = array_replace_recursive($this->loadDefaultScopeData($scopeType), $this->data);
157+
$this->data = array_replace_recursive(
158+
$this->data,
159+
$scopeData = $this->loadDefaultScopeData($scopeType)
160+
);
161+
$scopeData = $this->postProcessor->process($scopeData);
162+
$this->data = array_replace_recursive($this->data, $scopeData);
156163
}
157164

158165
return $this->getDataByPathParts($this->data[$scopeType], $pathParts);
@@ -162,10 +169,9 @@ private function getWithParts($path)
162169

163170
if (!isset($this->data[$scopeType][$scopeId])) {
164171
$scopeData = $this->loadScopeData($scopeType, $scopeId);
165-
166-
if (!isset($this->data[$scopeType][$scopeId])) {
167-
$this->data = array_replace_recursive($scopeData, $this->data);
168-
}
172+
$this->data = array_replace_recursive($this->data, $scopeData);
173+
$scopeData = $this->postProcessor->process($scopeData);
174+
$this->data = array_replace_recursive($this->data, $scopeData);
169175
}
170176

171177
return isset($this->data[$scopeType][$scopeId])
@@ -186,9 +192,10 @@ private function loadAllData()
186192
$data = $this->readData();
187193
} else {
188194
$data = $this->serializer->unserialize($cachedData);
195+
$this->data = $data;
189196
}
190197

191-
return $data;
198+
return $this->postProcessor->process($data);
192199
}
193200

194201
/**
@@ -243,6 +250,7 @@ private function loadScopeData($scopeType, $scopeId)
243250

244251
/**
245252
* Cache configuration data.
253+
*
246254
* Caches data per scope to avoid reading data for all scopes on every request
247255
*
248256
* @param array $data
@@ -308,9 +316,6 @@ private function getDataByPathParts($data, $pathParts)
308316
private function readData(): array
309317
{
310318
$this->data = $this->reader->read();
311-
$this->data = $this->postProcessor->process(
312-
$this->data
313-
);
314319

315320
return $this->data;
316321
}

app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php

Lines changed: 0 additions & 181 deletions
This file was deleted.

lib/internal/Magento/Framework/App/Config/MetadataConfigTypeProcessor.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
1212
use Magento\Framework\App\ObjectManager;
1313

14+
/**
15+
* Post-process config values using their backend models.
16+
*/
1417
class MetadataConfigTypeProcessor implements PostProcessorInterface
1518
{
1619
/**
@@ -114,9 +117,14 @@ private function processScopeData(
114117
$scopeCode = null
115118
) {
116119
foreach ($this->_metadata as $path => $metadata) {
117-
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode);
118-
if (!empty($this->configSource->get($configPath))) {
119-
continue;
120+
try {
121+
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode);
122+
if (!empty($this->configSource->get($configPath))) {
123+
continue;
124+
}
125+
} catch (\Throwable $exception) {
126+
//Failed to load scopes or config source, perhaps config data received is outdated.
127+
return $data;
120128
}
121129
/** @var \Magento\Framework\App\Config\Data\ProcessorInterface $processor */
122130
$processor = $this->_processorFactory->get($metadata['backendModel']);

0 commit comments

Comments
 (0)