@@ -21,12 +21,8 @@ public function actionIndex()
21
21
22
22
public function actionInstall ($ name )
23
23
{
24
- $ namespace = 'nullref/yii2- ' . $ name ;
25
- $ installerClassName = '\\nullref \\' . $ name . '\\Installer ' ;
26
- if (isset (\Yii::$ app ->extensions [$ namespace ])) {
27
- if (class_exists ($ installerClassName )) {
28
- /** @var ModuleInstaller $installer */
29
- $ installer = \Yii::createObject ($ installerClassName , ['db ' => $ this ->db ]);
24
+ if ($ this ->moduleExists ($ name )) {
25
+ if (($ installer = $ this ->getInstaller ($ name )) !== null ) {
30
26
$ installer ->install ();
31
27
echo 'Module module was installed successfully. ' . PHP_EOL ;
32
28
} else {
@@ -38,22 +34,63 @@ public function actionInstall($name)
38
34
}
39
35
40
36
37
+ /**
38
+ * @param $name
39
+ */
41
40
public function actionUninstall ($ name )
42
41
{
42
+ if ($ this ->moduleExists ($ name )) {
43
+ if (($ installer = $ this ->getInstaller ($ name )) !== null ) {
44
+ $ installer ->uninstall ();
45
+ echo 'Module module was uninstalled successfully. ' . PHP_EOL ;
46
+ } else {
47
+ echo 'Module installer don \'t found. ' . PHP_EOL ;
48
+ }
49
+ } else {
50
+ echo 'Module don \'t found. ' . PHP_EOL ;
51
+ }
52
+ }
43
53
44
- $ namespace = 'nullref/yii2- ' . $ name ;
45
- $ installerClassName = '\\nullref \\' . $ name . '\\Installer ' ;
46
- if (isset (\Yii::$ app ->extensions [$ namespace ])) {
47
- if (class_exists ($ installerClassName )) {
48
- /** @var ModuleInstaller $installer */
49
- $ installer = \Yii::createObject ($ installerClassName , ['db ' => $ this ->db ]);
54
+ /**
55
+ * @param $name
56
+ */
57
+ public function actionReinstall ($ name )
58
+ {
59
+ if ($ this ->moduleExists ($ name )) {
60
+ if (($ installer = $ this ->getInstaller ($ name )) !== null ) {
50
61
$ installer ->uninstall ();
51
- echo 'Module module was installed successfully. ' . PHP_EOL ;
62
+ $ installer ->install ();
63
+ echo 'Module module was reinstalled successfully. ' . PHP_EOL ;
52
64
} else {
53
65
echo 'Module installer don \'t found. ' . PHP_EOL ;
54
66
}
55
67
} else {
56
68
echo 'Module don \'t found. ' . PHP_EOL ;
57
69
}
58
70
}
71
+
72
+ /**
73
+ * @param $name
74
+ * @return null|ModuleInstaller
75
+ * @throws \yii\base\InvalidConfigException
76
+ */
77
+ protected function getInstaller ($ name )
78
+ {
79
+ $ installerClassName = '\\nullref \\' . $ name . '\\Installer ' ;
80
+ if (class_exists ($ installerClassName )) {
81
+ return \Yii::createObject ($ installerClassName , ['db ' => $ this ->db ]);
82
+ } else {
83
+ return null ;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * @param $name
89
+ * @return bool
90
+ */
91
+ protected function moduleExists ($ name )
92
+ {
93
+ $ namespace = 'nullref/yii2- ' . $ name ;
94
+ return isset (\Yii::$ app ->extensions [$ namespace ]);
95
+ }
59
96
}
0 commit comments