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\models; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Container; |
13
|
|
|
use gplcart\core\models\Translation; |
14
|
|
|
use gplcart\core\Module; |
15
|
|
|
use RuntimeException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Installer model |
19
|
|
|
*/ |
20
|
|
|
class Install |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Translation UI model instance |
25
|
|
|
* @var \gplcart\core\models\Translation $translation |
26
|
|
|
*/ |
27
|
|
|
protected $translation; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Module class instance |
31
|
|
|
* @var \gplcart\core\Module $module |
32
|
|
|
*/ |
33
|
|
|
protected $module; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Module $module |
37
|
|
|
* @param Translation $translation |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Module $module, Translation $translation) |
40
|
|
|
{ |
41
|
|
|
$this->module = $module; |
42
|
|
|
$this->translation = $translation; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Returns an array of modules required for Base installation profile |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
public function getRequiredModules() |
50
|
|
|
{ |
51
|
|
|
return gplcart_config_get(__DIR__ . '/../config/modules.php'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Whether the current distribution contains all the required modules |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function hasAllRequiredModules() |
59
|
|
|
{ |
60
|
|
|
$required = $this->getRequiredModules(); |
61
|
|
|
$available = array_keys($this->module->getList()); |
62
|
|
|
$difference = array_diff($required, array_intersect($required, $available)); |
63
|
|
|
|
64
|
|
|
return empty($difference); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Install all required modules |
69
|
|
|
* @return bool |
70
|
|
|
* @throws RuntimeException |
71
|
|
|
*/ |
72
|
|
|
public function installModules() |
73
|
|
|
{ |
74
|
|
|
foreach ($this->getRequiredModules() as $module_id) { |
75
|
|
|
if ($this->getModuleModel()->install($module_id) !== true) { |
76
|
|
|
$error = $this->translation->text('Failed to install module @module_id', array('@module_id' => $module_id)); |
77
|
|
|
throw new RuntimeException($error); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return true; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Create demo content using Demo module |
86
|
|
|
* @param integer $store_id |
87
|
|
|
* @param string $handler_id |
88
|
|
|
* @return bool|string |
89
|
|
|
*/ |
90
|
|
|
public function createDemo($store_id, $handler_id) |
91
|
|
|
{ |
92
|
|
|
return $this->getDemoModule()->create($store_id, $handler_id); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns an array of demo handlers |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function getDemoHandlers() |
100
|
|
|
{ |
101
|
|
|
return $this->getDemoModule()->getHandlers(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns Demo module instance |
106
|
|
|
* @return \gplcart\modules\demo\Main |
107
|
|
|
*/ |
108
|
|
|
public function getDemoModule() |
109
|
|
|
{ |
110
|
|
|
/* @var \gplcart\modules\demo\Main $instance */ |
111
|
|
|
$instance = $this->module->getInstance('demo'); |
112
|
|
|
return $instance; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Returns Module model class instance |
117
|
|
|
* @return \gplcart\core\models\Module |
118
|
|
|
*/ |
119
|
|
|
protected function getModuleModel() |
120
|
|
|
{ |
121
|
|
|
/** @var \gplcart\core\models\Module $instance */ |
122
|
|
|
$instance = Container::get('gplcart\\core\\models\\Module'); |
123
|
|
|
return $instance; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|