8
8
9
9
namespace Magento \Setup \Console \Command ;
10
10
11
+ use Magento \Framework \Console \Cli ;
11
12
use Magento \Framework \Module \FullModuleList ;
12
13
use Magento \Framework \Module \ModuleList ;
13
14
use Magento \Setup \Model \ObjectManagerProvider ;
14
- use Magento \ Framework \Console \Cli ;
15
+ use Symfony \ Component \Console \Input \ InputArgument ;
15
16
use Symfony \Component \Console \Input \InputInterface ;
16
17
use Symfony \Component \Console \Output \OutputInterface ;
17
- use Symfony \Component \Console \Input \InputArgument ;
18
18
19
19
/**
20
20
* Command for displaying status of modules
21
21
*/
22
22
class ModuleStatusCommand extends AbstractSetupCommand
23
23
{
24
24
/**
25
- * Object manager provider
26
- *
27
25
* @var ObjectManagerProvider
28
26
*/
29
27
private $ objectManagerProvider ;
30
28
31
29
/**
32
- * Inject dependencies
33
- *
34
30
* @param ObjectManagerProvider $objectManagerProvider
35
31
*/
36
32
public function __construct (ObjectManagerProvider $ objectManagerProvider )
@@ -40,28 +36,33 @@ public function __construct(ObjectManagerProvider $objectManagerProvider)
40
36
}
41
37
42
38
/**
43
- * { @inheritdoc}
39
+ * @inheritdoc
44
40
*/
45
41
protected function configure ()
46
42
{
47
43
$ this ->setName ('module:status ' )
48
44
->setDescription ('Displays status of modules ' )
49
- ->addArgument ('module-names ' , InputArgument::OPTIONAL | InputArgument::IS_ARRAY , 'Optional module name ' )
45
+ ->addArgument (
46
+ 'module-names ' ,
47
+ InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
48
+ 'Optional module name '
49
+ )
50
50
->addOption ('enabled ' , null , null , 'Print only enabled modules ' )
51
51
->addOption ('disabled ' , null , null , 'Print only disabled modules ' );
52
52
parent ::configure ();
53
53
}
54
54
55
55
/**
56
- * { @inheritdoc}
56
+ * @inheritdoc
57
57
*/
58
58
protected function execute (InputInterface $ input , OutputInterface $ output )
59
59
{
60
60
$ moduleNames = $ input ->getArgument ('module-names ' );
61
61
if (!empty ($ moduleNames )) {
62
- foreach ($ moduleNames as $ moduleName )
62
+ foreach ($ moduleNames as $ moduleName ) {
63
63
$ this ->showSpecificModule ($ moduleName , $ output );
64
- return ;
64
+ }
65
+ return 0 ;
65
66
}
66
67
67
68
$ onlyEnabled = $ input ->getOption ('enabled ' );
@@ -81,34 +82,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
81
82
$ output ->writeln ("<info>List of disabled modules:</info> " );
82
83
$ this ->showDisabledModules ($ output );
83
84
$ output ->writeln ('' );
85
+
86
+ return 0 ;
84
87
}
85
88
86
89
/**
90
+ * Specific module show
91
+ *
87
92
* @param string $moduleName
88
93
* @param OutputInterface $output
94
+ * @return int
89
95
*/
90
- private function showSpecificModule (string $ moduleName , OutputInterface $ output )
96
+ private function showSpecificModule (string $ moduleName , OutputInterface $ output ): int
91
97
{
92
98
$ allModules = $ this ->getAllModules ();
93
- if (!in_array ($ moduleName , $ allModules ->getNames ())) {
94
- $ output ->writeln ($ moduleName. ' : <error>Module does not exist</error> ' );
99
+ if (!in_array ($ moduleName , $ allModules ->getNames (), true )) {
100
+ $ output ->writeln ($ moduleName . ' : <error>Module does not exist</error> ' );
95
101
return Cli::RETURN_FAILURE ;
96
102
}
97
103
98
104
$ enabledModules = $ this ->getEnabledModules ();
99
- if (in_array ($ moduleName , $ enabledModules ->getNames ())) {
100
- $ output ->writeln ($ moduleName. ' : <info>Module is enabled</info> ' );
105
+ if (in_array ($ moduleName , $ enabledModules ->getNames (), true )) {
106
+ $ output ->writeln ($ moduleName . ' : <info>Module is enabled</info> ' );
101
107
return Cli::RETURN_FAILURE ;
102
108
}
103
109
104
- $ output ->writeln ($ moduleName. ' : <info> Module is disabled</info> ' );
105
- return \ Magento \ Framework \ Console \ Cli::RETURN_SUCCESS ;
110
+ $ output ->writeln ($ moduleName . ' : <info> Module is disabled</info> ' );
111
+ return Cli::RETURN_SUCCESS ;
106
112
}
107
113
108
114
/**
115
+ * Enable modules show
116
+ *
109
117
* @param OutputInterface $output
118
+ * @return int
110
119
*/
111
- private function showEnabledModules (OutputInterface $ output )
120
+ private function showEnabledModules (OutputInterface $ output ): int
112
121
{
113
122
$ enabledModules = $ this ->getEnabledModules ();
114
123
$ enabledModuleNames = $ enabledModules ->getNames ();
@@ -118,13 +127,17 @@ private function showEnabledModules(OutputInterface $output)
118
127
}
119
128
120
129
$ output ->writeln (join ("\n" , $ enabledModuleNames ));
121
- return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
130
+
131
+ return Cli::RETURN_SUCCESS ;
122
132
}
123
133
124
134
/**
135
+ * Disabled modules show
136
+ *
125
137
* @param OutputInterface $output
138
+ * @return int
126
139
*/
127
- private function showDisabledModules (OutputInterface $ output )
140
+ private function showDisabledModules (OutputInterface $ output ): int
128
141
{
129
142
$ disabledModuleNames = $ this ->getDisabledModuleNames ();
130
143
if (count ($ disabledModuleNames ) === 0 ) {
@@ -133,32 +146,42 @@ private function showDisabledModules(OutputInterface $output)
133
146
}
134
147
135
148
$ output ->writeln (join ("\n" , $ disabledModuleNames ));
136
- return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
149
+
150
+ return Cli::RETURN_SUCCESS ;
137
151
}
138
152
139
153
/**
154
+ * Returns all modules
155
+ *
140
156
* @return FullModuleList
141
157
*/
142
158
private function getAllModules (): FullModuleList
143
159
{
144
- return $ this ->objectManagerProvider ->get ()->create (FullModuleList::class);
160
+ return $ this ->objectManagerProvider ->get ()
161
+ ->create (FullModuleList::class);
145
162
}
146
163
147
164
/**
165
+ * Returns enabled modules
166
+ *
148
167
* @return ModuleList
149
168
*/
150
169
private function getEnabledModules (): ModuleList
151
170
{
152
- return $ this ->objectManagerProvider ->get ()->create (ModuleList::class);
171
+ return $ this ->objectManagerProvider ->get ()
172
+ ->create (ModuleList::class);
153
173
}
154
174
155
175
/**
176
+ * Returns disabled module names
177
+ *
156
178
* @return array
157
179
*/
158
180
private function getDisabledModuleNames (): array
159
181
{
160
182
$ fullModuleList = $ this ->getAllModules ();
161
183
$ enabledModules = $ this ->getEnabledModules ();
184
+
162
185
return array_diff ($ fullModuleList ->getNames (), $ enabledModules ->getNames ());
163
186
}
164
187
}
0 commit comments