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-1149: Provide alternative method to override settings in settings.php #82

Merged
merged 26 commits into from
Oct 1, 2018

Conversation

sergepavle
Copy link
Member

@sergepavle sergepavle commented Sep 26, 2018

No description provided.

Copy link
Member

@ademarco ademarco left a 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.

@@ -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');
Copy link
Member

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.

@@ -22,6 +22,7 @@ drupal:
root: "build"
root_absolute: ~
base_url: "http://127.0.0.1:8888"
settings_local_file: 'settings.local.php'
Copy link
Member

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'

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),
Copy link
Member

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.

@sergepavle sergepavle force-pushed the OPENEUROPA-1149 branch 2 times, most recently from 4345413 to b24f321 Compare September 27, 2018 08:27
@@ -22,6 +22,7 @@ drupal:
root: "build"
root_absolute: ~
base_url: "http://127.0.0.1:8888"
settings_local_file: 'settings.override.php'
Copy link
Member

@ademarco ademarco Sep 27, 2018

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

Copy link
Member Author

Choose a reason for hiding this comment

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

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),
Copy link
Member

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.

'<?php',
'',
]),
$this->taskAppendConfiguration($settings_override_path, $this->getConfig())->setConfigKey('drupal.settings'),
Copy link
Member

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.

'if (file_exists($app_root . \'/\' . $site_path . \'/' . $settings_override_filename . '\')) {',
' include $app_root . \'/\' . $site_path . \'/' . $settings_override_filename . '\';',
'}'
]),
Copy link
Member

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';",
        "}",
    ]),

@ademarco
Copy link
Member

@voidtek we also need to update the command comment:

    /**
     * Setup default Drupal settings file.
     *
     * This command will append settings specified at "drupal.settings" to the
     * current site's "default.settings.php" which, in turn, will be used
     * to generate the actual "settings.php" at installation time.
     *

@ademarco ademarco changed the title OPENEUROPA-1149 implementing workaround for avoiding writing settings… OPENEUROPA-1149: Provide alternative method to override settings in settings.php Sep 28, 2018
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),
Copy link
Member

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.

@@ -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}
Copy link
Member

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.


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),
Copy link
Member

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']?

Copy link
Member

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'] .

@voidtek voidtek force-pushed the OPENEUROPA-1149 branch 2 times, most recently from 63f4048 to 478abc7 Compare October 1, 2018 09:48
voidtek
voidtek previously approved these changes Oct 1, 2018
Copy link
Member

@voidtek voidtek left a comment

Choose a reason for hiding this comment

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

👍

@drupol drupol force-pushed the OPENEUROPA-1149 branch 8 times, most recently from e81cf3d to f0f9f5a Compare October 1, 2018 14:19
Copy link
Member

@voidtek voidtek left a comment

Choose a reason for hiding this comment

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

👍

@voidtek voidtek merged commit 77372d2 into master Oct 1, 2018
@voidtek voidtek deleted the OPENEUROPA-1149 branch October 1, 2018 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants