6
6
7
7
namespace Magento \Setup \Controller ;
8
8
9
- use Magento \Setup \ Model \ AdminAccount ;
9
+ use Magento \Framework \ App \ DeploymentConfig ;
10
10
use Magento \Framework \Config \ConfigOptionsListConstants as SetupConfigOptionsList ;
11
- use Magento \Backend \ Setup \ ConfigOptionsList as BackendConfigOptionsList ;
11
+ use Magento \SampleData ;
12
12
use Magento \Setup \Model \Installer ;
13
13
use Magento \Setup \Model \Installer \ProgressFactory ;
14
14
use Magento \Setup \Model \InstallerFactory ;
15
- use Magento \Setup \Model \StoreConfigurationDataMapper as UserConfig ;
15
+ use Magento \Setup \Model \RequestDataConverter ;
16
16
use Magento \Setup \Model \WebLogger ;
17
17
use Zend \Json \Json ;
18
18
use Zend \Mvc \Controller \AbstractActionController ;
19
19
use Zend \View \Model \JsonModel ;
20
20
use Zend \View \Model \ViewModel ;
21
- use Magento \Setup \Console \Command \InstallCommand ;
22
- use Magento \SampleData ;
23
- use Magento \Framework \App \DeploymentConfig ;
24
21
25
22
/**
26
23
* Install controller
@@ -54,6 +51,11 @@ class Install extends AbstractActionController
54
51
*/
55
52
private $ deploymentConfig ;
56
53
54
+ /**
55
+ * @var RequestDataConverter
56
+ */
57
+ private $ requestDataConverter ;
58
+
57
59
/**
58
60
* Default Constructor
59
61
*
@@ -62,19 +64,22 @@ class Install extends AbstractActionController
62
64
* @param ProgressFactory $progressFactory
63
65
* @param \Magento\Framework\Setup\SampleData\State $sampleDataState
64
66
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
67
+ * @param RequestDataConverter $requestDataConverter
65
68
*/
66
69
public function __construct (
67
70
WebLogger $ logger ,
68
71
InstallerFactory $ installerFactory ,
69
72
ProgressFactory $ progressFactory ,
70
73
\Magento \Framework \Setup \SampleData \State $ sampleDataState ,
71
- DeploymentConfig $ deploymentConfig
74
+ DeploymentConfig $ deploymentConfig ,
75
+ RequestDataConverter $ requestDataConverter
72
76
) {
73
77
$ this ->log = $ logger ;
74
78
$ this ->installer = $ installerFactory ->create ($ logger );
75
79
$ this ->progressFactory = $ progressFactory ;
76
80
$ this ->sampleDataState = $ sampleDataState ;
77
81
$ this ->deploymentConfig = $ deploymentConfig ;
82
+ $ this ->requestDataConverter = $ requestDataConverter ;
78
83
}
79
84
80
85
/**
@@ -91,19 +96,16 @@ public function indexAction()
91
96
* Index Action
92
97
*
93
98
* @return JsonModel
94
- * @SuppressWarnings(PHPMD.NPathComplexity)
95
99
*/
96
100
public function startAction ()
97
101
{
98
102
$ this ->log ->clear ();
99
103
$ json = new JsonModel ;
100
104
try {
101
105
$ this ->checkForPriorInstall ();
102
- $ data = array_merge (
103
- $ this ->importDeploymentConfigForm (),
104
- $ this ->importUserConfigForm (),
105
- $ this ->importAdminUserForm ()
106
- );
106
+ $ content = $ this ->getRequest ()->getContent ();
107
+ $ source = $ content ? $ source = Json::decode ($ content , Json::TYPE_ARRAY ) : [];
108
+ $ data = $ this ->requestDataConverter ->convert ($ source );
107
109
$ this ->installer ->install ($ data );
108
110
$ json ->setVariable (
109
111
'key ' ,
@@ -168,102 +170,4 @@ private function checkForPriorInstall()
168
170
throw new \Magento \Setup \Exception ('Magento application is already installed. ' );
169
171
}
170
172
}
171
-
172
- /**
173
- * Maps data from request to format of deployment config model
174
- *
175
- * @return array
176
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
177
- * @SuppressWarnings(PHPMD.NPathComplexity)
178
- */
179
- private function importDeploymentConfigForm ()
180
- {
181
- $ content = $ this ->getRequest ()->getContent ();
182
- $ source = [];
183
- if ($ content ) {
184
- $ source = Json::decode ($ content , Json::TYPE_ARRAY );
185
- }
186
-
187
- $ result = [];
188
- $ result [SetupConfigOptionsList::INPUT_KEY_DB_HOST ] = isset ($ source ['db ' ]['host ' ]) ? $ source ['db ' ]['host ' ] : '' ;
189
- $ result [SetupConfigOptionsList::INPUT_KEY_DB_NAME ] = isset ($ source ['db ' ]['name ' ]) ? $ source ['db ' ]['name ' ] : '' ;
190
- $ result [SetupConfigOptionsList::INPUT_KEY_DB_USER ] = isset ($ source ['db ' ]['user ' ]) ? $ source ['db ' ]['user ' ] :'' ;
191
- $ result [SetupConfigOptionsList::INPUT_KEY_DB_PASSWORD ] =
192
- isset ($ source ['db ' ]['password ' ]) ? $ source ['db ' ]['password ' ] : '' ;
193
- $ result [SetupConfigOptionsList::INPUT_KEY_DB_PREFIX ] =
194
- isset ($ source ['db ' ]['tablePrefix ' ]) ? $ source ['db ' ]['tablePrefix ' ] : '' ;
195
- $ result [BackendConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME ] = isset ($ source ['config ' ]['address ' ]['admin ' ])
196
- ? $ source ['config ' ]['address ' ]['admin ' ] : '' ;
197
- $ result [SetupConfigOptionsList::INPUT_KEY_ENCRYPTION_KEY ] = isset ($ source ['config ' ]['encrypt ' ]['key ' ])
198
- ? $ source ['config ' ]['encrypt ' ]['key ' ] : null ;
199
- $ result [SetupConfigOptionsList::INPUT_KEY_SESSION_SAVE ] = isset ($ source ['config ' ]['sessionSave ' ]['type ' ])
200
- ? $ source ['config ' ]['sessionSave ' ]['type ' ] : SetupConfigOptionsList::SESSION_SAVE_FILES ;
201
- $ result [Installer::ENABLE_MODULES ] = isset ($ source ['store ' ]['selectedModules ' ])
202
- ? implode (', ' , $ source ['store ' ]['selectedModules ' ]) : '' ;
203
- $ result [Installer::DISABLE_MODULES ] = isset ($ source ['store ' ]['allModules ' ])
204
- ? implode (', ' , array_diff ($ source ['store ' ]['allModules ' ], $ source ['store ' ]['selectedModules ' ])) : '' ;
205
- return $ result ;
206
- }
207
-
208
- /**
209
- * Maps data from request to format of user config model
210
- *
211
- * @return array
212
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
213
- * @SuppressWarnings(PHPMD.NPathComplexity)
214
- */
215
- private function importUserConfigForm ()
216
- {
217
- $ result = [];
218
- $ source = [];
219
- $ content = $ this ->getRequest ()->getContent ();
220
- if ($ content ) {
221
- $ source = Json::decode ($ content , Json::TYPE_ARRAY );
222
- }
223
- if (isset ($ source ['config ' ]['address ' ]['base_url ' ]) && !empty ($ source ['config ' ]['address ' ]['base_url ' ])) {
224
- $ result [UserConfig::KEY_BASE_URL ] = $ source ['config ' ]['address ' ]['base_url ' ];
225
- }
226
- $ result [UserConfig::KEY_USE_SEF_URL ] = isset ($ source ['config ' ]['rewrites ' ]['allowed ' ])
227
- ? $ source ['config ' ]['rewrites ' ]['allowed ' ] : '' ;
228
- $ result [UserConfig::KEY_IS_SECURE ] = isset ($ source ['config ' ]['https ' ]['front ' ])
229
- ? $ source ['config ' ]['https ' ]['front ' ] : '' ;
230
- $ result [UserConfig::KEY_IS_SECURE_ADMIN ] = isset ($ source ['config ' ]['https ' ]['admin ' ])
231
- ? $ source ['config ' ]['https ' ]['admin ' ] : '' ;
232
- $ result [UserConfig::KEY_BASE_URL_SECURE ] = (isset ($ source ['config ' ]['https ' ]['front ' ])
233
- || isset ($ source ['config ' ]['https ' ]['admin ' ]))
234
- ? $ source ['config ' ]['https ' ]['text ' ] : '' ;
235
- $ result [UserConfig::KEY_LANGUAGE ] = isset ($ source ['store ' ]['language ' ])
236
- ? $ source ['store ' ]['language ' ] : '' ;
237
- $ result [UserConfig::KEY_TIMEZONE ] = isset ($ source ['store ' ]['timezone ' ])
238
- ? $ source ['store ' ]['timezone ' ] : '' ;
239
- $ result [UserConfig::KEY_CURRENCY ] = isset ($ source ['store ' ]['currency ' ])
240
- ? $ source ['store ' ]['currency ' ] : '' ;
241
- $ result [InstallCommand::INPUT_KEY_USE_SAMPLE_DATA ] = isset ($ source ['store ' ]['useSampleData ' ])
242
- ? $ source ['store ' ]['useSampleData ' ] : '' ;
243
- $ result [InstallCommand::INPUT_KEY_CLEANUP_DB ] = isset ($ source ['store ' ]['cleanUpDatabase ' ])
244
- ? $ source ['store ' ]['cleanUpDatabase ' ] : '' ;
245
- return $ result ;
246
- }
247
-
248
- /**
249
- * Maps data from request to format of admin account model
250
- *
251
- * @return array
252
- * @SuppressWarnings(PHPMD.NPathComplexity)
253
- */
254
- private function importAdminUserForm ()
255
- {
256
- $ result = [];
257
- $ source = [];
258
- $ content = $ this ->getRequest ()->getContent ();
259
- if ($ content ) {
260
- $ source = Json::decode ($ content , Json::TYPE_ARRAY );
261
- }
262
- $ result [AdminAccount::KEY_USER ] = isset ($ source ['admin ' ]['username ' ]) ? $ source ['admin ' ]['username ' ] : '' ;
263
- $ result [AdminAccount::KEY_PASSWORD ] = isset ($ source ['admin ' ]['password ' ]) ? $ source ['admin ' ]['password ' ] : '' ;
264
- $ result [AdminAccount::KEY_EMAIL ] = isset ($ source ['admin ' ]['email ' ]) ? $ source ['admin ' ]['email ' ] : '' ;
265
- $ result [AdminAccount::KEY_FIRST_NAME ] = $ result [AdminAccount::KEY_USER ];
266
- $ result [AdminAccount::KEY_LAST_NAME ] = $ result [AdminAccount::KEY_USER ];
267
- return $ result ;
268
- }
269
173
}
0 commit comments