Allow update.php to regenerate settings.php

catch - September 4, 2008 - 21:47
Project:Drupal
Version:7.x-dev
Component:update system
Category:task
Priority:critical
Assigned:Unassigned
Status:closed
Issue tags:Release blocker
Description

Drupal 6 will be the first release where some admins will never have seen settings.php, ever. So asking them to edit it when they upgrade might come as a shock.

For those who've never touched their settings.php, I suggest we allow update.php to write a new file (exactly the same as the installer), then run update.php after that.

#1

webchick - September 5, 2008 - 00:17
Priority:normal» critical

I agree, and this is release-critical.

#2

Freso - October 8, 2008 - 10:43

And then there are those of us who have added a good deal of stuff into their settings.php, so it shouldn't (blindly) overwrite a custom settings.php.

#3

dmitrig01 - October 24, 2008 - 03:40

what about a settings-7.php for Durpal 7 settings, then it knows to look for that in conf_path. settings-8.php for Drupal 8 settings, etc.

#4

chx - October 26, 2008 - 16:30
Status:active» needs review

I think Dmitri's solution might just work. First, untested attempt attached.

AttachmentSizeStatusTest resultOperations
update_d6_d7.patch9.71 KBIdleFailed: Failed to apply patch.View details

#5

chx - October 26, 2008 - 16:32

Wrong patch, sry!

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch8.88 KBIdleFailed: Failed to apply patch.View details

#6

chx - October 26, 2008 - 19:12

Well, this is actually a lot simpler than we make it.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.03 KBIdleFailed: Failed to apply patch.View details

#7

chx - October 26, 2008 - 19:23

I need to make global $db_url 'cos we load settings.php in bootstrap.inc and you cant load it ever again cos if someone added a function to there then the reward for our efforts would be a nice fatal error.

#8

chx - October 26, 2008 - 19:28

Damien points out that even if settings.php wont be rewritten I still enforce its writeability. Fixed.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.25 KBIdleFailed: Failed to apply patch.View details

#9

chx - November 1, 2008 - 05:00

Reroll against HEAD. I have moved again the install_check_requirements from install.php to install.inc and applied mine change so I am not rolling back whatever change that function had.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch12.22 KBIdleFailed: Failed to apply patch.View details

#10

chx - November 13, 2008 - 06:33

With less debug and against HEAD.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.01 KBIdleFailed: Failed to apply patch.View details

#11

System Message - November 16, 2008 - 22:05
Status:needs review» needs work

The last submitted patch failed testing.

#12

webchick - November 17, 2008 - 07:01
Status:needs work» needs review

Re-submitting for testing after snafu this weekend.

#13

webchick - November 23, 2008 - 16:55
Title:Allow update.php to regenerate settings.php» UNSTABLE-4 Blocker: Allow update.php to regenerate settings.php

Ok. Now that some bigger fish are in (DST, SQLite, etc.) I'm adding this to the list of UNSTABLE-4 blockers. I would like to get UNSTABLE-4 rolled the first week of December, and this patch is critical to making upgrades work for mere mortals.

#14

System Message - January 21, 2009 - 00:55
Status:needs review» needs work

The last submitted patch failed testing.

#15

chx - February 8, 2009 - 17:32
Status:needs work» needs review

Note to anyone rerolling this patch in the future: should the install.php hunk fail, just move-paste the function to install.inc and change the first line to $requirements = $profile ? drupal_check_profile($profile) : array();.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.2 KBIdleFailed: Failed to apply patch.View details

#16

catch - February 9, 2009 - 11:49

tried this but ran into some issues. chx couldn't reproduce - so posting my results here in the hope that a third person can test it and confirm either way:
[error] [client 127.0.0.1] PHP Fatal error: Call to undefined function drupal_set_session() in /home/catch/www/7/includes/bootstrap.inc on line 983
[Sun Feb 08 18:34:46 2009] [error] [client 127.0.0.1] PHP Stack trace:
[Sun Feb 08 18:34:46 2009] [error] [client 127.0.0.1] PHP 1. {main}() /home/catch/www/7/update.php:0
[Sun Feb 08 18:34:46 2009] [error] [client 127.0.0.1] PHP 2. update_check_requirements() /home/catch/www/7/update.php:705
[Sun Feb 08 18:34:46 2009] [error] [client 127.0.0.1] PHP 3. drupal_set_message() /home/catch/www/7/update.php:651

Then:
chx: I added include_once session.inc to the top of update.php
chx: now I get:
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP Fatal error: session_start(): Failed to initialize storage module: user (path: /var/lib/php5) in /home/catch/www/7/includes/session.inc on line 175
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP Stack trace:
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP 1. {main}() /home/catch/www/7/update.php:0
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP 2. update_check_requirements() /home/catch/www/7/update.php:708
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP 3. drupal_set_message() /home/catch/www/7/update.php:654
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP 4. drupal_set_session() /home/catch/www/7/includes/bootstrap.inc:983
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP 5. drupal_session_start() /home/catch/www/7/includes/session.inc:222
[Sun Feb 08 18:59:25 2009] [error] [client 127.0.0.1] PHP 6. session_start() /home/catch/www/7/includes/session.inc:175

