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