1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Base |
5
|
|
|
* @author Iurii Makukh <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\base\controllers; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Controller; |
13
|
|
|
use gplcart\core\models\Install as InstallModel; |
14
|
|
|
use gplcart\modules\base\models\Install as InstallModuleModel; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Handles incoming requests and outputs data related to Base module |
18
|
|
|
*/ |
19
|
|
|
class Install extends Controller |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Install model instance |
24
|
|
|
* @var \gplcart\core\models\Install $install |
25
|
|
|
*/ |
26
|
|
|
protected $install; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Base module model instance |
30
|
|
|
* @var \gplcart\modules\base\models\Install $install_model |
31
|
|
|
*/ |
32
|
|
|
protected $install_model; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* An array of installation data set in the session |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $data_install; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The current installation step |
42
|
|
|
* @var integer |
43
|
|
|
*/ |
44
|
|
|
protected $data_step; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* An array of the current handler |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $data_handler; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Whether to enable the current step |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
protected $data_status = true; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param InstallModel $install |
60
|
|
|
* @param InstallModuleModel $base_model |
61
|
|
|
*/ |
62
|
|
|
public function __construct(InstallModel $install, InstallModuleModel $base_model) |
63
|
|
|
{ |
64
|
|
|
parent::__construct(); |
65
|
|
|
|
66
|
|
|
$this->install = $install; |
67
|
|
|
$this->install_model = $base_model; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Displays step pages |
72
|
|
|
* @param integer $step |
73
|
|
|
*/ |
74
|
|
|
public function stepInstall($step) |
75
|
|
|
{ |
76
|
|
|
$this->data_step = $step; |
77
|
|
|
$this->data_install = $this->session->get('install'); |
78
|
|
|
$this->data_handler = $this->install->getHandler('base'); |
79
|
|
|
|
80
|
|
|
$this->controlAccessStepInstall(); |
81
|
|
|
$this->submitStepInstall(); |
82
|
|
|
|
83
|
|
|
$this->setData('status', $this->data_status); |
84
|
|
|
$this->setData('handler', $this->data_handler); |
85
|
|
|
$this->setData('install', $this->data_install); |
86
|
|
|
$this->setData('demo_handlers', $this->install_model->getDemoHandlers()); |
87
|
|
|
|
88
|
|
|
$this->setJsStepInstall(); |
89
|
|
|
$this->setCssStepInstall(); |
90
|
|
|
|
91
|
|
|
$this->setTitleStepInstall(); |
92
|
|
|
$this->outputStepInstall(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Sets titles on the step page |
97
|
|
|
*/ |
98
|
|
|
protected function setTitleStepInstall() |
99
|
|
|
{ |
100
|
|
|
$this->setTitle($this->data_handler['steps'][$this->data_step]['title']); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Render and output the step page |
105
|
|
|
*/ |
106
|
|
|
protected function outputStepInstall() |
107
|
|
|
{ |
108
|
|
|
$this->output(array('body' => "base|step{$this->data_step}")); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Sets CSS on the step page |
113
|
|
|
*/ |
114
|
|
|
protected function setCssStepInstall() |
115
|
|
|
{ |
116
|
|
|
$this->setCss('system/modules/base/css/common.css'); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Sets Java-Scripts on the step page |
121
|
|
|
*/ |
122
|
|
|
protected function setJsStepInstall() |
123
|
|
|
{ |
124
|
|
|
$this->setJs('system/modules/base/js/common.js'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Handles submits |
129
|
|
|
*/ |
130
|
|
|
protected function submitStepInstall() |
131
|
|
|
{ |
132
|
|
|
if ($this->isPosted('next')) { |
133
|
|
|
|
134
|
|
|
$this->setSubmitted('step'); |
135
|
|
|
|
136
|
|
|
$this->data_install['data']['step'] = $this->data_step; |
137
|
|
|
$this->data_install['data'] = array_merge($this->data_install['data'], $this->getSubmitted()); |
138
|
|
|
$this->session->set('install', $this->data_install); |
139
|
|
|
|
140
|
|
|
$result = $this->install->process($this->data_install['data']); |
141
|
|
|
|
142
|
|
|
if (!empty($result['redirect'])) { |
143
|
|
|
$this->redirect($result['redirect'], $result['message'], $result['severity']); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
$this->data_status = false; |
147
|
|
|
$this->setMessage($result['message'], $result['severity']); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Sets and validates the installation step |
153
|
|
|
*/ |
154
|
|
|
protected function controlAccessStepInstall() |
155
|
|
|
{ |
156
|
|
|
if (!$this->config->isInitialized()) { |
157
|
|
|
$this->redirect('install'); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if ($this->data_step > count($this->data_handler['steps'])) { |
161
|
|
|
$this->redirect('install'); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
if (isset($this->data_install['data']['step']) && ($this->data_step - $this->data_install['data']['step']) != 1) { |
165
|
|
|
$this->data_status = false; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|