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,26 +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 ' , InputArgument::OPTIONAL , '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
- $ moduleName = (string )$ input ->getArgument ('module ' );
61
- if ($ moduleName ) {
62
- return $ this ->showSpecificModule ($ moduleName , $ output );
60
+ $ moduleNames = $ input ->getArgument ('module-names ' );
61
+ if (!empty ($ moduleNames )) {
62
+ foreach ($ moduleNames as $ moduleName ) {
63
+ $ this ->showSpecificModule ($ moduleName , $ output );
64
+ }
65
+ return Cli::RETURN_SUCCESS ;
63
66
}
64
67
65
68
$ onlyEnabled = $ input ->getOption ('enabled ' );
@@ -79,34 +82,42 @@ protected function execute(InputInterface $input, OutputInterface $output)
79
82
$ output ->writeln ("<info>List of disabled modules:</info> " );
80
83
$ this ->showDisabledModules ($ output );
81
84
$ output ->writeln ('' );
85
+
86
+ return Cli::RETURN_SUCCESS ;
82
87
}
83
88
84
89
/**
90
+ * Specific module show
91
+ *
85
92
* @param string $moduleName
86
93
* @param OutputInterface $output
94
+ * @return int
87
95
*/
88
- private function showSpecificModule (string $ moduleName , OutputInterface $ output )
96
+ private function showSpecificModule (string $ moduleName , OutputInterface $ output ): int
89
97
{
90
98
$ allModules = $ this ->getAllModules ();
91
- if (!in_array ($ moduleName , $ allModules ->getNames ())) {
92
- $ output ->writeln (' <error>Module does not exist</error> ' );
99
+ if (!in_array ($ moduleName , $ allModules ->getNames (), true )) {
100
+ $ output ->writeln ($ moduleName . ' : <error>Module does not exist</error> ' );
93
101
return Cli::RETURN_FAILURE ;
94
102
}
95
103
96
104
$ enabledModules = $ this ->getEnabledModules ();
97
- if (in_array ($ moduleName , $ enabledModules ->getNames ())) {
98
- $ output ->writeln (' <info>Module is enabled</info> ' );
105
+ if (in_array ($ moduleName , $ enabledModules ->getNames (), true )) {
106
+ $ output ->writeln ($ moduleName . ' : <info>Module is enabled</info> ' );
99
107
return Cli::RETURN_FAILURE ;
100
108
}
101
109
102
- $ output ->writeln (' <info>Module is disabled</info> ' );
103
- return \ Magento \ Framework \ Console \ Cli::RETURN_SUCCESS ;
110
+ $ output ->writeln ($ moduleName . ' : <info> Module is disabled</info> ' );
111
+ return Cli::RETURN_SUCCESS ;
104
112
}
105
113
106
114
/**
115
+ * Enable modules show
116
+ *
107
117
* @param OutputInterface $output
118
+ * @return int
108
119
*/
109
- private function showEnabledModules (OutputInterface $ output )
120
+ private function showEnabledModules (OutputInterface $ output ): int
110
121
{
111
122
$ enabledModules = $ this ->getEnabledModules ();
112
123
$ enabledModuleNames = $ enabledModules ->getNames ();
@@ -116,13 +127,17 @@ private function showEnabledModules(OutputInterface $output)
116
127
}
117
128
118
129
$ output ->writeln (join ("\n" , $ enabledModuleNames ));
119
- return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
130
+
131
+ return Cli::RETURN_SUCCESS ;
120
132
}
121
133
122
134
/**
135
+ * Disabled modules show
136
+ *
123
137
* @param OutputInterface $output
138
+ * @return int
124
139
*/
125
- private function showDisabledModules (OutputInterface $ output )
140
+ private function showDisabledModules (OutputInterface $ output ): int
126
141
{
127
142
$ disabledModuleNames = $ this ->getDisabledModuleNames ();
128
143
if (count ($ disabledModuleNames ) === 0 ) {
@@ -131,32 +146,42 @@ private function showDisabledModules(OutputInterface $output)
131
146
}
132
147
133
148
$ output ->writeln (join ("\n" , $ disabledModuleNames ));
134
- return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
149
+
150
+ return Cli::RETURN_SUCCESS ;
135
151
}
136
152
137
153
/**
154
+ * Returns all modules
155
+ *
138
156
* @return FullModuleList
139
157
*/
140
158
private function getAllModules (): FullModuleList
141
159
{
142
- return $ this ->objectManagerProvider ->get ()->create (FullModuleList::class);
160
+ return $ this ->objectManagerProvider ->get ()
161
+ ->create (FullModuleList::class);
143
162
}
144
163
145
164
/**
165
+ * Returns enabled modules
166
+ *
146
167
* @return ModuleList
147
168
*/
148
169
private function getEnabledModules (): ModuleList
149
170
{
150
- return $ this ->objectManagerProvider ->get ()->create (ModuleList::class);
171
+ return $ this ->objectManagerProvider ->get ()
172
+ ->create (ModuleList::class);
151
173
}
152
174
153
175
/**
176
+ * Returns disabled module names
177
+ *
154
178
* @return array
155
179
*/
156
180
private function getDisabledModuleNames (): array
157
181
{
158
182
$ fullModuleList = $ this ->getAllModules ();
159
183
$ enabledModules = $ this ->getEnabledModules ();
184
+
160
185
return array_diff ($ fullModuleList ->getNames (), $ enabledModules ->getNames ());
161
186
}
162
187
}
0 commit comments