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.
Part of #2068325: [META] Convert entity SQL queries to the Entity Query API. See the parent issue for details.
Comment | File | Size | Author |
---|---|---|---|
#81 | 2068329-convert_user_sql_queries_to_the_entity_query_api-81.patch | 15.63 KB | plach |
Comments
Comment #1
plachRelated issue: #1751274: Do not query user_roles directly.
Comment #2
peximo CreditAttribution: peximo commentedHi,
this is my initial work.
Comment #4
peximo CreditAttribution: peximo commentedRerolled
Comment #5
twistor CreditAttribution: twistor commentedShould we use STARTS_WITH here?
Go ahead and convert this to String::checkPlain().
Use CONTAINS?
Why not $user->save()?
Comment #6
peximo CreditAttribution: peximo commentedOk, I modified as suggested by @twistor, updated some parts and continued with the work.
Comment #7
Désiré CreditAttribution: Désiré commentedI'm successfully applied, and tested this patch.
I'm also not found any coding standard problems, so I change the status to RTBC.
Comment #8
BerdirI'm not sure about this change. This very explicitly did not use user save before, doing that is quite an overhead over the old code.
Comment #9
Désiré CreditAttribution: Désiré commentedThe main issue is about to use Entity API everywhere instead of SQL queries #2068325: [META] Convert entity SQL queries to the Entity Query API, and this means that we should user_save to change this data.
But I'm also thinking this is an overhead, have you any idea how can we resolve this without using db_update or user_save?
Comment #10
BerdirYes, there is an alternative, that would be to add a updateTimestamp($uid) to the user storage controller. But I'm not sure if it's worth it.
Comment #11
chx CreditAttribution: chx commentedI think it worths it.
Comment #13
Berdir#11: 2068329_11.patch queued for re-testing.
Comment #15
Désiré CreditAttribution: Désiré commentedIn the last patch the last login time wasn't set, here is the fix.
Comment #16
Désiré CreditAttribution: Désiré commentedI'm also confused of the variable name usage in this function:
Some cases it uses $user, other cases $account, they are the same of course, but is here any reason to using one or other in a context?
I think no, so if you agree, I'll change all usage of $account to $user from the 3. line of the function.
Comment #18
Désiré CreditAttribution: Désiré commented#15: 2068329-convert_user_sql_queries_to_the_entity_query_api-15.patch queued for re-testing.
Comment #19
chx CreditAttribution: chx commented> Some cases it uses $user, other cases $account, they are the same of course, but is here any reason to using one or other in a context?
I would rather change everything to account; using $user with the global $user being around is bad and dangerous practice. But if that's too much; just go with $user -- the global will be gone soon after all.
Comment #20
peximo CreditAttribution: peximo commentedOk I think it remains to change the anonimous and admin user creation on installation; but I do not know if at that stage it's possible to make an entity save.
@chx:
Do we also need to modify queries in the update functions and tests?
Comment #21
chx CreditAttribution: chx commented> change the anonimous and admin user creation on installation; but I do not know if at that stage it's possible to make an entity save.
I doubt you can; it worths trying; but I think any non-sql database will need to alter the install tasks anyways...
Regarding renames: just rename my $account to $user let's no go off on a tangent and do massive renames.
Regarding updates: absolutely not you can't use the entity system during updates.
Comment #22
Désiré CreditAttribution: Désiré commentedI'm agree that use $account is better than the global $user, so here is the new patch, only the variable names was changed in the user_login_finalize() function, and rerolled against the new 8.x HEAD.
Comment #23
peximo CreditAttribution: peximo commentedI believe that as expected you can not create the entity on installation. I only made one final change to the api file; I think that there is nothing else to do.
Comment #24
BerdirI guess we need to inject all those entity query instances?
Comment #25
peximo CreditAttribution: peximo commentedOk modified as suggested, I hope the right way.
Comment #26
plachChanges look good to me.
A very minor nitpick: if we happen to reroll this, can we swap the entity manager and the query factory order? The entity manager appears as more "important" to my eyes :)
Comment #28
peximo CreditAttribution: peximo commentedRerolled with some adjustment.
Comment #30
peximo CreditAttribution: peximo commentedI hope this is the last time, rerolled.
Comment #31
plachThe patch no longer applies:
EntityFormControllerNG
has been renamed toContentEntityFormController
.The operator here should just be omitted and the unescaped value should be passed, AAMOF the equality operator is already case-insensitive for regular string fields (see #2068655: Entity fields do not support case sensitive queries).
Now we always use a leading backslash:
\Drupal::...
Comment #32
peximo CreditAttribution: peximo commentedRerolled.
Comment #33
plachNice work!
I didn't realize we have a small API change here: the returned value is now an array of user ids. The documentation should reflect it.
Aside from this I'd say we are RTBC.
Comment #34
peximo CreditAttribution: peximo commentedOk modified as required.
Comment #35
peximo CreditAttribution: peximo commentedI realized that returning a boolean value is cleaner for the purpose of the function.
Comment #36
peximo CreditAttribution: peximo commentedSorry I forgot the cast.
Comment #37
plachThanks! RTBC if green.
Comment #38
plachComment #39
plachComment #40
plachComment #41
plachComment #42
Xano36: 2068329-convert_user_sql_queries_to_the_entity_query_api-36.patch queued for re-testing.
Comment #44
marcingy CreditAttribution: marcingy commentedJust a simple re-roll
Comment #46
marcingy CreditAttribution: marcingy commentedShould fix the issues and also kills what seems to be unused use statements
Comment #47
plachLooks good, thanks.
Comment #48
peximo CreditAttribution: peximo commentedRerolled.
Comment #50
peximo CreditAttribution: peximo commented48: 2068329-convert_user_sql_queries_to_the_entity_query_api-48.patch queued for re-testing.
Comment #52
plachThat test passes locally and is failing in other unrelated issues too.
Comment #53
plach48: 2068329-convert_user_sql_queries_to_the_entity_query_api-48.patch queued for re-testing.
Comment #54
LinL CreditAttribution: LinL commented48: 2068329-convert_user_sql_queries_to_the_entity_query_api-48.patch queued for re-testing.
Comment #56
herom CreditAttribution: herom commentedreroll
Comment #58
penyaskitoReroll. Attached diff between patches #48 and this one.
Comment #59
chx CreditAttribution: chx commentedComment #60
plachComment #61
LinL CreditAttribution: LinL commentedReroll. Patch no longer applied following #2145007: Convert form_set_error() in FormBase classes to use FormErrorInterface
Comment #62
LinL CreditAttribution: LinL commentedAnother reroll following #2146517: Remove annotation 'use' statements from all core classes
Comment #63
LinL CreditAttribution: LinL commentedComment #64
chx CreditAttribution: chx commentedComment #65
xjm62: 2068329-convert_user_sql_queries_to_the_entity_query_api-62.patch queued for re-testing.
Comment #66
BerdirNote that #2164715: Remove user_node_load() will remove the user_node_load() completely which I think is preferred over this, so will need a re-roll if it gets in first and if something else conflicts first, I'd suggest to re-roll without that change.
Comment #67
catchDoesn't this mean the query will no-longer be case insensitive?
Comment #68
plach@catch:
The equality operator is case-insensitive for regular string fields (see #2068655: Entity fields do not support case sensitive queries).
Comment #69
catchThat patch isn't in yet though right?
Comment #70
plachYep, but no code would change here. Do you want to postpone this on that one?
Comment #71
catchHmm. Either postpone or make that one critical?
Comment #72
plachWell, these conversions actually block a critical beta blocker so it's more or less the same thing, I guess. I'd vote to commit this to avoid the reroll fun :)
Comment #73
plachSpeaking of rerolls... This is smaller as a couple of hunks were removed.
Comment #74
catchBumped the other issue to critical, I haven't reviewed the full patch here yet so just leaving RTBC.
Comment #77
plach73: 2068329-convert_user_sql_queries_to_the_entity_query_api-73.patch queued for re-testing.
No failure here.
Comment #78
plachBack to RTBC
Comment #79
catch73: 2068329-convert_user_sql_queries_to_the_entity_query_api-73.patch queued for re-testing.
Comment #81
plachRerolled
Comment #83
plach81: 2068329-convert_user_sql_queries_to_the_entity_query_api-81.patch queued for re-testing.
Comment #84
plachBack to RTBC
Comment #85
alexpottThis looks great!
Committed 0f704ad and pushed to 8.x. Thanks!
Fixed during commit - there was an inconsistency between the parameter names in the interface and the class.
Comment #86
xjmHm. Do we actually need a change record here? It looks to me like we are just injecting a couple more dependencies in some constructors, so the only BC breaks would be for someone subclassing these things or using them directly in D8. Maybe we just need to see if there are any references to these classes in existing change records, or verify that their aren't? Or did I miss something?
Comment #87
plachWe have a small API change in
user_is_blocked()
and the addition ofUserStorageController::updateLastLoginTimestamp()
. Not sure whether that's enough for a change notice, but I'd say it wouldn't hurt :)Comment #88
xjmAlright, thanks @plach!
Tagging "Missing change record", as completing the change record updates here blocks a beta: #2083415: [META] Write up all outstanding change notices before release
Comment #89
plachHere it is:
https://drupal.org/node/2186163
I added a note about the API addition at the bottom of the CN, since it is primarily focused on the API change.
Comment #90
plachMoving the change record to the review queue.