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\handlers\install\Base as BaseInstaller; |
13
|
|
|
use gplcart\modules\base\models\Installer as BaseModuleModel; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Contains methods for installing Base profile |
17
|
|
|
*/ |
18
|
|
|
class Installer extends BaseInstaller |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Base module installer model |
23
|
|
|
* @var \gplcart\modules\base\models\Installer $installer |
24
|
|
|
*/ |
25
|
|
|
protected $base_model; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param BaseModuleModel $base_model |
29
|
|
|
*/ |
30
|
|
|
public function __construct(BaseModuleModel $base_model) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->base_model = $base_model; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Performs initial system installation. Step 0 |
39
|
|
|
* @param array $data |
40
|
|
|
* @param \gplcart\core\Database $db |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function install(array $data, $db) |
44
|
|
|
{ |
45
|
|
|
$this->db = $db; |
46
|
|
|
$this->data = $data; |
47
|
|
|
$this->data['step'] = 0; |
48
|
|
|
|
49
|
|
|
if (GC_CLI) { |
50
|
|
|
return $this->installCli(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->start(); |
54
|
|
|
|
55
|
|
|
$result = $this->process(); |
56
|
|
|
|
57
|
|
|
if ($result !== true) { |
58
|
|
|
return $result; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return array( |
62
|
|
|
'message' => '', |
63
|
|
|
'severity' => 'success', |
64
|
|
|
'redirect' => 'install/' . ($this->data['step'] + 1) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Install in CLI mode |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function installCli() |
73
|
|
|
{ |
74
|
|
|
$this->cli->line($this->language->text('Initial configuration...')); |
75
|
|
|
$result = $this->process(); |
76
|
|
|
|
77
|
|
|
if ($result !== true) { |
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$this->data['step'] = 1; |
82
|
|
|
$this->cli->line($this->language->text('Configuring modules...')); |
83
|
|
|
$result_modules = $this->installModules($this->data, $this->db); |
84
|
|
|
|
85
|
|
|
if ($result_modules['severity'] !== 'success') { |
86
|
|
|
return $result_modules; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$title = $this->language->text('Please select a demo content package (enter a number)'); |
90
|
|
|
$this->data['demo_handler_id'] = $this->cli->menu($this->getDemoOptions(), '', $title); |
91
|
|
|
|
92
|
|
|
if (!empty($this->data['demo_handler_id'])) { |
93
|
|
|
|
94
|
|
|
$this->data['step'] = 2; |
95
|
|
|
$this->cli->line($this->language->text('Installing demo content...')); |
96
|
|
|
$result_demo = $this->installDemo($this->data, $this->db); |
97
|
|
|
|
98
|
|
|
if ($result_demo['severity'] !== 'success') { |
99
|
|
|
$this->cli->error($result_demo['message']); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->data['step'] = 3; |
104
|
|
|
return $this->installFinish($this->data, $this->db); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns an array of demo content options |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
protected function getDemoOptions() |
112
|
|
|
{ |
113
|
|
|
$options = array('' => $this->language->text('No demo')); |
114
|
|
|
|
115
|
|
|
foreach ($this->base_model->getDemoHandlers() as $id => $handler) { |
116
|
|
|
$options[$id] = $handler['title']; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $options; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Installs required modules. Step 1 |
124
|
|
|
* @param array $data |
125
|
|
|
* @param \gplcart\core\Database $db |
126
|
|
|
* @return array |
127
|
|
|
*/ |
128
|
|
|
public function installModules(array $data, $db) |
129
|
|
|
{ |
130
|
|
|
$this->db = $db; |
131
|
|
|
$this->data = $data; |
132
|
|
|
|
133
|
|
|
$result = $this->base_model->installModules(); |
134
|
|
|
|
135
|
|
|
if ($result === true) { |
136
|
|
|
|
137
|
|
|
$this->configureModules(); |
138
|
|
|
|
139
|
|
|
return array( |
140
|
|
|
'message' => '', |
141
|
|
|
'severity' => 'success', |
142
|
|
|
'redirect' => 'install/' . ($this->data['step'] + 1) |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$message = $this->language->text('An error occurred during installing required modules'); |
147
|
|
|
$this->setContextError($this->data['step'], $message); |
148
|
|
|
|
149
|
|
|
return array( |
150
|
|
|
'redirect' => '', |
151
|
|
|
'severity' => 'danger', |
152
|
|
|
'message' => $message |
153
|
|
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Configure module settings |
158
|
|
|
*/ |
159
|
|
|
protected function configureModules() |
160
|
|
|
{ |
161
|
|
|
$this->configureModuleDevice(); |
162
|
|
|
$this->configureModuleGaReport(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Configure Device module settings |
167
|
|
|
* @return bool |
168
|
|
|
*/ |
169
|
|
|
protected function configureModuleDevice() |
170
|
|
|
{ |
171
|
|
|
$settings = array(); |
172
|
|
|
$store_id = $this->getContext('store_id'); |
173
|
|
|
$settings['theme'][$store_id]['mobile'] = 'mobile'; |
174
|
|
|
$settings['theme'][$store_id]['tablet'] = 'mobile'; |
175
|
|
|
|
176
|
|
|
return $this->base_model->setModuleSettings('device', $settings); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Configure Google Analytics Report module settings |
181
|
|
|
* @return bool |
182
|
|
|
*/ |
183
|
|
|
protected function configureModuleGaReport() |
184
|
|
|
{ |
185
|
|
|
$settings = array( |
186
|
|
|
'dashboard' => array('visit_date', 'pageview_date', |
187
|
|
|
'content_statistic', 'top_pages', 'source', 'keyword', 'audience') |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
return $this->base_model->setModuleSettings('ga_report', $settings); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Install a demo-content. Step 2 |
195
|
|
|
* @param array $data |
196
|
|
|
* @param \gplcart\core\Database $db |
197
|
|
|
* @return array |
198
|
|
|
*/ |
199
|
|
|
public function installDemo(array $data, $db) |
200
|
|
|
{ |
201
|
|
|
$this->db = $db; |
202
|
|
|
$this->data = $data; |
203
|
|
|
|
204
|
|
|
$success_result = array( |
205
|
|
|
'message' => '', |
206
|
|
|
'severity' => 'success', |
207
|
|
|
'redirect' => 'install/' . ($this->data['step'] + 1) |
208
|
|
|
); |
209
|
|
|
|
210
|
|
|
if (empty($data['demo_handler_id'])) { |
211
|
|
|
return $success_result; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/* @var $module \gplcart\modules\demo\Demo */ |
215
|
|
|
$module = $this->config->getModuleInstance('demo'); |
216
|
|
|
$result = $module->create($this->getContext('store_id'), $data['demo_handler_id']); |
217
|
|
|
|
218
|
|
|
if ($result !== true) { |
219
|
|
|
$this->setContextError($this->data['step'], $result); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return $success_result; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Performs final tasks. Step 3 |
227
|
|
|
* @param array $data |
228
|
|
|
* @param \gplcart\core\Database $db |
229
|
|
|
* @return array |
230
|
|
|
*/ |
231
|
|
|
public function installFinish(array $data, $db) |
232
|
|
|
{ |
233
|
|
|
$this->db = $db; |
234
|
|
|
$this->data = $data; |
235
|
|
|
|
236
|
|
|
$result = $this->finish(); |
237
|
|
|
$errors = $this->getContextErrors(); |
238
|
|
|
|
239
|
|
|
if (!empty($errors)) { |
240
|
|
|
$result['message'] = $errors; |
241
|
|
|
$result['severity'] = 'warning'; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return $result; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
} |
248
|
|
|
|