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

EWPP-1165: Add support for update-related parameters in site install command. #153

Open
wants to merge 12 commits into
base: 2.x
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"consolidation/robo": "^4.0",
"gitonomy/gitlib": "^1.0",
"jakeasmith/http_build_url": "^1.0.1",
"nuvoleweb/robo-config": "^3.0.0"
"nuvoleweb/robo-config": "^3.0.0",
"grasmash/expander": ">=3"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoudln't we just ^3?

},
"require-dev": {
"openeuropa/code-review": "2.x-dev",
Expand Down
2 changes: 2 additions & 0 deletions config/commands/drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ command:
# @deprecated
# Should only be used with Drupal 8.5 and lower. Use "existing-config".
config-dir: ${drupal.site.config_dir}
enable-update-status-module: ${drupal.install.update_status_module}
enable-update-status-emails: ${drupal.install.update_status_emails}
drush-setup:
options:
config-dir: ${drupal.root}/drush
Expand Down
5 changes: 5 additions & 0 deletions config/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ drupal:
# 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
install:
# Setting this to "false" will tell the "site-install" command to not enable the update status module.
update_status_module: true
# Setting this to "false" will tell the "site-install" command to disable email notifications about updates.
update_status_emails: true

# Administrator account information.
account:
Expand Down
52 changes: 31 additions & 21 deletions src/Commands/AbstractDrupalCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,28 @@ public function validateSiteInstall(CommandData $commandData)
*
* @command drupal:site-install
*
* @option root Drupal root.
* @option site-name Site name.
* @option site-mail Site mail.
* @option site-profile Installation profile
* @option site-update Whereas to enable the update module or not.
* @option site-locale Default site locale.
* @option account-name Admin account name.
* @option account-password Admin account password.
* @option account-mail Admin email.
* @option database-type Deprecated, use "database-scheme"
* @option database-scheme Database scheme.
* @option database-host Database host.
* @option database-port Database port.
* @option database-name Database name.
* @option database-user Database username.
* @option database-password Database password.
* @option sites-subdir Sites sub-directory.
* @option config-dir Deprecated, use "existing-config" for Drupal 8.6 and higher.
* @option existing-config Whether existing config should be imported during installation.
* @option skip-permissions-setup Whether to skip making the settings file and folder writable during installation.
* @option root Drupal root.
* @option site-name Site name.
* @option site-mail Site mail.
* @option site-profile Installation profile
* @option site-update Whereas to enable the update module or not.
* @option site-locale Default site locale.
* @option account-name Admin account name.
* @option account-password Admin account password.
* @option account-mail Admin email.
* @option database-type Deprecated, use "database-scheme"
* @option database-scheme Database scheme.
* @option database-host Database host.
* @option database-port Database port.
* @option database-name Database name.
* @option database-user Database username.
* @option database-password Database password.
* @option sites-subdir Sites sub-directory.
* @option config-dir Deprecated, use "existing-config" for Drupal 8.6 and higher.
* @option existing-config Whether existing config should be imported during installation.
* @option skip-permissions-setup Whether to skip making the settings file and folder writable during installation.
* @option enable-update-status-module Check for updates automatically.
* @option enable-update-status-emails Receive email notifications regarding updates.
*
* @aliases drupal:si,dsi
*
Expand Down Expand Up @@ -162,6 +164,8 @@ public function siteInstall(array $options = [
'config-dir' => InputOption::VALUE_REQUIRED,
'existing-config' => false,
'skip-permissions-setup' => false,
'enable-update-status-module' => true,
'enable-update-status-emails' => true,
])
{
if ($options['database-type']) {
Expand All @@ -174,6 +178,10 @@ public function siteInstall(array $options = [
$options['existing-config'] = true;
}

// Pass value as boolean type only.
$options['enable-update-status-module'] = filter_var($options['enable-update-status-module'], FILTER_VALIDATE_BOOLEAN);
$options['enable-update-status-emails'] = filter_var($options['enable-update-status-emails'], FILTER_VALIDATE_BOOLEAN);

$drush = $this->getConfig()->get('runner.bin_dir') . '/drush';
$task = $this->taskDrush($drush)
->root($options['root'])
Expand All @@ -190,7 +198,9 @@ public function siteInstall(array $options = [
->databasePort($options['database-port'])
->databaseName($options['database-name'])
->sitesSubdir($options['sites-subdir'])
->siteProfile($options['site-profile']);
->siteProfile($options['site-profile'])
->enableUpdateStatusModuleOnInstall($options['enable-update-status-module'])
->enableUpdateStatusEmailsOnInstall($options['enable-update-status-emails']);

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

Expand Down
32 changes: 31 additions & 1 deletion src/Tasks/Drush/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Drush extends Exec
protected $sitesSubdir = '';
protected $existingConfig = false;
protected $generateDbUrl = true;
protected $updateStatusModule = true;
protected $updateStatusEmails = true;

/**
* Build Drush site install command.
Expand Down Expand Up @@ -69,7 +71,11 @@ public function siteInstall()
$this->option('existing-config');
}

return $this->arg('site-install')->arg($this->siteProfile);
return $this->arg('site-install')
->arg($this->siteProfile)
// Adapt values for the installation configuration form parameters.
->rawArg('install_configure_form.enable_update_status_module=' . ($this->updateStatusModule ? 'true' : 'NULL'))
->rawArg('install_configure_form.enable_update_status_emails=' . ($this->updateStatusEmails ? 'true' : 'NULL'));
}

/**
Expand Down Expand Up @@ -287,4 +293,28 @@ public function setGenerateDbUrl($generateDbUrl)

return $this;
}

/**
* @param bool $enable
*
* @return Drush
*/
public function enableUpdateStatusModuleOnInstall($enable)
{
$this->updateStatusModule = $enable;

return $this;
}

/**
* @param bool $enable
*
* @return Drush
*/
public function enableUpdateStatusEmailsOnInstall($enable)
{
$this->updateStatusEmails = $enable;

return $this;
}
}
109 changes: 109 additions & 0 deletions tests/fixtures/simulation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
composer: ''
contains:
- "[Simulator] Running ./vendor/bin/drush -y --root=$(pwd)/build --site-name='Site name' [email protected] --locale=en [email protected] --account-name=admin --account-pass=admin --sites-subdir=default --db-url='mysql://root:[email protected]:3306/drupal' site-install standard"
- "site-install standard install_configure_form.enable_update_status_module=true install_configure_form.enable_update_status_emails=true"

- command: 'drupal:site-install --site-name="Test site"'
configuration:
Expand Down Expand Up @@ -374,3 +375,111 @@
composer: ''
contains:
- "./vendor/bin/drush --root=foo"

- command: 'drupal:site-install --enable-update-status-module=false --enable-update-status-emails=false'
configuration: {}
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL"

- command: 'drupal:site-install --enable-update-status-module= --enable-update-status-emails='
configuration: {}
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL"

- command: 'drupal:site-install --enable-update-status-module=true --enable-update-status-emails=true'
configuration: {}
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=true install_configure_form.enable_update_status_emails=true"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: false
update_status_emails: ~
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=true"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: 'false'
update_status_emails: ''
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: "false"
update_status_emails: ""
imanoleguskiza marked this conversation as resolved.
Show resolved Hide resolved
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: true
update_status_emails: ~
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=true install_configure_form.enable_update_status_emails=true"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: 'true'
update_status_emails: ''
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=true install_configure_form.enable_update_status_emails=NULL"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: "true"
update_status_emails: ""
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=true install_configure_form.enable_update_status_emails=NULL"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: ~
update_status_emails: true
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=true install_configure_form.enable_update_status_emails=true"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: ''
update_status_emails: 'true'
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=true"

- command: 'drupal:site-install'
configuration:
drupal:
install:
update_status_module: ""
update_status_emails: "true"
composer: ''
contains:
- "standard install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=true"