1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BFW\Install; |
4
|
|
|
|
5
|
|
|
use \BFW\Install\ModuleInstall; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Application class for install module script |
9
|
|
|
*/ |
10
|
|
|
class Application extends \BFW\Application |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \BFW\Install\ModuleInstall[] $modulesInstall Modules to install |
14
|
|
|
*/ |
15
|
|
|
protected static $modulesInstall = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected function initRequest() |
21
|
|
|
{ |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function initSession() |
29
|
|
|
{ |
30
|
|
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
protected function initErrors() |
37
|
|
|
{ |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function addModuleInstall(ModuleInstall $module) |
42
|
|
|
{ |
43
|
|
|
$moduleName = $module->getName(); |
44
|
|
|
|
45
|
|
|
self::$modulesInstall[$moduleName] = $module; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
protected function declareRunSteps() |
52
|
|
|
{ |
53
|
|
|
$this->runSteps = [ |
54
|
|
|
[$this, 'loadMemcached'], |
55
|
|
|
[$this, 'readAllModules'], |
56
|
|
|
[$this, 'installModules'] |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function run() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
foreach ($this->runSteps as $action) { |
66
|
|
|
$action(); |
67
|
|
|
|
68
|
|
|
$notifyAction = $action; |
69
|
|
|
if (is_array($action)) { |
70
|
|
|
$notifyAction = $action[1]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->notifyAction('bfw_modules_install_run_'.$notifyAction); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$this->notifyAction('bfw_modules_install_finish'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Install all modules in the order of the dependency tree. |
81
|
|
|
* |
82
|
|
|
* @return void |
83
|
|
|
*/ |
84
|
|
|
protected function installModules() |
85
|
|
|
{ |
86
|
|
|
echo 'Read all modules to run install script :'."\n"; |
87
|
|
|
|
88
|
|
|
$tree = $this->modules->getLoadTree(); |
89
|
|
|
|
90
|
|
|
foreach ($tree as $firstLine) { |
91
|
|
|
foreach ($firstLine as $secondLine) { |
92
|
|
|
foreach ($secondLine as $moduleName) { |
93
|
|
|
if (!isset(self::$modulesInstall[$moduleName])) { |
94
|
|
|
continue; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->installModule($moduleName); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Install a module |
105
|
|
|
* |
106
|
|
|
* @param string $moduleName The module name |
107
|
|
|
* |
108
|
|
|
* @return void |
109
|
|
|
*/ |
110
|
|
|
protected function installModule($moduleName) |
111
|
|
|
{ |
112
|
|
|
if (!isset(self::$modulesInstall[$moduleName])) { |
113
|
|
|
return; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
echo ' > Read for module '.$moduleName."\n"; |
117
|
|
|
|
118
|
|
|
$module = self::$modulesInstall[$moduleName]; |
119
|
|
|
$installScripts = $module->getSourceInstallScript(); |
120
|
|
|
|
121
|
|
|
if ($installScripts === '') { |
122
|
|
|
echo ' >> No script to run.'."\n"; |
123
|
|
|
return; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (is_string($installScripts)) { |
127
|
|
|
$installScripts = (array) $installScripts; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
foreach ($installScripts as $scriptPath) { |
|
|
|
|
131
|
|
|
$module->runInstall($scriptPath); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.