forked from PrestaShop/PrestaShop
/
process.php
357 lines (308 loc) · 11.4 KB
/
process.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShopBundle\Install\Database;
use PrestaShopBundle\Install\Install;
class InstallControllerConsoleProcess extends InstallControllerConsole implements HttpConfigureInterface
{
public $process_steps = array();
public $previous_button = false;
public function init()
{
$this->model_install = new Install();
$this->model_install->setTranslator($this->translator);
$this->model_database = new Database();
$this->model_database->setTranslator($this->translator);
}
/**
* @see HttpConfigureInterface::processNextStep()
*/
public function processNextStep()
{
}
public function display()
{
}
/**
* @see HttpConfigureInterface::validate()
*/
public function validate()
{
return false;
}
public function initializeContext()
{
global $smarty;
// Clean all cache values
Cache::clean('*');
Context::getContext()->shop = new Shop(1);
Shop::setContext(Shop::CONTEXT_SHOP, 1);
Configuration::loadConfiguration();
if (!isset(Context::getContext()->language) || !Validate::isLoadedObject(Context::getContext()->language)) {
if ($id_lang = (int)Configuration::get('PS_LANG_DEFAULT')) {
Context::getContext()->language = new Language($id_lang);
}
}
if (!isset(Context::getContext()->country) || !Validate::isLoadedObject(Context::getContext()->country)) {
if ($id_country = (int)Configuration::get('PS_COUNTRY_DEFAULT')) {
Context::getContext()->country = new Country((int)$id_country);
}
}
if (!isset(Context::getContext()->currency) || !Validate::isLoadedObject(Context::getContext()->currency)) {
if ($id_currency = (int)Configuration::get('PS_CURRENCY_DEFAULT')) {
Context::getContext()->currency = new Currency((int)$id_currency);
}
}
Context::getContext()->cart = new Cart();
Context::getContext()->employee = new Employee(1);
if (!defined('_PS_SMARTY_FAST_LOAD_')) {
define('_PS_SMARTY_FAST_LOAD_', true);
}
require_once _PS_ROOT_DIR_.'/config/smarty.config.inc.php';
Context::getContext()->smarty = $smarty;
}
public function process()
{
/* avoid exceptions on re-installation */
$this->clearConfigXML() && $this->clearConfigThemes();
$steps = explode(',', $this->datas->step);
if (in_array('all', $steps)) {
$steps = array('database','fixtures','theme','modules','addons_modules');
}
if (in_array('database', $steps)) {
if (!$this->processGenerateSettingsFile()) {
$this->printErrors();
}
if ($this->datas->database_create) {
$this->model_database->createDatabase($this->datas->database_server, $this->datas->database_name, $this->datas->database_login, $this->datas->database_password);
}
if (!$this->model_database->testDatabaseSettings($this->datas->database_server, $this->datas->database_name, $this->datas->database_login, $this->datas->database_password, $this->datas->database_prefix, $this->datas->database_engine, $this->datas->database_clear)) {
$this->printErrors();
}
if (!$this->processInstallDatabase()) {
$this->printErrors();
}
// Deferred Kernel Init
$this->initKernel();
if (!$this->processInstallDefaultData()) {
$this->printErrors();
}
if (!$this->processPopulateDatabase()) {
$this->printErrors();
}
if (!$this->processConfigureShop()) {
$this->printErrors();
}
}
if (in_array('modules', $steps)) {
if (!$this->processInstallModules()) {
$this->printErrors();
}
}
if (in_array('addons_modules', $steps)) {
if (!$this->processInstallAddonsModules()) {
$this->printErrors();
}
}
if (in_array('theme', $steps)) {
if (!$this->processInstallTheme()) {
$this->printErrors();
}
}
if (in_array('fixtures', $steps)) {
if (!$this->processInstallFixtures()) {
$this->printErrors();
}
}
// Update fixtures lang
foreach (Language::getLanguages() as $lang) {
Language::updateMultilangTable($lang['iso_code']);
}
if ($this->datas->newsletter) {
$params = http_build_query(array(
'email' => $this->datas->admin_email,
'method' => 'addMemberToNewsletter',
'language' => $this->datas->lang,
'visitorType' => 1,
'source' => 'installer',
));
Tools::file_get_contents('http://www.prestashop.com/ajax/controller.php?'.$params);
}
}
/**
* PROCESS : generateSettingsFile
*/
public function processGenerateSettingsFile()
{
return $this->model_install->generateSettingsFile(
$this->datas->database_server,
$this->datas->database_login,
$this->datas->database_password,
$this->datas->database_name,
$this->datas->database_prefix,
$this->datas->database_engine
);
}
/**
* PROCESS : installDatabase
* Create database structure
*/
public function processInstallDatabase()
{
return $this->model_install->installDatabase($this->datas->database_clear);
}
/**
* PROCESS : installDefaultData
* Create default shop and languages
*/
public function processInstallDefaultData()
{
$this->initializeContext();
if (!$res = $this->model_install->installDefaultData($this->datas->shop_name, $this->datas->shop_country, (int)$this->datas->all_languages, true)) {
return false;
}
if ($this->datas->base_uri != '/') {
$shop_url = new ShopUrl(1);
$shop_url->physical_uri = $this->datas->base_uri;
$shop_url->save();
}
return $res;
}
/**
* PROCESS : populateDatabase
* Populate database with default data
*/
public function processPopulateDatabase()
{
$this->initializeContext();
$this->model_install->xml_loader_ids = $this->datas->xml_loader_ids;
$result = $this->model_install->populateDatabase();
$this->datas->xml_loader_ids = $this->model_install->xml_loader_ids;
Configuration::updateValue('PS_INSTALL_XML_LOADERS_ID', json_encode($this->datas->xml_loader_ids));
return $result;
}
/**
* PROCESS : configureShop
* Set default shop configuration
*/
public function processConfigureShop()
{
$this->initializeContext();
return $this->model_install->configureShop(array(
'shop_name' => $this->datas->shop_name,
'shop_activity' => $this->datas->shop_activity,
'shop_country' => $this->datas->shop_country,
'shop_timezone' => $this->datas->timezone,
'use_smtp' => false,
'admin_firstname' => $this->datas->admin_firstname,
'admin_lastname' => $this->datas->admin_lastname,
'admin_password' => $this->datas->admin_password,
'admin_email' => $this->datas->admin_email,
'configuration_agrement' => true,
'send_informations' => true,
'enable_ssl' => $this->datas->enable_ssl,
));
}
/**
* PROCESS : installModules
* Install all modules in ~/modules/ directory
*/
public function processInstallModules()
{
$this->initializeContext();
return $this->model_install->installModules();
}
/**
* PROCESS : installFixtures
* Install fixtures (E.g. demo products)
*/
public function processInstallFixtures()
{
$this->initializeContext();
if ((!$this->datas->xml_loader_ids || !is_array($this->datas->xml_loader_ids)) && ($xml_ids = json_decode(Configuration::get('PS_INSTALL_XML_LOADERS_ID'), true))) {
$this->datas->xml_loader_ids = $xml_ids;
}
$this->model_install->xml_loader_ids = $this->datas->xml_loader_ids;
$result = $this->model_install->installFixtures(null, array('shop_activity' => $this->datas->shop_activity, 'shop_country' => $this->datas->shop_country));
$this->datas->xml_loader_ids = $this->model_install->xml_loader_ids;
return $result;
}
/**
* PROCESS : installModulesAddons
* Install modules from addons
*/
public function processInstallAddonsModules()
{
return $this->model_install->installModulesAddons();
}
/**
* PROCESS : installTheme
* Install theme
*/
public function processInstallTheme()
{
$this->initializeContext();
return $this->model_install->installTheme($this->datas->theme);
}
private function clearConfigXML()
{
$configXMLPath = _PS_ROOT_DIR_.'/config/xml/';
$cacheFiles = scandir($configXMLPath, SCANDIR_SORT_NONE);
$excludes = ['.htaccess', 'index.php'];
foreach($cacheFiles as $file) {
$filepath = $configXMLPath.$file;
if (is_file($filepath) && !in_array($file, $excludes)) {
unlink($filepath);
}
}
}
private function clearConfigThemes()
{
$themesPath = _PS_ROOT_DIR_.'/config/themes/';
$cacheFiles = scandir($themesPath, SCANDIR_SORT_NONE);
foreach($cacheFiles as $file) {
$file = $themesPath.$file;
if (is_file($file)) {
unlink($file);
}
}
}
/**
* Deferred initialization of Symfony Kernel
*/
private function initKernel()
{
require_once _PS_CORE_DIR_.'/config/bootstrap.php';
if (defined('_PS_IN_TEST_') && _PS_IN_TEST_) {
$env = 'test';
} else {
$env = _PS_MODE_DEV_ ? 'dev' : 'prod';
}
global $kernel;
$kernel = new AppKernel($env, _PS_MODE_DEV_);
$kernel->loadClassCache();
$kernel->boot();
}
}