Problem/Motivation
\Drupal\Core\Command\BootableCommandTrait::boot() uses Request::createFromGlobals() to create a request to boot Drupal with.
This, unfortunately, causes the base URL to be wrong; it will be http://:core/scripts, which is totally invalid and will cause URLs to be mis-generated.
Proposed resolution
Drush sidesteps this by actually constructing a real-enough URL and calling Request::create(). We should do something similar.
Remaining tasks
Test coverage is easy: BootableCommandTrait should always assert that the global base URL at least has a valid form, by asserting that parse_url($GLOBALS['base_url']) !== FALSE.
Issue fork drupal-3553664
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
phenaproximaComment #4
phenaproximaComment #5
alexpottThe assert can be removed no? Like it's not really adding much afaics
Comment #6
phenaproximaIt is. Adding that assert caused all functional test jobs to fail (see the first commit and its pipeline). It’s a very effective way to ensure the URL is coherent.
Comment #7
alexpottYou are literally testing the basically hardcoded string you have added in
Request::create('http://' . basename($kernel->getSitePath()) . '/core/scripts/drupal');For me this feels like:
Comment #8
phenaproximaThis is a Drupal CMS stable blocker. Our site templates will provide Canvas pages, and you can bet those pages will reference media items -- which is how I turned up this bug, but I don't doubt it could manifest in other ways too. If those recipes cannot be applied at the command line, we're in trouble.
In a quick Slack conversation with @alexpott, I agreed to remove the assertion. That means there's no explicit test coverage of this, but we both felt that the proper long term fix is for
BootableCommandTraitto support a global--urioption, same as Drush does. I'll open a follow-up for that.Comment #9
alexpott@phenaproxima - now that is a test. Love it.
Comment #10
nicxvan commentedThis looks good now, there was a discussion in Slack about the http vs https that this should not affect anything.
There is likely an issue in canvas that needs resolving for follow up.
Comment #11
alexpottCommitted and pushed 8ac2dac793f to 11.x and b07aab80fb8 to 11.2.x. Thanks!