Cms: Project Config bug?

Created on 1 Dec 2020  Â·  16Comments  Â·  Source: craftcms/cms

Description

If you set the Base URL of a site to an alias, it will properly set that alias in the Project Config files.

base-url@2x

But when you "Rebuild the Config", it will actually change it to the _value_ of the alias.

hardcoded@2x

Steps to reproduce

  1. Use an alias for the baseUrl
  2. Run "Rebuild the Config"
  3. Look at the changes in default--***.yaml

Additional info

  • Craft version: Craft Pro 3.5.16
  • PHP version: 7.4.9
bug

Most helpful comment

Worth mentioning here that I’ve just deprecated the siteUrl config setting for Craft 3.6 (see #3205). So while this bug will be fixed in the next release, you’re best off moving away from that config setting to begin with, and setting your sites’ Base URL settings using aliases or environment variables instead.

All 16 comments

Not able to reproduce this, and not sure how it could happen. Sites’ configs are rebuild from craft\models\Site::getConfig(), which returns the current $baseUrl value:

https://github.com/craftcms/cms/blob/1d69bfb0308d3b56990d7b257591071992d7a297/src/models/Site.php#L264-L277

Craft never stores the parsed base URL there – that only happens from getBaseUrl():

https://github.com/craftcms/cms/blob/1d69bfb0308d3b56990d7b257591071992d7a297/src/models/Site.php#L128-L135

Maybe something in a module/plugin is overwriting the $baseUrl property with the parsed URL?

Weirdly, this trick doesn't seem to be working for me either...

https://github.com/craftcms/cms/issues/5106#issuecomment-708718343

Can you reproduce that one? If not, i can nuke my whole vendor folder and try again.

For what it's worth, I've noticed something similar with a project updating from Craft 2 to 3. When doing the upgrade on the DB, we throw out the upgraded project config values (in favor of the ones we've been working on for Craft 3), but Craft seem to _really_ want us to use the URL string rather than an environment variable.

Next time we run the process I'll see if I can narrow down the issue to anything more specific.

@lindseydiloreto 'disabledPlugins' => '*' is still working for me.

Ah, my bad! I was doing it wrong, setting it as an array syntax (['*'] instead of just '*'). 🤦

Ok, I have:

  1. Disabled all plugins
  2. Disabled all modules
  3. Run composer nuke

And I still get the same issue when I click the "Rebuild the Config" button...

rebuild@2x


same@2x

It's worth noting that the baseUrl gets written to PC normally when you simply edit that field directly.

baseUrl@2x

After I re-save the field normally, it corrects the PC mistake.

And even now, after saving the site from the CP with @baseUrl, if you rebuild the project config, it will go back to http://industrialassets.test ?

If I save the field normally (as if I were editing it), the PC value is set to @baseUrl.

If I rebuild it (via "Rebuild the Config"), the PC value changes to http://industrialassets.test.

Alright, well I’m a bit stumped. If you can send in your Composer files, a database backup, and any custom module files, etc., we can try to reproduce it locally using those. [email protected]

You got it, thanks! I'll send that stuff over. 👍

We ended up tracking this down to the siteUrl config setting. Same issue could occur with the siteName config setting as well. I’ve fixed this for the next release.

Ok sweet, thanks @brandonkelly! 🍺

Worth mentioning here that I’ve just deprecated the siteUrl config setting for Craft 3.6 (see #3205). So while this bug will be fixed in the next release, you’re best off moving away from that config setting to begin with, and setting your sites’ Base URL settings using aliases or environment variables instead.

Craft 3.5.17 is out now with this fix.

Brilliant, thanks dude! 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mccombs picture mccombs  Â·  3Comments

bitboxfw picture bitboxfw  Â·  3Comments

RitterKnightCreative picture RitterKnightCreative  Â·  3Comments

brandonkelly picture brandonkelly  Â·  3Comments

darylknight picture darylknight  Â·  3Comments