I also found an interesting side-effect - if you've got an already installed Drupal 7 site, wipe the settings.php and replace it with an empty one, you can go to install.php, eventually get redirected to update.php and regenerate your settings without having to go in and recreate the settings manually. This was unintended according to chx, but doesn't do any harm I think.

#17

chx - February 9, 2009 - 20:55

catch, the thing is -- you cant have a session early on because the DB is not there! So .. wtf?

#18

David_Rothstein - February 21, 2009 - 22:25

Rewriting settings.php seems like a good approach here. Note that while discussing a different (not as good) approach to this problem at http://drupal.org/node/303889#comment-1078298 I wrote a function which parsed and rewrote the old $db_url string that I think was more robust than the code currently here.

I don't have time to roll it into the patch right now, but I'm pasting the function here for reference. I'm wondering if the mysql vs mysqli thing could have something to do with the problem @catch experienced above?

<?php
/**
* Parse database connection URLs (in the old, pre-Drupal 7 format) and
* return them as an array of database connection information.
*/
function _db_parse_url($db_url) {
 
$databases = array();
  if (!
is_array($db_url)) {
   
$db_url = array('default' => $db_url);
  }
  foreach (
$db_url as $database => $url) {
   
$url = parse_url($url);
   
$databases[$database]['default'] = array(
     
// MySQLi uses the mysql driver.
     
'driver' => $url['scheme'] == 'mysqli' ? 'mysql' : $url['scheme'],
     
// Remove the leading slash to get the database name.
     
'database' => substr(urldecode($url['path']), 1),
     
'username' => urldecode($url['user']),
     
'password' => isset($url['pass']) ? urldecode($url['pass']) : '',
     
'host' => urldecode($url['host']),
     
'port' => isset($url['port']) ? urldecode($url['port']) : '',
    );
  }
  return
$databases;
}
?>

#19

chx - February 27, 2009 - 13:29

David, extremely nice catch about mysqli. The rest is not really different from my code, I think.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.28 KBIdleFailed: Failed to apply patch.View details

#20

webchick - February 28, 2009 - 04:15
Title:UNSTABLE-4 Blocker: Allow update.php to regenerate settings.php» Allow update.php to regenerate settings.php

#21

chx - March 1, 2009 - 06:39
AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.33 KBIdleFailed: Failed to apply patch.View details

#22

webchick - March 1, 2009 - 07:11
Status:needs review» needs work

Testing method:
1. Downloaded and set up a local webchick.net (D6) site.
2. Visit http://localhost/webchick.net, verified it was working.
3. cvs up -dPC -r HEAD
4. Visit http://localhost/webchick.net again.

Before patch:

Redirect to install.php, where I get:

<!--[if lt IE 7]> Fatal error: Call to undefined function garland_get_ie_styles() in /Users/webchick/Sites/webchick.net/themes/garland/maintenance-page.tpl.php on line 24 Call Stack: 0.0039 380132 1. {main}() /Users/webchick/Sites/webchick.net/install.php:0 0.0069 606676 2. install_main() /Users/webchick/Sites/webchick.net/install.php:1183 0.1734 5689604 3. install_select_profile() /Users/webchick/Sites/webchick.net/install.php:98 0.1854 6264948 4. theme() /Users/webchick/Sites/webchick.net/install.php:434 0.1855 6268308 5. call_user_func_array() /Users/webchick/Sites/webchick.net/includes/theme.inc:628 0.1855 6268308 6. theme_install_page() /Users/webchick/Sites/webchick.net/includes/theme.inc:0 0.1863 6275648 7. theme_render_template() /Users/webchick/Sites/webchick.net/includes/theme.maintenance.inc:149 0.1867 6337392 8. include('/Users/webchick/Sites/webchick.net/themes/garland/maintenance-page.tpl.php') /Users/webchick/Sites/webchick.net/includes/theme.inc:1016

After patch:
Same thing. ;(

#23

chx - March 1, 2009 - 07:31
Status:needs work» needs review

Grrr! The sessions patch broke this nicely as drupal_set_message calls drupal_set_session... which wont fly really as session.inc is not even loaded.

AttachmentSizeStatusTest resultOperations
settings_d6_d7.patch9.68 KBIdleFailed: Failed to apply patch.View details

#24

webchick - March 1, 2009 - 08:10
Status:needs review» needs work

After some futzing around, I figured out the reason I was getting that error was because I had a hacked version of Garland sitting in sites/all/themes. Once I removed that things started working much better. :)

