Problem/Motivation

The core installer in D8 appends the database configuration at the end of the settings.php file, instead of after the $databases structure is documented, currently around line 220. For a person new to setting up Drupal this makes managing the settings file more confusing than it needs to be. For example, the documentation around the $databases variable is near the top of the file whereas the variable is added at the end.

Note: D7 and older used to work that way, so this is a regression.

Steps to reproduce

Run the site installer with a codebase that does not have an existing settings.php file present.

Proposed resolution

Change drupal_rewrite_settings() so that it replaces variables that already exist in the file rather than appending them.

Remaining tasks

Work out a fix to drupal_rewrite_settings() that replaces variables which already exist in the file.
Add test coverage.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

TBD

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

In which sense is that a problem? Isn't the end the place where you actually have a easy time to look it up?

DamienMcKenna’s picture

The config file is broken up into several sections, each section devoted to specific things with oodles of comments. Why would the code not be inserted where the corresponding comments are? It seems like the legacy code was replaced with simple file concatenation rather than going through the effort of inserting the values where they should actually be.

DamienMcKenna’s picture

In short, in D7 and older the file made sense, you could scan through the file and see the appropriate configuration details. In D8 this is no longer possible because all of the customized details are dumped at the end. We don't need justification of why it is the way it is, or defense of why people should be able to deal with it, it's a bad DX we just need to fix it.

dawehner’s picture

I totally understand the point from where you are coming from.

Honestly though, I really enjoy having all actual configuration though in one place, as I hate to remember those line numbers to look things up :)

Just a pointer, core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php:158 is writing out this settings using drupal_rewrite_settings(),
so we might want to fix that one.

DamienMcKenna’s picture

Thanks for the pointer, I'll try to dig into it soon.

justindodge’s picture

Since there's some question about the validity of this as an issue, here is a use-case where it causes a problem:

In our setup, one of the local overrides to the settings file is the database connection information itself, which on our development server is derived programmatically based on the location of the installation.

When Drupal rewrites the settings file and appends this information to the bottom of the file, it overrides any database configuration that you are already overriding in a local settings include because the new database variable is appended below the include (note - I'm not actually using the convention of settings.local.php, but a different file name in a common php include location - but I don't think drupal_rewrite_settings takes this into account anyway).

In D8 this type of local override is actually documented in the settings.php file itself rather than just being inferred by common convention like in D7 and prior, so it seems fair to call this a bug to me because the 'appendage' will potentially break the documented behavior.

frob’s picture

Title: Databases configuration in settings.php should be inserted at the top of the file, per D7 » drupal_rewrite_settings doesn't work as documented
Version: 8.0.x-dev » 8.2.x-dev
Issue tags: +Regression
Related issues: +#2614456: Conditional local settings are no longer at the bottom of settings.php, making them near useless.

This issue should probably be around this function being flat out broken. There is lots of logic that is supposed to make this not happen. I do not know why it doesn't work, but this function is supposed to add the settings inline, replacing their previous placement.

I am updating the title to reflect this.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xumepadismal’s picture

Okay, that's a first try. $databases and $config_directories should be OK, but it lacks some logic/tests for those $settings and globals, commented out in default.settings.php. I guess that $settings['install_profile'] still in the end of the file...

Status: Needs review » Needs work

The last submitted patch, 11: drupal_rewrite_settings_in_place-2466799-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

xumepadismal’s picture

Status: Needs work » Needs review
FileSize
4.13 KB

Status: Needs review » Needs work

The last submitted patch, 13: drupal_rewrite_settings_in_place-2466799-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

DamienMcKenna’s picture

Title: drupal_rewrite_settings doesn't work as documented » drupal_rewrite_settings should replace existing variables in settings.php, not just append
Issue summary: View changes

I updated the issue title and summary per suggestion from lendude.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.