Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENEUROPA-1697: Add drupal.site.generate_db_url parameter #99

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ root = true
[*]
end_of_line = LF
indent_style = space
indent_size = 2
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[composer.{json,lock}]
indent_size = 4

[*.yml]
indent_size = 2
3 changes: 3 additions & 0 deletions config/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ drupal:
config_dir: ~
existing_config: false
settings_override_file: "settings.override.php"
# Setting this to "false" will run "site-install" without the "--db-url" parameter.
# This is useful if the database settings are already set in your settings.php file.
generate_db_url: true

# Administrator account information.
account:
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public function siteInstall(array $options = [
->sitesSubdir($options['sites-subdir'])
->siteProfile($options['site-profile']);

$task->setGenerateDbUrl($this->getConfig()->get('drupal.site.generate_db_url'));

if (!empty($options['existing-config'])) {
$task->setExistingConfig($options['existing-config']);
}
Expand Down
38 changes: 27 additions & 11 deletions src/Tasks/Drush/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Drush extends Exec
protected $databaseName = '';
protected $sitesSubdir = '';
protected $existingConfig = false;
protected $generateDbUrl = true;

/**
* Build Drush site install command.
Expand All @@ -38,16 +39,6 @@ class Drush extends Exec
*/
public function siteInstall()
{
$dbArray = [
'scheme' => $this->databaseScheme,
'user' => $this->databaseUser,
'pass' => $this->databasePassword,
'host' => $this->databaseHost,
'port' => $this->databasePort,
'path' => $this->databaseName,
];
$dbUrl = http_build_url($dbArray, $dbArray);

$this->option('-y')
->rawArg("--root=$(pwd)/".$this->root)
->options([
Expand All @@ -58,9 +49,22 @@ public function siteInstall()
'account-name' => $this->accountName,
'account-pass' => $this->accountPassword,
'sites-subdir' => $this->sitesSubdir,
'db-url' => $dbUrl,
], '=');

if ($this->generateDbUrl) {
$dbArray = [
'scheme' => $this->databaseScheme,
'user' => $this->databaseUser,
'pass' => $this->databasePassword,
'host' => $this->databaseHost,
'port' => $this->databasePort,
'path' => $this->databaseName,
];
$dbUrl = http_build_url($dbArray, $dbArray);

$this->option('db-url', $dbUrl, '=');
}

if (!empty($this->existingConfig)) {
$this->option('existing-config');
}
Expand Down Expand Up @@ -271,4 +275,16 @@ public function setExistingConfig($existingConfig)

return $this;
}

/**
* @param bool $generateDbUrl
*
* @return Drush
*/
public function setGenerateDbUrl($generateDbUrl)
{
$this->generateDbUrl = $generateDbUrl;

return $this;
}
}
10 changes: 10 additions & 0 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,13 @@
- "./vendor/bin/drush -y"
not_contains:
- "--existing-config"

- command: "drupal:site-install"
configuration:
drupal:
site:
generate_db_url: false
composer: ''
contains: []
not_contains:
- "--db-url='mysql://127.0.0.1:3306'"