update.php now completes, however I get Fatal error: Call to undefined function field_attach_load() in /Users/webchick/Sites/webchick.net/modules/node/node.module on line 917

#25

chx - March 1, 2009 - 08:13
Status:needs work» needs review
AttachmentSizeStatusTest resultOperations
settings_d6_d7_is_getting_long_in_the_tooth.patch10.25 KBIdleFailed: Failed to apply patch.View details

#26

webchick - March 1, 2009 - 09:33
Status:needs review» fixed

Tested this with webchick.net, and as long as I switch to Garland first, this latest patch updates without incident. I'm sure there are many many more edge cases we'll run across, but this fixes the main issue. Committed to HEAD with small doxygen improvement. Thanks so much! :D

#27

David_Rothstein - March 3, 2009 - 04:11

It's definitely good this went in, but trying out the new version I found several problems and wrote a patch to fix them. Here are the issues I found:

  1. When visiting update.php with a settings.php file that is not yet writable, the error message you get looks like this:

    This makes reference to the install process and has some other weird things too (e.g., the parenthetical remark at the end). Also, if you click on the Continue button, it redirects you to install.php instead. Overall, since the message we're sending here is different from install.php, maybe it's actually best not to try reusing that code here.
  2. Regarding this:
    -    if (!isset($_SESSION['messages'])) {
    +    if (!isset($_SESSION['messages']) && function_exists('drupal_set_session')) {

    I'm not sure that putting that special-case code into drupal_set_message() just to deal with the update.php situation is a good idea. I think update.php should deal with the special cases itself.
  3. I think we do need to use the function from #18 (above) for parsing the URL, because the other thing that function allowed was the possibility that $db_url is an array containing more than one database. Since D6 allows this, I think we should support that conversion in the upgrade path too.
AttachmentSizeStatusTest resultOperations
update_requirements_old.png39.35 KBIgnoredNoneNone

#28

David_Rothstein - March 3, 2009 - 04:14
Status:fixed» needs review

Here is the patch that fixes the above issues. Mostly, it moves the install_check_requirements() function back to install.php, and then implements a separate, cleaner check in update.php itself that is optimized for the update.php situation.

AttachmentSizeStatusTest resultOperations
update_settings_php_cleanup.patch19.21 KBIdleUnable to apply patch update_settings_php_cleanup.patchView details

#29

David_Rothstein - March 3, 2009 - 04:17

Also, here's a screenshot showing what the update.php requirements check looks like with the new patch.

We might want to tweak some things and perhaps move the order of operations around a bit (so that this information isn't exposed until after the access check is performed), but overall, this should be good because it makes the requirements checking look similar to the way it is done in install.php as well as on the Status Report page.

AttachmentSizeStatusTest resultOperations
update_requirements_new.png68.4 KBIgnoredNoneNone

#30

Bojhan - April 11, 2009 - 22:18

So does this patch, at that verify requirements page to the update process? Or did I always just miss that.

#31

Dries - April 12, 2009 - 20:36

I reviewed this patch and it looks good. I haven't tested it yet. I'll commit it after a test -- either by myself or someone else. Thanks!

#32

David_Rothstein - May 4, 2009 - 03:25

Well, no one else tested it, so I went and tested my own patch again - and it still works :)

However, as I hinted at in #29, I do think it's important to make sure we don't show this page until the access check has been performed (otherwise we are printing tons of new information about the server for anyone who comes along to see). This is fixed in the attached patch - which has also been tested by me and appears to work fine...

@Bojhan: Yes, the screenshot shown in #29 is added by this patch. Before, the checks were performed, but errors were printed to the screen as shown in the screenshot from #27. So basically I'm switching it to use the same style used elsewhere in Drupal (e.g., install.php and the status reports page), which hopefully should be a good thing!

AttachmentSizeStatusTest resultOperations
update_settings_php_cleanup_2.patch19.91 KBIdleUnable to apply patch update_settings_php_cleanup_2.patchView details

#33

catch - May 4, 2009 - 08:59
Status:needs review» needs work

Until #278592: Sync 6.x extra updates with HEAD is in I don't see how we can remove update_fix_d6_requirements()

#34

David_Rothstein - May 5, 2009 - 03:36
Status:needs work» needs review

Well, it's not like direct Drupal 5 => Drupal 7 updates are working now anyway :) But as long as there's a separate issue to track it, I agree there's no reason to remove it here.

New patch attached.

AttachmentSizeStatusTest resultOperations
update_settings_php_cleanup_3.patch16.75 KBIdlePassed: 11225 passes, 0 fails, 0 exceptionsView details

#35

chx - May 9, 2009 - 17:08
Status:needs review» reviewed & tested by the community

Sure. My goal was to let an update happen. Making it pretty, that's another thing :) thanks.

#36

Dries - May 9, 2009 - 18:35
Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks!

#37

System Message - May 23, 2009 - 18:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.