Skip to content

Commit acc8722

Browse files
author
Alexander Akimov
authored
Merge pull request #1139 from magento-falcons/MAGETWO-69411
[Falcons] Delivery of bug fixes for Setup and Deployment
2 parents 83e7b3b + 4f7a3ea commit acc8722

File tree

11 files changed

+527
-179
lines changed

11 files changed

+527
-179
lines changed

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

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Config\Model\Config;
77

8-
use Magento\Config\Model\PreparedValueFactory;
8+
use Magento\Config\Model\Config\Importer\SaveProcessor;
99
use Magento\Framework\App\Area;
1010
use Magento\Framework\App\Config;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
@@ -45,13 +45,6 @@ class Importer implements ImporterInterface
4545
*/
4646
private $flagResource;
4747

48-
/**
49-
* Builder which creates value object according to their backend models.
50-
*
51-
* @var PreparedValueFactory
52-
*/
53-
private $valueFactory;
54-
5548
/**
5649
* An array utils.
5750
*
@@ -80,11 +73,18 @@ class Importer implements ImporterInterface
8073
*/
8174
private $scope;
8275

76+
/**
77+
* The configuration saving processor.
78+
*
79+
* @var SaveProcessor
80+
*/
81+
private $saveProcessor;
82+
8383
/**
8484
* @param FlagFactory $flagFactory The flag factory
8585
* @param FlagResource $flagResource The flag resource
8686
* @param ArrayUtils $arrayUtils An array utils
87-
* @param PreparedValueFactory $valueBuilder Builder which creates value object according to their backend models
87+
* @param SaveProcessor $saveProcessor Saves configuration data
8888
* @param ScopeConfigInterface $scopeConfig The application config storage.
8989
* @param State $state The application scope to run
9090
* @param ScopeInterface $scope The application scope
@@ -93,15 +93,15 @@ public function __construct(
9393
FlagFactory $flagFactory,
9494
FlagResource $flagResource,
9595
ArrayUtils $arrayUtils,
96-
PreparedValueFactory $valueBuilder,
96+
SaveProcessor $saveProcessor,
9797
ScopeConfigInterface $scopeConfig,
9898
State $state,
9999
ScopeInterface $scope
100100
) {
101101
$this->flagFactory = $flagFactory;
102102
$this->flagResource = $flagResource;
103103
$this->arrayUtils = $arrayUtils;
104-
$this->valueFactory = $valueBuilder;
104+
$this->saveProcessor = $saveProcessor;
105105
$this->scopeConfig = $scopeConfig;
106106
$this->state = $state;
107107
$this->scope = $scope;
@@ -139,7 +139,7 @@ public function import(array $data)
139139
$this->scope->setCurrentScope(Area::AREA_ADMINHTML);
140140

141141
// Invoke saving of new values.
142-
$this->invokeSaveAll($changedData);
142+
$this->saveProcessor->process($changedData);
143143
});
144144

145145
$flag->setFlagData($data);
@@ -161,60 +161,4 @@ public function getWarningMessages(array $data)
161161
{
162162
return [];
163163
}
164-
165-
/**
166-
* Emulates saving of data array.
167-
*
168-
* @param array $data The data to be saved
169-
* @return void
170-
*/
171-
private function invokeSaveAll(array $data)
172-
{
173-
foreach ($data as $scope => $scopeData) {
174-
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
175-
$this->invokeSave($scopeData, $scope);
176-
} else {
177-
foreach ($scopeData as $scopeCode => $scopeCodeData) {
178-
$this->invokeSave($scopeCodeData, $scope, $scopeCode);
179-
}
180-
}
181-
}
182-
}
183-
184-
/**
185-
* Emulates saving of configuration.
186-
* This is a temporary solution until Magento reworks
187-
* backend models for configurations.
188-
*
189-
* Example of $scopeData argument:
190-
*
191-
* ```php
192-
* [
193-
* 'web' => [
194-
* 'unsecure' => [
195-
* 'base_url' => "http://magento2.local/"
196-
* ]
197-
* ]
198-
* ];
199-
* ```
200-
*
201-
* @param array $scopeData The data for specific scope
202-
* @param string $scope The configuration scope (default, website, or store)
203-
* @param string $scopeCode The scope code
204-
* @return void
205-
*/
206-
private function invokeSave(array $scopeData, $scope, $scopeCode = null)
207-
{
208-
$scopeData = array_keys($this->arrayUtils->flatten($scopeData));
209-
210-
foreach ($scopeData as $path) {
211-
$value = $this->scopeConfig->getValue($path, $scope, $scopeCode);
212-
$backendModel = $this->valueFactory->create($path, $value, $scope, $scopeCode);
213-
214-
if ($backendModel instanceof Config\Value) {
215-
$backendModel->beforeSave();
216-
$backendModel->afterSave();
217-
}
218-
}
219-
}
220164
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Config\Model\Config\Importer;
7+
8+
use Magento\Config\Model\Config\Backend\Currency\AbstractCurrency;
9+
use Magento\Config\Model\PreparedValueFactory;
10+
use Magento\Directory\Model\Currency;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\Config\Value;
13+
use Magento\Framework\Stdlib\ArrayUtils;
14+
15+
/**
16+
* Saves configuration from importer
17+
*/
18+
class SaveProcessor
19+
{
20+
/**
21+
* Builder which creates value object according to their backend models.
22+
*
23+
* @var PreparedValueFactory
24+
*/
25+
private $valueFactory;
26+
27+
/**
28+
* An array utils.
29+
*
30+
* @var ArrayUtils
31+
*/
32+
private $arrayUtils;
33+
34+
/**
35+
* The application config storage.
36+
*
37+
* @var ScopeConfigInterface
38+
*/
39+
private $scopeConfig;
40+
41+
/**
42+
* @param ArrayUtils $arrayUtils An array utils
43+
* @param PreparedValueFactory $valueBuilder Builder which creates value object according to their backend models
44+
* @param ScopeConfigInterface $scopeConfig The application config storage.
45+
*/
46+
public function __construct(
47+
ArrayUtils $arrayUtils,
48+
PreparedValueFactory $valueBuilder,
49+
ScopeConfigInterface $scopeConfig
50+
) {
51+
$this->arrayUtils = $arrayUtils;
52+
$this->valueFactory = $valueBuilder;
53+
$this->scopeConfig = $scopeConfig;
54+
}
55+
56+
/**
57+
* Emulates saving of data array.
58+
*
59+
* @param array $data The data to be saved
60+
* @return void
61+
*/
62+
public function process(array $data)
63+
{
64+
foreach ($data as $scope => $scopeData) {
65+
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
66+
$this->invokeSave($scopeData, $scope);
67+
} else {
68+
foreach ($scopeData as $scopeCode => $scopeCodeData) {
69+
$this->invokeSave($scopeCodeData, $scope, $scopeCode);
70+
}
71+
}
72+
}
73+
}
74+
75+
/**
76+
* Emulates saving of configuration.
77+
* This is a temporary solution until Magento reworks
78+
* backend models for configurations.
79+
*
80+
* Example of $scopeData argument:
81+
*
82+
* ```php
83+
* [
84+
* 'web' => [
85+
* 'unsecure' => [
86+
* 'base_url' => "http://magento2.local/"
87+
* ]
88+
* ]
89+
* ];
90+
* ```
91+
*
92+
* @param array $scopeData The data for specific scope
93+
* @param string $scope The configuration scope (default, website, or store)
94+
* @param string $scopeCode The scope code
95+
* @return void
96+
*/
97+
private function invokeSave(array $scopeData, $scope, $scopeCode = null)
98+
{
99+
$scopeData = array_keys($this->arrayUtils->flatten($scopeData));
100+
101+
foreach ($scopeData as $path) {
102+
$value = $this->scopeConfig->getValue($path, $scope, $scopeCode);
103+
$backendModel = $this->valueFactory->create($path, $value, $scope, $scopeCode);
104+
105+
if ($backendModel instanceof Value) {
106+
$this->setAdditionalData($backendModel);
107+
$backendModel->beforeSave();
108+
$backendModel->afterSave();
109+
}
110+
}
111+
}
112+
113+
/**
114+
* Adds additional data to backendModel if needed.
115+
*
116+
* Additional data, such as groups is coming within form request.
117+
* There is no possibility to retrieve this data separately, so
118+
* this emulation should be performed to preserve backward compatibility.
119+
*
120+
* @param Value $backendModel Instance of Value
121+
* @return void
122+
*/
123+
private function setAdditionalData(Value $backendModel)
124+
{
125+
// sets allowed currencies before save base or default currency value
126+
if ($backendModel instanceof AbstractCurrency) {
127+
$allowedCurrencies = $this->scopeConfig->getValue(
128+
Currency::XML_PATH_CURRENCY_ALLOW,
129+
$backendModel->getScope(),
130+
$backendModel->getScopeId()
131+
);
132+
$backendModel->addData([
133+
'groups' => [
134+
'options' => [
135+
'fields' => [
136+
'allow' => ['value' => explode(',', $allowedCurrencies)]
137+
]
138+
]
139+
]
140+
]);
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)