Follow up for #1250800: Language domain should work regardless of ports or protocols
Parent issue
#1269834: META: Clean up language negotiation code
Problem/Motivation
locale.admin.inc does not check the entered domain, as of now the entered domain may not contain a protocol nor a port.
Proposed resolution
1/ add a form_validate to check this
2/ add an upgrade function to convert all domains from D7
Comment | File | Size | Author |
---|---|---|---|
#87 | interdiff.txt | 417 bytes | Gábor Hojtsy |
#87 | 1272840-87.patch | 4.96 KB | Gábor Hojtsy |
#85 | 1272840-85.patch | 4.56 KB | Gábor Hojtsy |
#81 | 1272840-81.patch | 4.48 KB | Gábor Hojtsy |
#81 | interdiff.txt | 528 bytes | Gábor Hojtsy |
Comments
Comment #1
Gábor HojtsyTagging.
Comment #1.0
Gábor HojtsyAdd parent
Comment #2
Gábor HojtsyWould be great if you could work on this! Thanks for your contributions!
Comment #3
attiks CreditAttribution: attiks commentedi'll will somewhere this week.
Comment #4
attiks CreditAttribution: attiks commentedFirst attempt, no tests yet
Comment #5
attiks CreditAttribution: attiks commentedUpgrading can be a problem, since Drupal 7 allowed specifying protocol and port numbers, it's in theory possible that someone used the same domain name for multiple languages, for example:
http://localhost for English
http://localhost:88 for Dutch
So we need a way to alert the user that the upgrade isn't working?
Comment #6
Gábor HojtsyInteresting, I'd have used a regex to ensure no slashes, only letters, numbers and dots are in the setting. That would allow domains and IP addresses alike, at least IPv4. It becomes complicated with IPv6. Does this solution deal well with that? http://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_netw...
Agreed, automated tests would be great / important.
Comment #7
Gábor Hojtsy@attiks: cross-post. In the update function, you can warn them that the domains are now identical and they need to go and configure it differently.
Comment #9
attiks CreditAttribution: attiks commentedIt works for IP4, not for IP6
Comment #10
attiks CreditAttribution: attiks commentedUpdated the test, but now we're having a problem to test if https is working :/
Comment #11
Gábor Hojtsy@attiks: your new patch does not include the submission change? Also, update functions are still needed as discussed above.
Comment #12
attiks CreditAttribution: attiks commentednew patch including update function, but since this is my first update_N for core, no idea if this is OK, I tested this using devel and it appears to work
Change to conflicting values (enable Dutch and French first)
Run the update
Comment #13
Gábor HojtsyLooking good. Some comments:
1. I'm not sure we can ignore ipv6 support. By the time Drupal 8 is released and as long as it is in production, ipv6 should be pretty commonplace. Granted this is supposed to be a domain name, not an IP address, but I think people would use IPs here for testing, no?
2. I'd not include a message if the domain was just updated to do the same thing. If there were any in error though, we should have a link to the config page to fix it (at the end, not as part of every single error message :).
Comment #14
attiks CreditAttribution: attiks commented#13/1: IP6 works, if you enter addresses like [fe80::78ba:e205:3a59:b09%13], including the brackets
Comment #15
attiks CreditAttribution: attiks commented#13/2 new patch attached
Comment #16
Gábor HojtsyComment #17
attiks CreditAttribution: attiks commented@Gabor, message is only set once (it's a string, not an array anymore), it's easier to keep it inside the same foreach, otherwise we need another one just for the message. Or am I missing something?
Comment #18
Gábor Hojtsy@attiks: right, you are right, I missed that. Looking at the message then, t() is not used correctly there. We usually include the full a tags for links so we can include the full text for the link. However, we avoid using t() in update functions since the underlying database might change, and in D8 especially, it sounds unlikely that t() will work in the update function, there are just way too many changes going on underneath. So I'd drop the t().
Comment #19
attiks CreditAttribution: attiks commentedPatch without t, if necessary we can patch it later
Comment #20
attiks CreditAttribution: attiks commented#19: i1272840_no_t.patch queued for re-testing.
Comment #22
Gábor HojtsyFix title now that function is moved. I think you'll at least need to re-roll the patch for the /core/* move (#22336: Move all core Drupal files under a /core folder to improve usability and upgrades).
Comment #23
attiks CreditAttribution: attiks commentedRerolled the patch against new core structure
Comment #24
attiks CreditAttribution: attiks commentedsome typos fixed
Comment #26
attiks CreditAttribution: attiks commentedFailed on UpdateCoreTestCase->testDatestampMismatch(), but no idea if it's related to the new update function.
Comment #27
attiks CreditAttribution: attiks commented@Gabor: is there something wrong in the update test? I had to add the isset line.
23 days to next Drupal core point release.
Comment #28
attiks CreditAttribution: attiks commentedComment #29
Gábor HojtsyIt is best to avoid calling API functions like language_list() in an update function. Other update functions, like the one above, you can see use direct DB queries to do changes to the db. That ensures we control the whole code running and accidental hooks are not fired which expect updated schemas, etc. If the $languages[1] list is empty there, then your patch does not really do any update, so yeah, that sounds like a sizable issue :)
Comment #30
good_man CreditAttribution: good_man commentedYou need also to rename locale_update_8001() to locale_update_8002() or put it in the already existed update locale_update_8001(). As now after applying your patch your update 8001 will be duplicated with another one.
Comment #31
Gábor HojtsyLets introduce a new update function for this IMHO.
Comment #32
attiks CreditAttribution: attiks commentedlocale_update_8001() was a typo, I'll fix it and rewrite it using direct db calls
Comment #33
Gábor HojtsyPerfect, thanks.
Comment #34
Gábor Hojtsy@attiks: can you provide an updated patch?
Comment #35
attiks CreditAttribution: attiks commented@Gabor, sorry for the delay lost track of it ;p
New patch is using locale_language_negotiation_url_domains(); to get all defined domains, not sure if it's the right way to go.
Comment #36
Gábor HojtsyTagging for base language system.
Comment #37
Gábor HojtsyTagging for language negotiation too.
Comment #38
Gábor Hojtsy#1250800: Language domain should work regardless of ports or protocols is now comitted to D8, so lets work on the upgrade path. Can you re-roll the patch? Also will need upgrade path testing after that. I can help with that.
Comment #39
pp CreditAttribution: pp commentedComment #40
pp CreditAttribution: pp commentedI rerolled the patch and added a test for the upgrading method.
Comment #41
Gábor Hojtsy- can not => should not.
- end sentence with a dot.
Maybe add a comment here that we check if the entered text is exactly a hostname (or change the above comment to that), given that we discussed this quite a bit.
"Converts language domains to new format."
That should already be true since it is a requirement for locale, no?
Dots at end of line.
Add a dot at end of sentence.
"Tests language domain upgrade path."
I'd add a newline before and after this one, since its the big dramatic piece in the function :)
"Language domain for Catalan properly upgraded."
Comment #42
pp CreditAttribution: pp commentedThank's for review. I corrected the patch. Please review again.
Comment #43
Gábor HojtsyWrap at 80 chars. Otherwise looks good.
Comment #44
pp CreditAttribution: pp commentedThank's, I corrected it.
Comment #45
fubhy CreditAttribution: fubhy commentedWhat are the double quotes arround the array key good for? :) Also, can we use single quotes for the URL? I always prefer single quotes :)
Comment #46
pp CreditAttribution: pp commentedThank's,
Is this what you like?
Comment #47
pp CreditAttribution: pp commentedComment #48
fubhy CreditAttribution: fubhy commentedMy fault. I read wrong (didn't see the dollar sign) :/. The array key for the edit in the test was fine. Sorry!
Comment #49
Gábor HojtsyLooks like then #44 should be RTBC. Uploading here again for making sure the right one is committed. It is not my patch, not changed from #44.
Comment #50
catchThis looks fine. Committed/pushed to 8.x.
Comment #51
Gábor HojtsyYay, thanks! Removing outdated tags.
Comment #52
Gábor HojtsyBroke head. locale_update_8001 already existed. Also, 8001 was put before 8000, hah. Attached patch moves the update function to after 8001 and renames to 8002.
Comment #53
catchWhoops committed the follow-up.
Comment #54
Dave ReidAfter an update to D8 I had the following error when running update.php:
Fatal error: Call to undefined function locale_language_negotiation_url_domains() in /home/dave/Dropbox/Projects/drupal8dev/core/modules/locale/locale.install on line 294
Note I did not have locale.module enabled on my D8 local install. I suspect that may be the issue. Simple fix to add a call to include includes/locale.inc but we need to catch these types of things in testing.
Comment #55
Dave ReidThis allowed the update function to run in my case successfully.
Comment #56
webchickWhy the hell did the upgrade path tests not catch this..??
Comment #57
xjmRecategorizing. We think the upgrade tests start from having the module enabled, so we probably need to expand the test coverage to account for the other case?
Comment #58
xjmSo the issue is pretty clear; calling an API function from within
foo.install
, and as I have just now learned we run upgrades whether a module is disabled or not.So sounds like upgrade path coverage against the
bare
dump is missing? Or, wait, we need an upgrade path test for a filled dump with all the modules disabled.Comment #59
Dave ReidI have filed #1460764: Missing test coverage for a D7 install with non-required modules installed but disabled as a critical task for D8 since I'm not sure what other bugs we're going to expose with disabled module update functions and this task is non-trivial as a follow-up in this issue.
Comment #60
xjmdavereid filed #1460764: Missing test coverage for a D7 install with non-required modules installed but disabled. As far as I can figure adding test coverage for the upgrade path for previously installed (a.k.a. disabled) modules is a pretty big task, so IMO we should commit this as-is to fix the upgrade path, and then work on making sure it doesn't happen in the future.
Comment #61
webchickGreat, thanks for the follow-up.
Committed and pushed to 8.x. Thanks for the fast turnaround!
Reverted status.
Comment #62
Dave ReidThanks all.
Comment #63
catchSorry I must have been asleep when I committed this. Crud api functions like this can't be used in updates anyway, so this needs fixing to add _update_foo versions.
Comment #64
xjmDo those go in the
.install
?Comment #65
catchThey do. I'm not at pc at the moment but I'll likely roll the already committed patches back later so we can get this out of the criticals queue and add proper test coverage before it goes in again.
Comment #66
catchOK I've reverted three commits from this issue.
Here's the resultant patch for reference.
Comment #67
xjmSo back to NW on #49 then.
Comment #68
Gábor HojtsyOk, well, http://api.drupal.org/api/drupal/core%21includes%21locale.inc/function/l... is just a simple variable_get() wrapper. We could just as well replace all its occurances with variable_get() if that is better. Having two separately named wrappers for the same very simple thing is absolutely overkill.
Save function, same thing, just a variable_set(): http://api.drupal.org/api/drupal/core%21includes%21locale.inc/function/l...
Comments?
Comment #69
catchThere's already #1348162: Add update_variable_*() open for a proper upgrade variable_get() wrapper, so if we fixed that issue we could use that here.
Comment #70
Gábor HojtsyI've checked that 2/3rds of the update functions in node.install, locale.install and system.install all use variable_get/set, so sounds like using it here would not hurt anybody. #1348162: Add update_variable_*() can patch this one too when it is ready.
Comment #71
Gábor HojtsyUsing variable_get/set directly in the update function. Decided not to ruffle feathers and go in and change all places where the wrappers were used. I'm happy to do if that sounds like it would clear this up better. Feedback welcome.
Comment #72
catchI'd prefer it if we did #1348162: Add update_variable_*() first before adding any more update functions that we have to go back and fix later. Should we mark this postponed?
Comment #73
Gábor HojtsyOk, well, nobody seems to be working on that for the past three months. I don't see why we'd want to postpone landing this (and as a consequence moving language negotiation to language module and further cleanup of locale module, for which we are tirelessly working towards with issues like #1222106: Unify language negotiation APIs, declutter terminology too). Unlike #1348162: Add update_variable_*(), this is part of a stream of issues which constantly step on each other's toes to get in so they can form the puzzle pieces of the bigger overall goal.
Comment #74
webchickI actually agree with Gábor here. This feels akin to holding up sensible block system improvements because something in WSCCI vaguely touches it, and forcing people to work on stuff outside of their immediate area.
variable_get/set()s in update functions already pre-date this patch. It's not making the situation any worse, other than it's one more find/replace to do when #1348162: Add update_variable_*() is completed. That issue is a critical task, so it'll definitely get done before D8 ships.
Comment #75
catchNo it's about fixing the upgrade path now, not in a year's time.
Comment #76
Gábor HojtsyOk, well I fixed the code as per recommendation to not use API functions (outside of variable_get/set used in ~2/3rds of existing upgrade functions in core). I consider this back to RTBC. If you think the other improvement needs to be in first, please mark this postponed. I'll make sure to mark other issues postponed as a consequence, like our other RTBC issue at #1222106: Unify language negotiation APIs, declutter terminology.
Comment #77
Gábor HojtsyAlso in terms of head-to-head upgrade path, this one had locale_update_8002() in Drupal core before. Now its backed out, so other changes might get locale_update_8002() (like #1222106: Unify language negotiation APIs, declutter terminology and #746240: Race condition in locale() - duplicates in {locales_source}, which now compete for that number too) which would break head-to-head updates. So in practice, postponing this one postpones any language patches that would need an update function in locale.install added. (Unless if we skip this update function number for the future, in which case maybe #746240: Race condition in locale() - duplicates in {locales_source} can land since it only uses DB calls - although the DB system methods also don't have any update version counterparts).
Comment #78
catchThe head-to-head upgrade path issue is only talking about unstable-n to unstable-n at the moment, so anything that happens in between those we'd not need to cover.
Comment #79
Gábor HojtsyOk, so since we don't have an unstable release yet, then its a free to take, so I'll reroll #746240: Race condition in locale() - duplicates in {locales_source} to compete for 8002 as well, and then whichever lands first will win that number despite this patch using it originally and the other two will need rerolls. At least my understanding of the guidelines then.
Comment #80
Gábor HojtsyTag again for sprint.
Comment #81
Gábor HojtsyUpdate function 8002 is now taken. Rerolled with 8003.
Comment #82
Dries CreditAttribution: Dries commented#81: 1272840-81.patch queued for re-testing.
Comment #83
Dries CreditAttribution: Dries commentedAsking for a re-test as I don't think this patch applies anymore.
Comment #85
Gábor HojtsyQuick simple reroll. Should still be RTBC if it passes tests. (It will be passed backed to needs work otherwise anyway).
Comment #87
Gábor HojtsyFunny, this patch fails on a tiny notice introduced by #1454538: Add langcode property to all entity types; for the user entity, distinguish entity language from user's language preference. Basically the $user->preferred_langcode might not be set yet. This looks pretty simple to fix, so we can IMHO fix it here instead of reopening that issue.
Comment #88
attiks CreditAttribution: attiks commentedChange looks good, but not marking as RTBC because there's code from me in here ;p
Comment #89
Gábor Hojtsy@attiks: heh, its been a while since you last touched it, right? Thanks for the review. The change was minimal so back to RTBC then :)
Comment #90
Dries CreditAttribution: Dries commentedIt applies now and still looks good. Committed to 8.x.
Comment #91
Gábor HojtsySuperb, thanks everyone!
Comment #92.0
(not verified) CreditAttribution: commentedBetter description, i hoe