Skip to content

Commit

Permalink
Merge pull request #102 from openeuropa/OPENEUROPA-2030
Browse files Browse the repository at this point in the history
OPENEUROPA-2030: Allow to pass Drupal root as a token to pre and post commands
  • Loading branch information
ademarco authored Jun 27, 2019
2 parents b323586 + e1376e7 commit 333cb1a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
43 changes: 39 additions & 4 deletions src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}
}
18 changes: 18 additions & 0 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 333cb1a

Please sign in to comment.