9
9
use Symfony \Component \Console \Output \OutputInterface ;
10
10
use Symfony \Component \Console \Input \InputOption ;
11
11
use Magento \Framework \App \DeploymentConfig ;
12
+ use Magento \Framework \Module \Status ;
12
13
13
14
abstract class AbstractModuleManageCommand extends AbstractModuleCommand
14
15
{
@@ -71,20 +72,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
71
72
$ output ->writeln (implode (PHP_EOL , $ messages ));
72
73
return ;
73
74
}
74
- /**
75
- * @var \Magento\Framework\Module\Status $status
76
- */
77
- $ status = $ this ->objectManager ->get ('Magento\Framework\Module\Status ' );
78
75
try {
79
- $ modulesToChange = $ status ->getModulesToChange ($ isEnable , $ modules );
76
+ $ modulesToChange = $ this -> getStatus () ->getModulesToChange ($ isEnable , $ modules );
80
77
} catch (\LogicException $ e ) {
81
78
$ output ->writeln ('<error> ' . $ e ->getMessage () . '</error> ' );
82
79
return ;
83
80
}
84
81
if (!empty ($ modulesToChange )) {
85
82
$ force = $ input ->getOption (self ::INPUT_KEY_FORCE );
86
83
if (!$ force ) {
87
- $ constraints = $ status ->checkConstraints ($ isEnable , $ modulesToChange );
84
+ $ constraints = $ this -> getStatus () ->checkConstraints ($ isEnable , $ modulesToChange );
88
85
if ($ constraints ) {
89
86
$ output ->writeln (
90
87
"<error>Unable to change status of modules because of the following constraints:</error> "
@@ -93,22 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
93
90
return ;
94
91
}
95
92
}
96
- $ status ->setIsEnabled ($ isEnable , $ modulesToChange );
97
- if ($ isEnable ) {
98
- $ output ->writeln ('<info>The following modules have been enabled:</info> ' );
99
- $ output ->writeln ('<info>- ' . implode ("\n- " , $ modulesToChange ) . '</info> ' );
100
- $ output ->writeln ('' );
101
- if ($ this ->getDeploymentConfig ()->isAvailable ()) {
102
- $ output ->writeln (
103
- '<info>To make sure that the enabled modules are properly registered, '
104
- . " run 'setup:upgrade'.</info> "
105
- );
106
- }
107
- } else {
108
- $ output ->writeln ('<info>The following modules have been disabled:</info> ' );
109
- $ output ->writeln ('<info>- ' . implode ("\n- " , $ modulesToChange ) . '</info> ' );
110
- $ output ->writeln ('' );
111
- }
93
+ $ this ->setIsEnabled ($ isEnable , $ modulesToChange , $ output );
112
94
$ this ->cleanup ($ input , $ output );
113
95
if ($ force ) {
114
96
$ output ->writeln (
@@ -121,6 +103,43 @@ protected function execute(InputInterface $input, OutputInterface $output)
121
103
}
122
104
}
123
105
106
+ /**
107
+ * Enable/disable modules
108
+ *
109
+ * @param bool $isEnable
110
+ * @param string[] $modulesToChange
111
+ * @param OutputInterface $output
112
+ */
113
+ private function setIsEnabled ($ isEnable , $ modulesToChange , $ output )
114
+ {
115
+ $ this ->getStatus ()->setIsEnabled ($ isEnable , $ modulesToChange );
116
+ if ($ isEnable ) {
117
+ $ output ->writeln ('<info>The following modules have been enabled:</info> ' );
118
+ $ output ->writeln ('<info>- ' . implode ("\n- " , $ modulesToChange ) . '</info> ' );
119
+ $ output ->writeln ('' );
120
+ if ($ this ->getDeploymentConfig ()->isAvailable ()) {
121
+ $ output ->writeln (
122
+ '<info>To make sure that the enabled modules are properly registered, '
123
+ . " run 'setup:upgrade'.</info> "
124
+ );
125
+ }
126
+ } else {
127
+ $ output ->writeln ('<info>The following modules have been disabled:</info> ' );
128
+ $ output ->writeln ('<info>- ' . implode ("\n- " , $ modulesToChange ) . '</info> ' );
129
+ $ output ->writeln ('' );
130
+ }
131
+ }
132
+
133
+ /**
134
+ * Get module status
135
+ *
136
+ * @return Status
137
+ */
138
+ private function getStatus ()
139
+ {
140
+ return $ this ->objectManager ->get (Status::class);
141
+ }
142
+
124
143
/**
125
144
* Validate list of modules and return error messages
126
145
*
0 commit comments