|
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; |
|
11
|
|
|
|
|
12
|
|
|
use gplcart\core\Container, |
|
13
|
|
|
gplcart\core\Config; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Main class for Base module |
|
17
|
|
|
*/ |
|
18
|
|
|
class Base |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Config class instance |
|
23
|
|
|
* @var \gplcart\core\Config $config |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $config; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param Config $config |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(Config $config) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->config = $config; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Implements hook "route.list" |
|
37
|
|
|
* @param array $routes |
|
38
|
|
|
*/ |
|
39
|
|
|
public function hookRouteList(array &$routes) |
|
40
|
|
|
{ |
|
41
|
|
|
$routes['install/(\d+)'] = array( |
|
42
|
|
|
'handlers' => array( |
|
43
|
|
|
'controller' => array('gplcart\\modules\\base\\controllers\\Install', 'stepInstall') |
|
44
|
|
|
) |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Implements hook "install.handlers" |
|
50
|
|
|
* @param array $handlers |
|
51
|
|
|
*/ |
|
52
|
|
|
public function hookInstallHandlers(array &$handlers) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->setInstallHandlers($handlers); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Implements hook "install.before" |
|
59
|
|
|
* @param array $data |
|
60
|
|
|
* @param mixed $result |
|
61
|
|
|
*/ |
|
62
|
|
|
public function hookInstallBefore(array $data, &$result) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->checkRequiredModules($data, $result); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Implements hook "template.render" |
|
69
|
|
|
* @param array $templates |
|
70
|
|
|
*/ |
|
71
|
|
|
public function hookTemplateRender(array &$templates) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->replaceTemplates($templates); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Adds installation handlers |
|
78
|
|
|
* @param array $handlers |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function setInstallHandlers(array &$handlers) |
|
81
|
|
|
{ |
|
82
|
|
|
$language = $this->getLanguage(); |
|
83
|
|
|
|
|
84
|
|
|
$handlers['base'] = array( |
|
85
|
|
|
'module' => 'base', |
|
86
|
|
|
'title' => $language->text('Base'), |
|
87
|
|
|
'steps' => array( |
|
88
|
|
|
1 => array('title' => $language->text('Configure modules')), |
|
89
|
|
|
2 => array('title' => $language->text('Create demo')), |
|
90
|
|
|
3 => array('title' => $language->text('Finish installation')) |
|
91
|
|
|
), |
|
92
|
|
|
'handlers' => array( |
|
93
|
|
|
'install' => array('gplcart\\modules\\base\\handlers\\Installer', 'install'), |
|
94
|
|
|
'install_1' => array('gplcart\\modules\\base\\handlers\\Installer', 'installModules'), |
|
95
|
|
|
'install_2' => array('gplcart\\modules\\base\\handlers\\Installer', 'installDemo'), |
|
96
|
|
|
'install_3' => array('gplcart\\modules\\base\\handlers\\Installer', 'installFinish') |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Check if all required modules in place |
|
103
|
|
|
* @param array $data |
|
104
|
|
|
* @param array $result |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function checkRequiredModules(array $data, &$result) |
|
107
|
|
|
{ |
|
108
|
|
|
if ($data['installer'] === 'base' && empty($data['step']) && !$this->getModel()->hasAllRequiredModules()) { |
|
109
|
|
|
$result = array( |
|
110
|
|
|
'redirect' => '', |
|
111
|
|
|
'severity' => 'warning', |
|
112
|
|
|
'message' => $this->getLanguage()->text('You cannot use this installer because some modules are missed in your distribution') |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Replace system templates |
|
119
|
|
|
* @param array $templates |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function replaceTemplates(array &$templates) |
|
122
|
|
|
{ |
|
123
|
|
|
if (substr($templates[0], -15) === 'dashboard/intro' && $this->config->get('installer') === 'base') { |
|
124
|
|
|
$templates[0] = __DIR__ . '/templates/intro'; |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Returns the module model |
|
130
|
|
|
* @return \gplcart\modules\base\models\Installer |
|
131
|
|
|
*/ |
|
132
|
|
|
protected function getModel() |
|
133
|
|
|
{ |
|
134
|
|
|
return Container::get('gplcart\\modules\\base\\models\\Installer'); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Language model instance |
|
139
|
|
|
* @return \gplcart\core\models\Language $language |
|
140
|
|
|
*/ |
|
141
|
|
|
protected function getLanguage() |
|
142
|
|
|
{ |
|
143
|
|
|
return Container::get('gplcart\\core\\models\\Language'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|