Problem Motivation

The installer checks $readability and $writability of the settings file, defaults it to FALSE but only checks it in one of three cases. When the file already exists. So when the file is automatically created, there is a requirement file claiming that it can't be read. And when you refresh the page, then it works.

Steps to reproduce:
- Remove settings.php if you have it.
- Give the apache user write permission of the directory
- Start the installer.
- You get the settings.php can not be read error.
- Refresh page.
- Now it works.

Proposed resolution

See #5: set $readable and $writable again.

Remaining tasks

  • (done) patch test bot likes in #1 by Berdir
  • (done) manual testing in #2 by maryedith
  • (done) code review in #5, #6, and #7 by chx, David_Rothstein, sun
  • (done) code standards review ... agreed this is fine in #8, #9

User interface changes

none.

API changes

none.

CommentFileSizeAuthor
#1 settings-readable-check-1805324-1.patch1.32 KBBerdir
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Status: Active » Needs review
FileSize
1.32 KB

Attaching a patch. $writable actually currently checks both.

Alternatively, we could also remove the separte settings.php is not readable check and change the text of the other one.

maryedith’s picture

I started with a clean git of 8.x-dev. when I started the installation I observed the error. Verified that the bug still exists.

Found this issue, downloaded the patch from http://drupal.org/files/settings-readable-check-1805324-1.patch
Made a new branch , applied the patch in the new branch.
Deleted my setting.php in order to restart the install.
Went back to initial installation of this Drupal install,

The error did not occur. Proceded directly to the Database setup page rather than having the error.

This patch fixes the bug.

Next step is to get a code review.

znerol’s picture

Status: Needs review » Reviewed & tested by the community

Patch seems sane and fixes the problem.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

It would be great to get a couple of more reviews on this, from sun or chx for example.

chx’s picture

Status: Needs review » Reviewed & tested by the community

So what happens to $readable? It starts as FALSE and in current HEAD only gets flipped to TRUE if the dir and settings file both exist already. Otherwise we copy the default to settings.php and... forget to set $readable. There's some dance happening after the copying which is amply documented but anyways indeed you will get a readable error because we do not set $readable and when you reload then it'll be set because again, that's the only way it is -- when the file already exists. The patch is correct.

David_Rothstein’s picture

Didn't test it out, but reading the patch and surrounding code it makes sense to me also.

I was confused because I was quite sure based on previous experience that this bug didn't actually exist (for example, in Drupal 7), so I checked a bit and it turns out it was introduced relatively recently (and for Drupal 8 only) via #1542620: Fatal errors when file permissions for settings.php are messed up (can't read file)

sun’s picture

Yep, this is essentially the same fix as in #1798732: Convert install_task, install_time and install_current_batch to use the state system

That said, I studied what the called code is doing (which is anything but trivial) and concluded that the returned value can be assigned to both $readable and $writeable, as in:

$readable = $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);

However, we can also check them separately — doesn't make much of a difference.

Berdir’s picture

Thanks for the reviews.

@sun: Right, that works technically too. But I think it's against our coding standards to do double assignments like that. Don't know if it's documented but I know patches of me were set to needs work because of such things.

sun’s picture

Right, that works technically too. But I think it's against our coding standards to do double assignments like that. Don't know if it's documented but I know patches of me were set to needs work because of such things.

Yeah, very sad panda. Commenting on this would only circle back into #1791872: [Policy, no patch] Add special tag to identify issues ready for a high level only review... so I refrain from that and that's why I'm fine with the duplicate invocation.

Someone will ask whether we cannot do a simple $readable = $writable; assignment on a second line, but that would be even more confusing than the double variable assignment. At least in my book.

YesCT’s picture

Since I was reading the comments to catch up on the progress here, I updated the issue summary.

@webchick, I think your concerns from #4 have been address and this is ready.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Oh, nice! It turns out this issue has been driving me nuts while I've been testing Spark. :) Nice to see a fix! And thanks for the extra reviews.

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary to reflect code review done.