Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce
- Create an install profile that assigns a value to system.date:timezone.default = Europe/London using config\install\system.date.yml.
- Run unattended install using drush.
- Expected: site has timezone Europe/London.
- Actual: site has timezone UTC (or whatever PHP date_default_timezone_get returns).
Proposal
SiteConfigureForm should check for existing values and use them. The fallback defaults should only be used if there is no existing value.
There are two values that are currently wrong: system.site:site_mail and system.date:timezone.default.
Comments
Comment #4
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedI came across this too, working on a patch.
Comment #5
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedHere's a patch that fixes the
timezone.default
issue as described in the issue summary.I wasn't able to replicate the same with issue with
mail
but I did add a test that verifies a site email address provided by the install profile is retained. That means the problem may be with Drush on that one.Comment #6
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedComment #7
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedI know 8.3.x is done, but here's a patch anyway for anyone who wants it.
Comment #8
AdamPS CreditAttribution: AdamPS commented@decafdennis Thanks for the patch.
I can reproduce the site mail issue running the install GUI by hand. The required site mail field appears as blank even though the install profile set a value. This matches reading the code of SiteConfigureForm::buildForm which makes no attempt to read the existing value of site_mail.
I suggest that the patch should have the same logic for site_mail as for the timezone.
I can't explain how your test passes. sendmail_from is a mandatory field. Could it be that in submitForm
$this->config('system.site')->save(TRUE)
silently fails, leaving the original correct value in place?One other minor comment: the line
protected function installParameters() {
is incorrectly indented.Comment #9
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedThanks for the feedback! I'll take another look at it and see if I can get a failing test for the site email field.
Comment #10
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedHere's a new patch that:
* fixes the code indentation issue,
* favors an existing
system.site:mail
value, if present, over the defaultini_get('sendmail_from')
,* tests the default values present on the form, in addition to testing the site config after installer completion.
Note that this still does not fix the unattended installer use case for the site email address field, because Drush has it hardcoded to always default to admin@example.com if
--site-mail
is not provided.Comment #11
AdamPS CreditAttribution: AdamPS commented@decafdennis Thanks again, new patch looks good to me.
Good point about drush, however that feels outside the scope of this Drupal core issue. I vote for RTBC.
Comment #12
xjmFor readability and maintainability, I think it would be better to put it all in one line for later use in the form array, with a comment:
Comment #13
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedSee attached a new patch with requested changes, and a test-only patch.
@xjm: I don't think we can remove that @ as there could still be a warning in PHP 5.5, see https://www.drupal.org/node/2446859
Comment #15
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commentedRerolled patch for 8.4. The default email is already fixed in 8.4. The tests are still new, so I have kept them in the patch
// Edit => Nvm, previous comment also includes a patch for 8.4
Comment #16
nils.destoop CreditAttribution: nils.destoop as a volunteer and at Wunder commentedComment #18
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedComment #19
AdamPS CreditAttribution: AdamPS commentedLooks good to me
Comment #20
alexpottThe question about the usage of
@
and PHP versions was answered in #13 - PHP5.5 is greater than PHP5.4.
I've re-uploaded the patch in #13 as that is the latest and RTBC patch as far as I can tell. The rtbc patch should always be the latest patch since that's how rtbc patches are re-tested.
Comment #21
alexpottClass properties should be camelCase and also need a doc block.
I'm sure though that storing this on the class is really necessary. For the email - just use the hardcoded email in the assert it removes one level of indirection. For timezone maybe a class property is okay. So that would be something like:
Rather than doing this in the constructor we should do this in setUp() as this is test set up. It is super rare to override a test constructor.
Comment #22
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedThanks for the feedback. Here's a new patch with the following changes:
expectedTimezone
class property intosetUp()
. @alexpott For my understanding, can you say more about why this is necessary? It feels more like object initialization to me, which belongs in the constructor, more than test set up, which would go insetUp()
.Comment #24
alexpottSo with the timezone thing we have an interesting problem!
At the moment the test works because InstallerSiteConfigProfileTest inherits for WebTestBase. All Simpletests will be converted to BrowserTestBase at some point. This means that in the test running process the timezone will be set to
'Australia/Sydney'
by bootstrap.php. However because the install is happening in a separate process from test running the install is still occurring with PHP's default timezone. In WebTestBase land the timezone is set to'Australia/Sydney'
in WebTestBase::setUp() but that is still only occurring in the test runner process. Fortunately in regular tests we do a non-interactive install so for the most part all sites are being installed with'Australia/Sydney'
- the exception being any test extending InstallerTestBase. I think we need to open an issue to ensure that sites installed by InstallerTestBase have the expected default timezone of'Australia/Sydney'
and then this test could just use a constant for the timezone and not have to do anything tricky and it won't break when InstallerTestBase gets converted. Opened #2915664: Sites installed by InstallerTestBase should have a timezone of 'Australia/Sydney' to address this. We should postpone this on fixing that.As re: test class constants for expected values vs just having the string - for me it depends how often it appears. Twice I'd hard code the string.
Comment #25
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedBlocked by #2915664: Sites installed by InstallerTestBase should have a timezone of 'Australia/Sydney', will need work following.
Comment #26
alexpottIt's not blocked anymore.
Comment #27
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedWith the timezone in
InstallerTestBase
being standardized and with other inspiration from #2915664: Sites installed by InstallerTestBase should have a timezone of 'Australia/Sydney' I was able to simplify the patch significantly.Comment #29
sagesolutions CreditAttribution: sagesolutions commentedI just tested drupal-profile-site-config-2849074-27.patch and it does keep the timezone as set in the system.date.yml file.
However, the site's email does not get saved from system.site.yml I believe this is due to drush overriding it as per https://drushcommands.com/drush-8x/core/site-install/
--site-mail : From: for system mailings. Defaults to admin@example.com
So when I run
drush site-install mycustomprofile
the site email is set to admin@example.com instead of whats in the system.site.yml file.Comment #30
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedSee #10 and #11; Drush is outside the scope of this issue.
Comment #32
decafdennis CreditAttribution: decafdennis at Digital Deployment, Inc. commentedRe-rolled for 8.5.x and 8.6.x (they're the same, actually).
Comment #36
tuchoWe are using the patch from #32 on a Drupal 8.6.x installation and it works ok.
We have tested it using a YAML file on the profile and, also, setting the timezone on the profile's hook_install without any problem.
Comment #37
AdamPS CreditAttribution: AdamPS commentedThanks @tucho, so looks like this is back to RTBC.
Comment #39
alexpottLooks like this needs a reroll and we should target 8.7.x first. Hopefully the patch will also apply to 8.6.x
Comment #40
alexpottRerolled the patch.
Comment #41
AdamPS CreditAttribution: AdamPS commentedThanks @alexpott
Comment #42
alexpottCommitted and pushed 04d46f628d to 8.7.x and 55037b509c to 8.6.x. Thanks!
As a non-disruptive bug fix backported to 8.6.x
Comment #45
AdamPS CreditAttribution: AdamPS commentedGreat thanks @alexpott