17
17
use Magento \Framework \Shell \ComplexParameter ;
18
18
use Magento \Setup \Console \CompilerPreparation ;
19
19
use \Magento \Framework \App \ProductMetadata ;
20
+ use Magento \Framework \App \State ;
20
21
21
22
/**
22
23
* Magento 2 CLI Application. This is the hood for all command line tools supported by Magento
@@ -47,6 +48,11 @@ class Cli extends SymfonyApplication
47
48
*/
48
49
private $ initException ;
49
50
51
+ /**
52
+ * @var \Magento\Framework\ObjectManagerInterface
53
+ */
54
+ private $ objectManager ;
55
+
50
56
/**
51
57
* @param string $name application name
52
58
* @param string $version application version
@@ -56,15 +62,7 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
56
62
{
57
63
$ this ->serviceManager = \Zend \Mvc \Application::init (require BP . '/setup/config/application.config.php ' )
58
64
->getServiceManager ();
59
- $ generationDirectoryAccess = new GenerationDirectoryAccess ($ this ->serviceManager );
60
- if (!$ generationDirectoryAccess ->check ()) {
61
- $ output = new ConsoleOutput ();
62
- $ output ->writeln (
63
- '<error>Command line user does not have read and write permissions on var/generation directory. Please '
64
- . ' address this issue before using Magento command line.</error> '
65
- );
66
- exit (0 );
67
- }
65
+
68
66
/**
69
67
* Temporary workaround until the compiler is able to clear the generation directory
70
68
* @todo remove after MAGETWO-44493 resolved
@@ -74,6 +72,21 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
74
72
$ compilerPreparation ->handleCompilerEnvironment ();
75
73
}
76
74
75
+ $ bootstrapParam = new ComplexParameter (self ::INPUT_KEY_BOOTSTRAP );
76
+ $ params = $ bootstrapParam ->mergeFromArgv ($ _SERVER , $ _SERVER );
77
+ $ params [Bootstrap::PARAM_REQUIRE_MAINTENANCE ] = null ;
78
+ $ bootstrap = Bootstrap::create (BP , $ params );
79
+ $ this ->objectManager = $ bootstrap ->getObjectManager ();
80
+
81
+ if ($ this ->checkGenerationDirectoryAccess ()) {
82
+ $ output = new ConsoleOutput ();
83
+ $ output ->writeln (
84
+ '<error>Command line user does not have read and write permissions on var/generation directory. Please '
85
+ . ' address this issue before using Magento command line.</error> '
86
+ );
87
+ exit (0 );
88
+ }
89
+
77
90
if ($ version == 'UNKNOWN ' ) {
78
91
$ directoryList = new DirectoryList (BP );
79
92
$ composerJsonFinder = new ComposerJsonFinder ($ directoryList );
@@ -83,6 +96,22 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
83
96
parent ::__construct ($ name , $ version );
84
97
}
85
98
99
+ /**
100
+ * Check generation directory access.
101
+ *
102
+ * Skip and return true if production mode is enabled.
103
+ *
104
+ * @return bool
105
+ */
106
+ private function checkGenerationDirectoryAccess ()
107
+ {
108
+ $ generationDirectoryAccess = new GenerationDirectoryAccess ($ this ->serviceManager );
109
+ /** @var State $state */
110
+ $ state = $ this ->objectManager ->create (State::class);
111
+
112
+ return $ state ->getMode () !== State::MODE_PRODUCTION && !$ generationDirectoryAccess ->check ();
113
+ }
114
+
86
115
/**
87
116
* Process an error happened during initialization of commands, if any
88
117
*
@@ -121,31 +150,25 @@ protected function getApplicationCommands()
121
150
{
122
151
$ commands = [];
123
152
try {
124
- $ bootstrapParam = new ComplexParameter (self ::INPUT_KEY_BOOTSTRAP );
125
- $ params = $ bootstrapParam ->mergeFromArgv ($ _SERVER , $ _SERVER );
126
- $ params [Bootstrap::PARAM_REQUIRE_MAINTENANCE ] = null ;
127
- $ bootstrap = Bootstrap::create (BP , $ params );
128
- $ objectManager = $ bootstrap ->getObjectManager ();
129
-
130
153
// Specialized setup command list available before and after M2 install
131
154
if (class_exists ('Magento\Setup\Console\CommandList ' )
132
155
&& class_exists ('Magento\Setup\Model\ObjectManagerProvider ' )
133
156
) {
134
157
/** @var \Magento\Setup\Model\ObjectManagerProvider $omProvider */
135
158
$ omProvider = $ this ->serviceManager ->get (\Magento \Setup \Model \ObjectManagerProvider::class);
136
- $ omProvider ->setObjectManager ($ objectManager );
159
+ $ omProvider ->setObjectManager ($ this -> objectManager );
137
160
$ setupCommandList = new \Magento \Setup \Console \CommandList ($ this ->serviceManager );
138
161
$ commands = array_merge ($ commands , $ setupCommandList ->getCommands ());
139
162
}
140
163
141
164
// Allowing instances of all modular commands only after M2 install
142
- if ($ objectManager ->get (\Magento \Framework \App \DeploymentConfig::class)->isAvailable ()) {
165
+ if ($ this -> objectManager ->get (\Magento \Framework \App \DeploymentConfig::class)->isAvailable ()) {
143
166
/** @var \Magento\Framework\Console\CommandListInterface $commandList */
144
- $ commandList = $ objectManager ->create (\Magento \Framework \Console \CommandListInterface::class);
167
+ $ commandList = $ this -> objectManager ->create (\Magento \Framework \Console \CommandListInterface::class);
145
168
$ commands = array_merge ($ commands , $ commandList ->getCommands ());
146
169
}
147
170
148
- $ commands = array_merge ($ commands , $ this ->getVendorCommands ($ objectManager ));
171
+ $ commands = array_merge ($ commands , $ this ->getVendorCommands ($ this -> objectManager ));
149
172
} catch (\Exception $ e ) {
150
173
$ this ->initException = $ e ;
151
174
}
0 commit comments