@@ -318,42 +318,36 @@ public function drushSetup(array $options = [
318
318
/**
319
319
* Setup Drupal services file.
320
320
*
321
- * This command will copy the content of the file given in service-parameters to "services.yml" file in
322
- * the site directory.
323
- *
324
- * The services file name can be set in the Task Runner
325
- * configuration by setting the "drupal.service_parameters" property.
321
+ * This command will add the configuration under service_parameters present in
322
+ * runner.yml into "services.yml" file in the site directory.
326
323
*
327
324
* @command drupal:services-setup
328
325
*
329
- * @option service-parameters Drupal services filename.
330
326
* @option root Drupal root.
331
327
* @option sites-subdir Drupal site subdirectory.
332
328
* @option force Drupal force generation of a new services.yml.
333
329
*
334
330
* @param array $options
335
331
*
336
332
* @return \Robo\Collection\CollectionBuilder
337
- * @throws \Exception
338
333
*/
339
334
public function servicesSetup (array $ options = [
340
- 'service-parameters ' => InputOption::VALUE_REQUIRED ,
341
335
'root ' => InputOption::VALUE_REQUIRED ,
342
336
'sites-subdir ' => InputOption::VALUE_REQUIRED ,
343
337
'force ' => false ,
344
338
])
345
339
{
346
- $ services_runner_file = $ this ->getConfig ()->get ('drupal.service_parameters ' );
347
- $ services_options_file = $ options ['service-parameters ' ];
348
- $ services_source_file = empty ($ services_options_file )? $ services_runner_file : $ services_options_file ;
349
-
350
- if (!file_exists ($ services_source_file )) {
351
- throw new \Exception (sprintf ('Services file %s not found. ' , $ services_source_file ));
352
- }
340
+ // Read given parameters.
341
+ $ service_parameters ['parameters ' ] = $ this ->getConfig ()->get ('drupal.service_parameters ' );
342
+ $ yaml = Yaml::dump ($ service_parameters );
353
343
344
+ // Set the destination file.
354
345
$ services_destination_file = $ options ['root ' ] . '/sites/ ' . $ options ['sites-subdir ' ] . '/services.yml ' ;
355
346
356
- $ collection = [$ this ->taskFilesystemStack ()->copy ($ services_source_file , $ services_destination_file , (bool ) $ options ['force ' ])];
347
+ $ collection = [];
348
+ if (true === (bool ) $ options ['force ' ] || !file_exists ($ services_destination_file )) {
349
+ $ collection [] = $ this ->taskWriteToFile ($ services_destination_file )->append (false )->text ($ yaml );
350
+ }
357
351
358
352
return $ this ->collectionBuilder ()->addTaskList ($ collection );
359
353
}
0 commit comments