diff --git a/composer.json b/composer.json index 246db242..d3094f1c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "jakeasmith/http_build_url": "^1.0.1" }, "require-dev": { - "openeuropa/code-review": "~1.0@beta", + "openeuropa/code-review": "~1.0.0-beta3", "phpunit/phpunit": "~5.5||~6.0" }, "autoload": { diff --git a/src/Commands/AbstractDrupalCommands.php b/src/Commands/AbstractDrupalCommands.php index e74e4f30..28e1592d 100644 --- a/src/Commands/AbstractDrupalCommands.php +++ b/src/Commands/AbstractDrupalCommands.php @@ -194,13 +194,13 @@ public function siteInstall(array $options = [ // Define collection of tasks. $collection = [ - $this->sitePreInstall(), + $this->sitePreInstall($options), ]; if (!$options['skip-permissions-setup']) { $collection[] = $this->permissionsSetup($options); } $collection[] = $task->siteInstall(); - $collection[] = $this->sitePostInstall(); + $collection[] = $this->sitePostInstall($options); return $this->collectionBuilder()->addTaskList($collection); } @@ -222,11 +222,20 @@ public function siteInstall(array $options = [ * * @command drupal:site-post-install * + * @option root + * The Drupal root. All occurrences of "!root" in the post-install + * string-only commands will be substituted with this value. + * * @return \Robo\Contract\TaskInterface */ - public function sitePostInstall() + public function sitePostInstall(array $options = [ + 'root' => InputOption::VALUE_REQUIRED, + ]) { $tasks = $this->getConfig()->get('drupal.post_install', []); + $this->processPrePostInstallCommands($tasks, [ + '!root' => $options['root'], + ]); return $this->taskCollectionFactory($tasks); } @@ -248,11 +257,20 @@ public function sitePostInstall() * * @command drupal:site-pre-install * + * @option root + * The Drupal root. All occurrences of "!root" in the pre-install + * string-only commands will be substituted with this value. + * * @return \Robo\Contract\TaskInterface */ - public function sitePreInstall() + public function sitePreInstall(array $options = [ + 'root' => InputOption::VALUE_REQUIRED, + ]) { $tasks = $this->getConfig()->get('drupal.pre_install', []); + $this->processPrePostInstallCommands($tasks, [ + '!root' => $options['root'], + ]); return $this->taskCollectionFactory($tasks); } @@ -402,4 +420,21 @@ public function permissionsSetup(array $options = [ return $this->collectionBuilder()->addTaskList($collection); } + + /** + * Process pre and post install string-only commands by replacing given tokens. + * + * @param array $commands + * List of commands. + * @param array $tokens + * Replacement key-value tokens. + */ + protected function processPrePostInstallCommands(array &$commands, array $tokens) + { + foreach ($commands as $key => $value) { + if (is_string($value)) { + $commands[$key] = str_replace(array_keys($tokens), array_values($tokens), $value); + } + } + } } diff --git a/tests/fixtures/simulation.yml b/tests/fixtures/simulation.yml index 434203e8..0d60fb4a 100644 --- a/tests/fixtures/simulation.yml +++ b/tests/fixtures/simulation.yml @@ -356,3 +356,21 @@ contains: [] not_contains: - "--db-url='mysql://127.0.0.1:3306'" + +- command: 'drupal:site-install --root=foo' + configuration: + drupal: + post_install: + - "./vendor/bin/drush --root=!root" + composer: '' + contains: + - "./vendor/bin/drush --root=foo" + +- command: 'drupal:site-install --root=foo' + configuration: + drupal: + pre_install: + - "./vendor/bin/drush --root=!root" + composer: '' + contains: + - "./vendor/bin/drush --root=foo"