3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
7
+ declare (strict_types=1 );
8
+
6
9
namespace Magento \Setup \Console \Command ;
7
10
11
+ use Magento \Framework \Module \FullModuleList ;
12
+ use Magento \Framework \Module \ModuleList ;
8
13
use Magento \Setup \Model \ObjectManagerProvider ;
14
+ use Magento \Framework \Console \Cli ;
9
15
use Symfony \Component \Console \Input \InputInterface ;
10
16
use Symfony \Component \Console \Output \OutputInterface ;
17
+ use Symfony \Component \Console \Input \InputArgument ;
11
18
12
19
/**
13
20
* Command for displaying status of modules
@@ -38,7 +45,10 @@ public function __construct(ObjectManagerProvider $objectManagerProvider)
38
45
protected function configure ()
39
46
{
40
47
$ this ->setName ('module:status ' )
41
- ->setDescription ('Displays status of modules ' );
48
+ ->setDescription ('Displays status of modules ' )
49
+ ->addArgument ('module ' , InputArgument::OPTIONAL , 'Optional module name ' )
50
+ ->addOption ('enabled ' , null , null , 'Print only enabled modules ' )
51
+ ->addOption ('disabled ' , null , null , 'Print only disabled modules ' );
42
52
parent ::configure ();
43
53
}
44
54
@@ -47,24 +57,106 @@ protected function configure()
47
57
*/
48
58
protected function execute (InputInterface $ input , OutputInterface $ output )
49
59
{
50
- $ moduleList = $ this ->objectManagerProvider ->get ()->create (\Magento \Framework \Module \ModuleList::class);
51
- $ output ->writeln ('<info>List of enabled modules:</info> ' );
52
- $ enabledModules = $ moduleList ->getNames ();
53
- if (count ($ enabledModules ) === 0 ) {
54
- $ output ->writeln ('None ' );
55
- } else {
56
- $ output ->writeln (join ("\n" , $ enabledModules ));
60
+ $ moduleName = (string )$ input ->getArgument ('module ' );
61
+ if ($ moduleName ) {
62
+ return $ this ->showSpecificModule ($ moduleName , $ output );
57
63
}
64
+
65
+ $ onlyEnabled = $ input ->getOption ('enabled ' );
66
+ if ($ onlyEnabled ) {
67
+ return $ this ->showEnabledModules ($ output );
68
+ }
69
+
70
+ $ onlyDisabled = $ input ->getOption ('disabled ' );
71
+ if ($ onlyDisabled ) {
72
+ return $ this ->showDisabledModules ($ output );
73
+ }
74
+
75
+ $ output ->writeln ('<info>List of enabled modules:</info> ' );
76
+ $ this ->showEnabledModules ($ output );
58
77
$ output ->writeln ('' );
59
78
60
- $ fullModuleList = $ this ->objectManagerProvider ->get ()->create (\Magento \Framework \Module \FullModuleList::class);
61
79
$ output ->writeln ("<info>List of disabled modules:</info> " );
62
- $ disabledModules = array_diff ($ fullModuleList ->getNames (), $ enabledModules );
63
- if (count ($ disabledModules ) === 0 ) {
80
+ $ this ->showDisabledModules ($ output );
81
+ $ output ->writeln ('' );
82
+ }
83
+
84
+ /**
85
+ * @param string $moduleName
86
+ * @param OutputInterface $output
87
+ */
88
+ private function showSpecificModule (string $ moduleName , OutputInterface $ output )
89
+ {
90
+ $ allModules = $ this ->getAllModules ();
91
+ if (!in_array ($ moduleName , $ allModules ->getNames ())) {
92
+ $ output ->writeln ('<error>Module does not exist</error> ' );
93
+ return Cli::RETURN_FAILURE ;
94
+ }
95
+
96
+ $ enabledModules = $ this ->getEnabledModules ();
97
+ if (in_array ($ moduleName , $ enabledModules ->getNames ())) {
98
+ $ output ->writeln ('<info>Module is enabled</info> ' );
99
+ return Cli::RETURN_FAILURE ;
100
+ }
101
+
102
+ $ output ->writeln ('<info>Module is disabled</info> ' );
103
+ return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
104
+ }
105
+
106
+ /**
107
+ * @param OutputInterface $output
108
+ */
109
+ private function showEnabledModules (OutputInterface $ output )
110
+ {
111
+ $ enabledModules = $ this ->getEnabledModules ();
112
+ $ enabledModuleNames = $ enabledModules ->getNames ();
113
+ if (count ($ enabledModuleNames ) === 0 ) {
114
+ $ output ->writeln ('None ' );
115
+ return Cli::RETURN_FAILURE ;
116
+ }
117
+
118
+ $ output ->writeln (join ("\n" , $ enabledModuleNames ));
119
+ return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
120
+ }
121
+
122
+ /**
123
+ * @param OutputInterface $output
124
+ */
125
+ private function showDisabledModules (OutputInterface $ output )
126
+ {
127
+ $ disabledModuleNames = $ this ->getDisabledModuleNames ();
128
+ if (count ($ disabledModuleNames ) === 0 ) {
64
129
$ output ->writeln ('None ' );
65
- } else {
66
- $ output ->writeln (join ("\n" , $ disabledModules ));
130
+ return Cli::RETURN_FAILURE ;
67
131
}
132
+
133
+ $ output ->writeln (join ("\n" , $ disabledModuleNames ));
68
134
return \Magento \Framework \Console \Cli::RETURN_SUCCESS ;
69
135
}
136
+
137
+ /**
138
+ * @return FullModuleList
139
+ */
140
+ private function getAllModules (): FullModuleList
141
+ {
142
+ return $ this ->objectManagerProvider ->get ()->create (FullModuleList::class);
143
+ }
144
+
145
+ /**
146
+ * @return ModuleList
147
+ */
148
+ private function getEnabledModules (): ModuleList
149
+ {
150
+ return $ this ->objectManagerProvider ->get ()->create (ModuleList::class);
151
+ }
152
+
153
+ /**
154
+ * @return array
155
+ */
156
+ private function getDisabledModuleNames (): array
157
+ {
158
+ $ fullModuleList = $ this ->getAllModules ();
159
+ $ enabledModules = $ this ->getEnabledModules ();
160
+ return array_diff ($ fullModuleList ->getNames (), $ enabledModules ->getNames ());
161
+ }
70
162
}
0 commit comments