drupal_rewrite_settings is an abomination on god-fearing configuration formats. That being said, it would be a little less heinous and reusable if it would at least return the contents of its evil-regex-doing instead of writing to conf_path() . '/settings.php';

Very minor change, but understood if it doesn't make it in.

Comments

JacobSingh’s picture

Status: Active » Needs review
StatusFileSize
new2.58 KB

whoops, wrong patch.

JacobSingh’s picture

StatusFileSize
new2.62 KB

Sorry, it's really late. Oddly, there was an undocumented argument to the function which wasn't used in any callsites ($prefix) removed it.

David_Rothstein’s picture

Status: Needs review » Needs work

I think it makes sense to split them up, but a function called "drupal_rewrite_settings" really sounds like it should actually rewrite the settings file. How about making a separate helper function that does this? Then you get the best of both worlds: A reusable function, but no changes to the existing behavior of drupal_rewrite_settings().

Maybe drupal_get_updated_settings_file_content(), or something shorter? :)

effulgentsia’s picture

Title: drupal_rewrite_settings should be decoupled from writing to settings.php (i.e. should just do the string munging) » Make it possible to re-use the internal logic of drupal_rewrite_settings() in other installation processes
Status: Needs work » Needs review
StatusFileSize
new2.81 KB

Yeah, consider scenarios like aegir or any other kind of Drupal provisioning system, where the provisioning site wants to re-use the functionality of generating a settings.php file, but without overwriting the settings.php file of the provisioning site itself. But I agree with #3 that we don't want to change the API of drupal_rewrite_settings() at this stage of D7. So here's a pretty minimal patch to achieve the goal without any API change.

Status: Needs review » Needs work

The last submitted patch, drupal_rewrite_settings-852352-4.patch, failed testing.

effulgentsia’s picture

StatusFileSize
new2.92 KB
effulgentsia’s picture

Status: Needs work » Needs review
gábor hojtsy’s picture

StatusFileSize
new2.97 KB

Patch looks good. Here it is rerolled with phpdoc wrapping changes.

damien tournoud’s picture

Thanks for using file_put_contents() here, while we are at it.

JacobSingh’s picture

Status: Needs review » Reviewed & tested by the community

why aren't you using file_put_contents here?

$fp = fopen(DRUPAL_ROOT . '/' . $settings_file, 'w');
+  if ($fp && fwrite($fp, $buffer) === FALSE) {
+    throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
+  }

If there is a good reason to use the more verbose fwrite() that I don't see, RTBC. Otherwise, use file_put_contents(). no big deal either way though.

-J

dries’s picture

Status: Reviewed & tested by the community » Needs work

I guess that means it is 'needs work'.

David_Rothstein’s picture

Status: Needs work » Needs review
David_Rothstein’s picture

Probably getting a little late for this issue in D7 (given that it is marked a feature request).

However, the patch looks fine as is. Switching to file_put_contents() would be a separate issue - all this patch does is move the code around; it is not a requirement for it to try to improve the existing code at the same time as it's moving it :)

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community
If there is a good reason to use the more verbose fwrite() that I don't see, RTBC.

The good reason is that's how it is in HEAD, so as per #13, out of scope for this issue. Therefore, back to RTBC.

dries’s picture

Status: Reviewed & tested by the community » Needs work

The function names don't seem 100% consistent and self-explanatory. For example, the new function has '_file' in its name but doesn't actually write to a file.

I also recommend that we document the use case for this so people better understand why these are separate functions.

Needs a bit more work, IMO.

ksenzee’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.88 KB

I reviewed the function names and the best I could come up with is drupal_generate_settings_file_content(). A bit verbose, but it clarifies what the function does, and I think even manages to make it clear why we're separating the two. Generating content and writing that content to a file are two separate jobs.

This patch is a reroll that simply changes the function name (and adds a couple hyphens in the phpdoc). I think it's reasonable for backport to D7, but I'm moving it to D8 first.

nagba’s picture

Version: 8.x-dev » 7.x-dev
StatusFileSize
new2.88 KB

rerolling the patch for Drupal 7.18

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev

Needs to go into Drupal 8 first.

David_Rothstein’s picture

Issue tags: +Needs backport to D7

Tagging for possible backport, though...

David_Rothstein’s picture

pwolanin’s picture

Issue summary: View changes
Issue tags: +Needs backport to D7

looks like the tag got eaten

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
ankitgarg’s picture

Status: Needs work » Needs review
StatusFileSize
new594 bytes

New Changes are already applied to files. Can be close.

jhedstrom’s picture

Status: Needs review » Needs work

Patch in #23 only contains some comment changes.

piyuesh23’s picture

Issue tags: +#DCM2015
ayesh’s picture

Assigned: Unassigned » ayesh

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.

vijaycs85’s picture

Assigned: ayesh » Unassigned
pk188’s picture

Issue tags: -Needs reroll

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for sharing your idea for improving Drupal.

We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.