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.
Afaik we need to use the global $base_url to fix this :(
From code : core/includes/bootstrap.inc
// @todo Temporary BC for install.php, update.php, and other scripts.
// - #1547184: Refactor Core scripts
// - #1546082: Follow-up to variable_get('clean_url') removal
I also checked #1648004: Helpful links use base_path() when they don't have to for more clues how to solve this.
Comment | File | Size | Author |
---|---|---|---|
#40 | drupal-2017769-40.patch | 2.54 KB | pplantinga |
#38 | drupal-2017769-38.patch | 0 bytes | pplantinga |
#37 | base-url-2017769-37.patch | 3.02 KB | longwave |
#26 | base-url-2017769-26.patch | 1.17 KB | pplantinga |
#17 | drupal-2017769-17.patch | 2.54 KB | katbailey |
Comments
Comment #1
clemens.tolboomComment #2
elachlan CreditAttribution: elachlan commentedRe rolled the patch. This needs some attention. This should have been committed ages ago.
Comment #3
elachlan CreditAttribution: elachlan commentedChange to be appropriate.
Comment #4
clemens.tolboom@elachlan afaik there is no difference between #3 and #2
Hmmm ... I got this problem when installing. Did you got this while updating?
Comment #5
elachlan CreditAttribution: elachlan commentedYes.
If you run Update.php then the links will link back to update.php.
Hence why I tagged it as database update system.
Comment #6
dawehnerPerfect, that is the design of url(), but shouldn't we use $base_path . '' ... i guess this is not possible?
Comment #7
elachlan CreditAttribution: elachlan commented$base_path returns "/" pretty much.
I think this is for the best. We now have tests to test for regression as well.
Comment #8
alexpottI think you might be abe to use
Drupal::request()->getBaseUrl();
here instead of the global...Comment #9
alexpottMarked #2020141: Wrong link to admin pages after succesful update as a duplicate...
jeroen12345, suhel.rangnekar, marcoscano
should be added to the commit message to ensure there work on producing exactly the same patch :) is credited.Comment #10
elachlan CreditAttribution: elachlan commentedMarking as RTBC.
Comment #11
alexpottSorry... this isn't rtbc... we need to address the issue raised in #8
Comment #12
elachlan CreditAttribution: elachlan commentedIn collaboration with alexpott, we worked out that
Drupal::request()->getBaseUrl()
isn't working how we would like.So for now it is best to use
global $base_url;
This is due to Url() https://api.drupal.org/api/drupal/core!includes!common.inc/function/url/8
At the moment it isn't working properly, this comment is left in the code in common.inc
alexpott will check on outstanding issues tomorrow with a few others.
Comment #13
alexpottI think what we can do this...
Comment #14
elachlan CreditAttribution: elachlan commentedThat didn't work for me when I tried it.
Comment #15
alexpottYep me neither... what is very interesting is my I access update.php the baseUrl property on the url_generator is set to
http://my.drupal8.site/core
when the actual base url ishttp://my.drupal8.site
I think we're dealing with a deeper issue in the routing system / url generation system.
Comment #16
clemens.tolboomHave you read the issue summary? $base_url is necessary. It has todo's in common.inc which should be addressed somewhere else.
Note the request to update.php has its url() pointing to update.php as the request came from it.
This patch is RBTC-ed by dawehner on my request so afaik it's good to go.
@alexpott I agree this is not perfect but we cannot patch url() as /update.php is the active request and not /index.php
Comment #17
katbailey CreditAttribution: katbailey commentedHere's a fix that uses the same technique as we use in the installer - setting the script path and base path to use on the generator.
Comment #18
elachlan CreditAttribution: elachlan commentedWorks for me. Has my +1.
Comment #20
elachlan CreditAttribution: elachlan commented#17: drupal-2017769-17.patch queued for re-testing.
Comment #21
clemens.tolboomSome notes:
- Patch looks great but does it work for the url's used in update php when results from either drupal_requirements_url() and drupal_current_script_url() are put through check_url()? Are all URLs ok which patch #17?
- I've tested the patch by changing user update 8018 to 8017 as it's code seems non destructive. The links on http://drupal.d8/core/update.php?op=results are ok.
Comment #22
pplantinga CreditAttribution: pplantinga commentedThe issue here is deeper than just update.php
In UrlGenerator::generateFromPath we refer to $this->basePath which is set to be Symfony's $request->getBasePath() which returns the currently executing script's location. It looks like we're assuming that index.php will be the executing script.
So anytime we're not in index.php (e.g. install.php, update.php, authorize.php, etc.) this will return a different value.
Comment #23
elachlan CreditAttribution: elachlan commentedIs it related to this issue? #2031353: URLgenerator broken for Drupal installed in a subdirectory - doesn't have a way to get a Drupal path
On that note, has anyone tested without drupal being installed in a subdirectory?
Comment #24
longwaveMarked #2029541: Links in update.php page don't point to the right location as duplicate, which has a similar patch to #17.
Comment #25
elachlan CreditAttribution: elachlan commented#22 - could you explain what you mean by "It looks like we're assuming that index.php will be the executing script."
I couldn't find mention of it in UrlGenerator::generateFromPath.
Comment #26
pplantinga CreditAttribution: pplantinga commentedSure, I'll elaborate.
In drupal 7 url() (the place where this code used to reside) the line reads
Where base_path() is the global $base_path variable, which is the installation directory of drupal.
Now the line reads:
Where $this->basePath is set to be the directory of the currently executing script.
Perhaps this was done before scripts were moved to core/ and so the author didn't realize that $this->basePath would be different in different scripts.
I think probably the best solution is to make $this->basePath be based on the global $base_path variable again, and then change $this->scriptPath to include /core/ or whatever. Also, the comment on 'script' is misleading:
I think ideally, 'script' would just be a boolean indicating whether or not to include the script path since the path can be set using $this->setScriptPath()
Here's a patch just implementing the basePath change, and "fixing" the broken links on the update page. I'm kinda thinking more needs to be done, but I'm not sure if "API freeze" prevents this...
Comment #28
pplantinga CreditAttribution: pplantinga commented#26: base-url-2017769-26.patch queued for re-testing.
Comment #30
pplantinga CreditAttribution: pplantinga commented#26: base-url-2017769-26.patch queued for re-testing.
Comment #31
katbailey CreditAttribution: katbailey commentedThe "assumption" here, if there is one, is that we are using a front controller - update.php and install.php are not proper front controllers, and so they need to be special-cased. We certainly do not want to be putting calls to
base_path()
in the generator. The solution in #17 is what we need here: tell the generator what script path and base path to use when generating urls in update.php or install.php because it cannot get them from the current path as it is a stupid non-front-controller path.Comment #32
longwave+$generator->setBasePath(str_replace('/core', '', $request->getBasePath()) . '/');
What if there is another directory beginning with "core" in the path?
Comment #33
pplantinga CreditAttribution: pplantinga commentedFair enough. This gets my +1 too then.
As for #32, this is a special case, so we need not worry about other cases.
Comment #34
YesCT CreditAttribution: YesCT commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #35
clemens.tolboomWhere are the tests done by #2#3 #17?
Comment #36
longwaveMarked #2044371: wrong links under update.php as duplicate.
@clemens.tolboom: #17 adds tests to ensure the links no longer contain "update.php"; if this is not enough, what else should be tested?
Comment #37
longwaveOh, I see what you mean now :)
Attached is #26 plus tests from #17.
Comment #38
pplantinga CreditAttribution: pplantinga commentedWhen I marked this as rtbc, I was referring to #17, not #26, sorry for the confusion. I'll attach it again just to make it clearer.
Comment #39
elachlan CreditAttribution: elachlan commented#38 - You posted an empty patch.
Comment #40
pplantinga CreditAttribution: pplantinga commentedSomeone needs a brain transplant (hint: the answer is me). here's an actual patch.
Comment #41
dawehnerNice
Comment #42
alexpottConfirmed the additions to the tests fail without the fix...
Committed 79347b8 and pushed to 8.x. Thanks!