-
Notifications
You must be signed in to change notification settings - Fork 11
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-1149: Provide alternative method to override settings in settings.php #82
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good start and nice alternative approach @sergepavle ! I've left some comments and we need to fix / add tests.
src/Commands/DrupalCommands.php
Outdated
@@ -282,8 +282,20 @@ public function settingsSetup(array $options = [ | |||
'root' => InputOption::VALUE_REQUIRED, | |||
]) | |||
{ | |||
$settings_file = $options['root'].'/sites/default/settings.php'; | |||
$settings_local_file = $options['root'] . '/sites/default/' . $this->getConfig()->get('drupal.settings_local_file'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The site path /sites/default/
is actually configurable, we should get it from the runner configuration.
config/runner.yml
Outdated
@@ -22,6 +22,7 @@ drupal: | |||
root: "build" | |||
root_absolute: ~ | |||
base_url: "http://127.0.0.1:8888" | |||
settings_local_file: 'settings.local.php' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drupal core already uses settings.local.php
shall we maybe rename this as below?
settings_override_file: 'settings.override.php'
src/Commands/DrupalCommands.php
Outdated
return $this->collectionBuilder()->addTaskList([ | ||
$this->taskAppendConfiguration($options['root'].'/sites/default/default.settings.php', $this->getConfig())->setConfigKey('drupal.settings'), | ||
$this->taskFilesystemStack()->copy($options['root'] . '/sites/default/default.settings.php', $settings_file), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to set the third parameter $force
to TRUE
otherwise the runner will not override an already existing settings.php
.
4345413
to
b24f321
Compare
config/runner.yml
Outdated
@@ -22,6 +22,7 @@ drupal: | |||
root: "build" | |||
root_absolute: ~ | |||
base_url: "http://127.0.0.1:8888" | |||
settings_local_file: 'settings.override.php' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also pass this one as an overridable parameter to the command. We should also rename it in settings_override_file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
60ed986
to
05e26e2
Compare
src/Commands/DrupalCommands.php
Outdated
return $this->collectionBuilder()->addTaskList([ | ||
$this->taskAppendConfiguration($options['root'].'/sites/default/default.settings.php', $this->getConfig())->setConfigKey('drupal.settings'), | ||
$this->taskFilesystemStack()->copy($options['root'] . '/sites/default/default.settings.php', $settings_file, true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$options['sites-subdir']
should replace /default/
on these two lines above too.
src/Commands/DrupalCommands.php
Outdated
'<?php', | ||
'', | ||
]), | ||
$this->taskAppendConfiguration($settings_override_path, $this->getConfig())->setConfigKey('drupal.settings'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use taskWriteConfiguration
instead of taskAppendConfiguration
and you can remove the lines initializing the file above:
$this->taskWriteToFile($settings_override_path)->lines([
'<?php',
'',
]),
The taskWriteConfiguration
takes care of inserting a <?php\n
already.
src/Commands/DrupalCommands.php
Outdated
'if (file_exists($app_root . \'/\' . $site_path . \'/' . $settings_override_filename . '\')) {', | ||
' include $app_root . \'/\' . $site_path . \'/' . $settings_override_filename . '\';', | ||
'}' | ||
]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we wrap these strings in double quotes, so we don't have to escape and concatenate things? Something like the following is more readable:
$this->taskWriteToFile($settings_file)->append()->lines([
"if (file_exists(\$app_root . '/' . \$site_path . '/$settings_override_filename')) {",
" include \$app_root . '/' . \$site_path . '/$settings_override_filename';",
"}",
]),
@voidtek we also need to update the command comment:
|
src/Commands/DrupalCommands.php
Outdated
return $this->collectionBuilder()->addTaskList([ | ||
$this->taskAppendConfiguration($options['root'].'/sites/default/default.settings.php', $this->getConfig())->setConfigKey('drupal.settings'), | ||
$this->taskFilesystemStack()->copy($settings_default_path, $settings_path, true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the force
configurable (last parameter) by passing a parameter to the command (so no configuration value in this case), and let's default it to false, since if we force it here we wipe out the whole settings.php file which will force a full site reinstall in order to have it regenerated by Drupal.
8012f34
to
d371202
Compare
config/commands/drupal.yml
Outdated
@@ -31,4 +31,4 @@ command: | |||
options: | |||
sites-subdir: ${drupal.site.sites_subdir} | |||
settings-override-file: ${drupal.site.settings_override_file} | |||
force-override-file: ${drupal.site.force_override_file} | |||
force: ${drupal.site.force} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this here since the default value is set directly in the method function signature to false
.
src/Commands/DrupalCommands.php
Outdated
|
||
return $this->collectionBuilder()->addTaskList([ | ||
$this->taskFilesystemStack()->copy($settings_default_path, $settings_path, true), | ||
$this->taskFilesystemStack()->copy($settings_default_path, $settings_path, ($options['force'] === true) ? $options['force'] : false), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?
($options['force'] === true) ? $options['force'] : false
Isn't enough to use $options['force']
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed to (bool) $options['force'] .
63f4048
to
478abc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
0ff3482
to
8fab957
Compare
…s in default.settings.php file.
8fab957
to
fc56405
Compare
…additional option for settings-setup command.
fc56405
to
b9ddd27
Compare
e81cf3d
to
f0f9f5a
Compare
f0f9f5a
to
e636f9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
No description provided.