Skip to content

Commit 0e0ee91

Browse files
MC-32634: Default store and view are disappearing after changing Default website code and using exported config.php to install magento
1 parent 0423eae commit 0e0ee91

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

app/code/Magento/Store/Model/Config/Importer/DataDifferenceCalculator.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ class DataDifferenceCalculator
2020
*/
2121
private $runtimeConfigSource;
2222

23+
/**
24+
* Scopes identifier
25+
*
26+
* @var string[]
27+
*/
28+
private $identifiers = [
29+
'websites' => 'website_id',
30+
'groups' => 'group_id',
31+
'stores' => 'store_id',
32+
];
33+
2334
/**
2435
* @param ConfigSourceInterface $runtimeConfigSource The config source to retrieve current config
2536
*/
@@ -28,6 +39,31 @@ public function __construct(ConfigSourceInterface $runtimeConfigSource)
2839
$this->runtimeConfigSource = $runtimeConfigSource;
2940
}
3041

42+
/**
43+
* Update data by checking ID
44+
*
45+
* @param string $scope
46+
* @param array $data
47+
* @param array $runtimeScopeData
48+
* @return array
49+
*/
50+
private function updateDataById(string $scope, array $data, array $runtimeScopeData): array
51+
{
52+
$diffData = array_diff_key($data, $runtimeScopeData);
53+
foreach ($diffData as $code => $datum) {
54+
foreach ($runtimeScopeData as $runTimeScopeCode => $runtimeScopeDatum) {
55+
if (isset($datum[$this->identifiers[$scope]])
56+
&& $datum[$this->identifiers[$scope]] === $runtimeScopeDatum[$this->identifiers[$scope]]
57+
) {
58+
$data[$runTimeScopeCode] = $data[$code];
59+
unset($data[$code]);
60+
}
61+
}
62+
}
63+
64+
return $data;
65+
}
66+
3167
/**
3268
* Calculates items to delete.
3369
*
@@ -41,6 +77,7 @@ public function getItemsToDelete($scope, array $data)
4177
$runtimeScopeData = $this->changeDataKeyToCode(
4278
$this->getRuntimeData($scope)
4379
);
80+
$data = $this->updateDataById($scope, $data, $runtimeScopeData);
4481

4582
return array_diff_key($runtimeScopeData, $data);
4683
}
@@ -58,6 +95,7 @@ public function getItemsToCreate($scope, array $data)
5895
$runtimeScopeData = $this->changeDataKeyToCode(
5996
$this->getRuntimeData($scope)
6097
);
98+
$data = $this->updateDataById($scope, $data, $runtimeScopeData);
6199

62100
return array_diff_key($data, $runtimeScopeData);
63101
}
@@ -77,7 +115,7 @@ public function getItemsToUpdate($scope, array $data)
77115
$runtimeScopeData = $this->changeDataKeyToCode(
78116
$this->getRuntimeData($scope)
79117
);
80-
118+
$data = $this->updateDataById($scope, $data, $runtimeScopeData);
81119
foreach ($runtimeScopeData as $entityCode => $entityData) {
82120
if (isset($data[$entityCode]) && array_diff_assoc($entityData, $data[$entityCode])) {
83121
$itemsToUpdate[$entityCode] = array_replace($entityData, $data[$entityCode]);

dev/tests/integration/testsuite/Magento/Deploy/_files/scopes/config_with_changed_stores.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
'default_group_id' => '0',
1515
'is_default' => '0',
1616
],
17-
'base' => [
17+
'base_code_changed' => [
1818
'website_id' => '1',
19-
'code' => 'base',
19+
'code' => 'base_code_changed',
2020
'name' => 'Main Website',
2121
'sort_order' => '0',
2222
'default_group_id' => '1',

0 commit comments

Comments
 (0)