1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Base |
5
|
|
|
* @author Iurii Makukh <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2015, Iurii Makukh |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl.html GNU/GPLv3 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\base\handlers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module; |
13
|
|
|
use gplcart\core\handlers\install\Base as BaseInstaller; |
14
|
|
|
use gplcart\modules\base\models\Install as ModuleModel; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Contains methods for installing Base profile |
18
|
|
|
*/ |
19
|
|
|
class Install extends BaseInstaller |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Base module installer model |
24
|
|
|
* @var \gplcart\modules\base\models\Installer $installer |
25
|
|
|
*/ |
26
|
|
|
protected $model; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Module class instance |
30
|
|
|
* @var \gplcart\core\Module $module |
31
|
|
|
*/ |
32
|
|
|
protected $module; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Module $module |
36
|
|
|
* @param ModuleModel $model |
37
|
|
|
*/ |
38
|
|
|
public function __construct(Module $module, ModuleModel $model) |
39
|
|
|
{ |
40
|
|
|
parent::__construct(); |
41
|
|
|
|
42
|
|
|
$this->model = $model; |
|
|
|
|
43
|
|
|
$this->module = $module; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Performs initial system installation. Step 0 |
48
|
|
|
* @param array $data |
49
|
|
|
* @param \gplcart\core\Database $db |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function install(array $data, $db) |
53
|
|
|
{ |
54
|
|
|
$this->db = $db; |
55
|
|
|
$this->data = $data; |
56
|
|
|
$this->data['step'] = 0; |
57
|
|
|
|
58
|
|
|
if (GC_CLI) { |
59
|
|
|
return $this->installCli(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->start(); |
63
|
|
|
$result = $this->process(); |
64
|
|
|
|
65
|
|
|
if ($result !== true) { |
66
|
|
|
return $result; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return array( |
70
|
|
|
'message' => '', |
71
|
|
|
'severity' => 'success', |
72
|
|
|
'redirect' => 'install/' . ($this->data['step'] + 1) |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Install in CLI mode |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
protected function installCli() |
81
|
|
|
{ |
82
|
|
|
$result = $this->process(); |
83
|
|
|
|
84
|
|
|
if ($result !== true) { |
85
|
|
|
return $result; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$result1 = $this->installCliStep1(); |
89
|
|
|
|
90
|
|
|
if ($result1['severity'] !== 'success') { |
91
|
|
|
return $result1; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->installCliStep2(); |
95
|
|
|
return $this->installCliStep3(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Process step 1 in CLI mode |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
protected function installCliStep1() |
103
|
|
|
{ |
104
|
|
|
$this->data['step'] = 1; |
105
|
|
|
$this->setCliMessage('Configuring modules...'); |
106
|
|
|
return $this->installModules($this->data, $this->db); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Process step 2 in CLI mode |
111
|
|
|
*/ |
112
|
|
|
protected function installCliStep2() |
113
|
|
|
{ |
114
|
|
|
$title = $this->translation->text('Please select a demo content package (enter a number)'); |
115
|
|
|
$this->data['demo_handler_id'] = $this->cli->menu($this->getDemoOptions(), '', $title); |
116
|
|
|
|
117
|
|
|
if (!empty($this->data['demo_handler_id'])) { |
118
|
|
|
|
119
|
|
|
$this->data['step'] = 2; |
120
|
|
|
$this->setCliMessage('Installing demo content...'); |
121
|
|
|
$result = $this->installDemo($this->data, $this->db); |
122
|
|
|
|
123
|
|
|
if ($result['severity'] !== 'success') { |
124
|
|
|
$this->cli->error($result['message']); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Precess step 3 in CLI mode |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
protected function installCliStep3() |
134
|
|
|
{ |
135
|
|
|
$this->data['step'] = 3; |
136
|
|
|
return $this->installFinish($this->data, $this->db); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Returns an array of demo content options |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
|
|
protected function getDemoOptions() |
144
|
|
|
{ |
145
|
|
|
$options = array( |
146
|
|
|
'' => $this->translation->text('No demo')); |
147
|
|
|
|
148
|
|
|
foreach ($this->model->getDemoHandlers() as $id => $handler) { |
149
|
|
|
$options[$id] = $handler['title']; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $options; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Installs required modules. Step 1 |
157
|
|
|
* @param array $data |
158
|
|
|
* @param \gplcart\core\Database $db |
159
|
|
|
* @return array |
160
|
|
|
*/ |
161
|
|
|
public function installModules(array $data, $db) |
162
|
|
|
{ |
163
|
|
|
$this->db = $db; |
164
|
|
|
$this->data = $data; |
165
|
|
|
|
166
|
|
|
$result = $this->model->installModules(); |
167
|
|
|
|
168
|
|
|
if ($result === true) { |
169
|
|
|
|
170
|
|
|
$this->configureModules(); |
171
|
|
|
|
172
|
|
|
return array( |
173
|
|
|
'message' => '', |
174
|
|
|
'severity' => 'success', |
175
|
|
|
'redirect' => 'install/' . ($this->data['step'] + 1) |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->setContextError($this->data['step'], $result); |
180
|
|
|
|
181
|
|
|
return array( |
182
|
|
|
'redirect' => '', |
183
|
|
|
'severity' => 'danger', |
184
|
|
|
'message' => $result |
185
|
|
|
); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Configure module settings |
190
|
|
|
*/ |
191
|
|
|
protected function configureModules() |
192
|
|
|
{ |
193
|
|
|
$this->configureModuleDevice(); |
194
|
|
|
$this->configureModuleGaReport(); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Configure Device module settings |
199
|
|
|
* @return bool |
200
|
|
|
*/ |
201
|
|
|
protected function configureModuleDevice() |
202
|
|
|
{ |
203
|
|
|
$store_id = $this->getContext('store_id'); |
204
|
|
|
|
205
|
|
|
$settings = array(); |
206
|
|
|
$settings['theme'][$store_id]['mobile'] = 'mobile'; |
207
|
|
|
$settings['theme'][$store_id]['tablet'] = 'mobile'; |
208
|
|
|
|
209
|
|
|
return $this->module->setSettings('device', $settings); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Configure Google Analytics Report module settings |
214
|
|
|
* @return bool |
215
|
|
|
*/ |
216
|
|
|
protected function configureModuleGaReport() |
217
|
|
|
{ |
218
|
|
|
$info = $this->module->getInfo('ga_report'); |
219
|
|
|
|
220
|
|
|
$info['settings']['dashboard'] = array( |
221
|
|
|
'visit_date', |
222
|
|
|
'pageview_date', |
223
|
|
|
'content_statistic', |
224
|
|
|
'top_pages', |
225
|
|
|
'source', |
226
|
|
|
'keyword', |
227
|
|
|
'audience' |
228
|
|
|
); |
229
|
|
|
|
230
|
|
|
return $this->module->setSettings('ga_report', $info['settings']); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Install a demo-content. Step 2 |
235
|
|
|
* @param array $data |
236
|
|
|
* @param \gplcart\core\Database $db |
237
|
|
|
* @return array |
238
|
|
|
*/ |
239
|
|
|
public function installDemo(array $data, $db) |
240
|
|
|
{ |
241
|
|
|
set_time_limit(0); |
242
|
|
|
|
243
|
|
|
$this->db = $db; |
244
|
|
|
$this->data = $data; |
245
|
|
|
|
246
|
|
|
$success_result = array( |
247
|
|
|
'message' => '', |
248
|
|
|
'severity' => 'success', |
249
|
|
|
'redirect' => 'install/' . ($this->data['step'] + 1) |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
if (empty($data['demo_handler_id'])) { |
253
|
|
|
return $success_result; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
$result = $this->model->getDemoModule()->create($this->getContext('store_id'), $data['demo_handler_id']); |
257
|
|
|
|
258
|
|
|
if ($result !== true) { |
259
|
|
|
$this->setContextError($this->data['step'], $result); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
return $success_result; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Performs final tasks. Step 3 |
267
|
|
|
* @param array $data |
268
|
|
|
* @param \gplcart\core\Database $db |
269
|
|
|
* @return array |
270
|
|
|
*/ |
271
|
|
|
public function installFinish(array $data, $db) |
272
|
|
|
{ |
273
|
|
|
$this->db = $db; |
274
|
|
|
$this->data = $data; |
275
|
|
|
|
276
|
|
|
$result = $this->finish(); |
277
|
|
|
$errors = $this->getContextErrors(); |
278
|
|
|
|
279
|
|
|
if (!empty($errors)) { |
280
|
|
|
$result['message'] = $errors; |
281
|
|
|
$result['severity'] = 'warning'; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return $result; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
} |
288
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..