@@ -148,67 +148,106 @@ protected function execute(InputInterface $input, OutputInterface $output)
148
148
149
149
$ this ->site ->loadLegacyFile ('/core/includes/bootstrap.inc ' );
150
150
151
- // check module's requirements
152
- $ this ->moduleRequirement ($ module );
151
+ // Check module's requirements, only for Drupal below 8.7.7. From there
152
+ // on, we just use Drupal's API.
153
+ if (version_compare (\Drupal::VERSION , '8.7.7 ' ) < 0 ) {
154
+ $ this ->moduleRequirement ($ module );
155
+ }
153
156
157
+ // When --composer is specified, build a command to Composer require
158
+ // all the needed modules in one go. This will just download the
159
+ // modules from the composer endpoint, not do any 'installation', in
160
+ // Drupal terminology.
154
161
if ($ composer ) {
155
- foreach ($ module as $ moduleItem ) {
156
- $ command = sprintf (
157
- 'composer show drupal/%s ' ,
158
- $ moduleItem
159
- );
160
-
161
- $ processBuilder = new ProcessBuilder ([]);
162
- $ processBuilder ->setWorkingDirectory ($ this ->appRoot );
163
- $ processBuilder ->setArguments (explode (' ' , $ command ));
164
- $ process = $ processBuilder ->getProcess ();
165
- $ process ->setTty ('true ' );
166
- $ process ->run ();
167
-
168
- if ($ process ->isSuccessful ()) {
169
- $ this ->getIo ()->info (
170
- sprintf (
171
- $ this ->trans ('commands.module.install.messages.download-with-composer ' ),
172
- $ moduleItem
173
- )
174
- );
162
+ $ composer_package_list = [];
163
+ $ module_list = [];
164
+ foreach ($ module as $ item ) {
165
+ // Decompose each module item passed on the command line into
166
+ // Composer-ready elements.
167
+ $ temp = explode ('/ ' , $ item );
168
+ if (count ($ temp ) === 1 ) {
169
+ $ package_namespace = 'drupal ' ;
170
+ $ package = $ temp [0 ];
175
171
} else {
176
- $ this ->getIo ()->error (
177
- sprintf (
178
- $ this ->trans ('commands.module.install.messages.not-installed-with-composer ' ),
179
- $ moduleItem
180
- )
181
- );
182
- throw new \RuntimeException ($ process ->getErrorOutput ());
172
+ $ package_namespace = $ temp [0 ];
173
+ $ package = $ temp [1 ];
174
+ }
175
+ $ temp = explode (': ' , $ package );
176
+ if (count ($ temp ) === 1 ) {
177
+ $ package_constraint = null ;
178
+ } else {
179
+ $ package = $ temp [0 ];
180
+ $ package_constraint = $ temp [1 ];
183
181
}
184
- }
185
182
186
- $ unInstalledModules = $ module ;
187
- } else {
188
- $ resultList = $ this ->downloadModules ($ module , $ latest );
189
-
190
- $ invalidModules = $ resultList ['invalid ' ];
191
- $ unInstalledModules = $ resultList ['uninstalled ' ];
192
-
193
- if ($ invalidModules ) {
194
- foreach ($ invalidModules as $ invalidModule ) {
195
- unset($ module [array_search ($ invalidModule , $ module )]);
196
- $ this ->getIo ()->error (
197
- sprintf (
198
- $ this ->trans ('commands.module.install.messages.invalid-name ' ),
199
- $ invalidModule
200
- )
201
- );
183
+ // Add the Composer argument.
184
+ $ temp = "$ package_namespace/ $ package " ;
185
+ if (isset ($ package_constraint )) {
186
+ $ temp .= ': ' . $ package_constraint ;
202
187
}
203
- }
188
+ $ composer_package_list [] = $ temp ;
204
189
205
- if (!$ unInstalledModules ) {
206
- $ this ->getIo ()->warning ($ this ->trans ('commands.module.install.messages.nothing ' ));
190
+ // Add the module to the list of those to be Drupal-installed.
191
+ if ($ package_namespace === 'drupal ' ) {
192
+ $ module_list [] = $ package ;
193
+ }
194
+ }
195
+ $ module = $ module_list ;
196
+
197
+ // Run the Composer require command.
198
+ $ command = array_merge (['composer ' , 'require ' ], $ composer_package_list );
199
+ $ this ->getIo ()->info ('Executing... ' . implode (' ' , $ command ));
200
+ $ processBuilder = new ProcessBuilder ([]);
201
+ $ processBuilder ->setWorkingDirectory ($ this ->appRoot );
202
+ $ processBuilder ->setArguments ($ command );
203
+ $ processBuilder ->inheritEnvironmentVariables ();
204
+ $ process = $ processBuilder ->getProcess ();
205
+ $ process ->setTty (true );
206
+ $ process ->run ();
207
+
208
+ if ($ process ->isSuccessful ()) {
209
+ $ this ->getIo ()->info (
210
+ sprintf (
211
+ $ this ->trans ('commands.module.install.messages.download-with-composer ' ),
212
+ implode (', ' , $ composer_package_list )
213
+ )
214
+ );
215
+ } else {
216
+ $ this ->getIo ()->error (
217
+ sprintf (
218
+ $ this ->trans ('commands.module.install.messages.not-installed-with-composer ' ),
219
+ implode (', ' , $ composer_package_list )
220
+ )
221
+ );
222
+ throw new \RuntimeException ($ process ->getErrorOutput ());
223
+ }
224
+ }
207
225
208
- return 0 ;
226
+ // Build the list of modules to be installed, skipping those that are
227
+ // installed already.
228
+ $ resultList = $ this ->downloadModules ($ module , $ latest );
229
+ $ invalidModules = $ resultList ['invalid ' ];
230
+ $ unInstalledModules = $ resultList ['uninstalled ' ];
231
+
232
+ if ($ invalidModules ) {
233
+ foreach ($ invalidModules as $ invalidModule ) {
234
+ unset($ module [array_search ($ invalidModule , $ module )]);
235
+ $ this ->getIo ()->error (
236
+ sprintf (
237
+ $ this ->trans ('commands.module.install.messages.invalid-name ' ),
238
+ $ invalidModule
239
+ )
240
+ );
209
241
}
210
242
}
211
243
244
+ // If no modules need to be installed, warn and exit.
245
+ if (!$ unInstalledModules ) {
246
+ $ this ->getIo ()->warning ($ this ->trans ('commands.module.install.messages.nothing ' ));
247
+ return 0 ;
248
+ }
249
+
250
+ // Install the needed modules.
212
251
try {
213
252
$ this ->getIo ()->comment (
214
253
sprintf (
0 commit comments