Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Config bug? #7208

Closed
lindseydiloreto opened this issue Dec 1, 2020 · 16 comments
Closed

Project Config bug? #7208

lindseydiloreto opened this issue Dec 1, 2020 · 16 comments
Labels

Comments

@lindseydiloreto
Copy link
Contributor

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
@brandonkelly
Copy link
Member

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:

cms/src/models/Site.php

Lines 264 to 277 in 1d69bfb

public function getConfig(): array
{
return [
'siteGroup' => $this->getGroup()->uid,
'name' => $this->name,
'handle' => $this->handle,
'language' => $this->language,
'hasUrls' => (bool)$this->hasUrls,
'baseUrl' => $this->baseUrl ?: null,
'sortOrder' => (int)$this->sortOrder,
'primary' => (bool)$this->primary,
'enabled' => (bool)$this->enabled,
];
}

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

cms/src/models/Site.php

Lines 128 to 135 in 1d69bfb

public function getBaseUrl()
{
if ($this->baseUrl) {
return rtrim(Craft::parseEnv($this->baseUrl), '/') . '/';
}
return null;
}

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

@lindseydiloreto
Copy link
Contributor Author

lindseydiloreto commented Dec 1, 2020

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

#5106 (comment)

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

@brianjhanson
Copy link
Contributor

brianjhanson commented Dec 1, 2020

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.

@brandonkelly
Copy link
Member

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

@lindseydiloreto
Copy link
Contributor Author

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

@lindseydiloreto
Copy link
Contributor Author

lindseydiloreto commented Dec 1, 2020

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

@lindseydiloreto
Copy link
Contributor Author

lindseydiloreto commented Dec 1, 2020

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.

@brandonkelly
Copy link
Member

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 ?

@lindseydiloreto
Copy link
Contributor Author

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.

@brandonkelly
Copy link
Member

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. support@craftcms.com

@lindseydiloreto
Copy link
Contributor Author

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

@brandonkelly
Copy link
Member

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.

@lindseydiloreto
Copy link
Contributor Author

Ok sweet, thanks @brandonkelly! 🍺

@brandonkelly
Copy link
Member

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.

@brandonkelly
Copy link
Member

Craft 3.5.17 is out now with this fix.

@lindseydiloreto
Copy link
Contributor Author

Brilliant, thanks dude! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants