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.
Problem/Motivation
Core should not use direct db calls to entity tables because they are managed by the table mapper entity API.
Proposed resolution
All db_query()
and similar should be replaced with \Drupal::entityQuery()
or with injected entity storage, and updates/deletes should be done via the Entity API.
Remaining tasks
replace all usage
User interface changes
no
API changes
no
Data model changes
no
Comment | File | Size | Author |
---|---|---|---|
#17 | 3014950-17.patch | 10.15 KB | goodboy |
#17 | interdiff-3014950-15-17.txt | 839 bytes | goodboy |
Comments
Comment #2
mondrakePatch.
Comment #3
mondrakeForgot some.
Comment #4
goodboyWe enshure that returns an integer value because it may be used on compare operations.
For empty
$fids_query
results$max_fid_after
is NULL (or FALSE) and can't be used on compare operation.Or use
current()
insteadreset()
to prevent errors with reset's argumentarray &$array
.Comment #5
volegerComment #6
mondrakeThanks for review @goodboy!
You are right in principle... I left that consciouly though because at that point in the test we expect at least one entity is returned.
Can you make #4 into a patch?
Comment #7
goodboyComment #8
goodboy@mondrake , I'll do a patch.
I understand that specific tests will be correct, but I would like to make uniform functions.
Comment #9
goodboyPatch #4
Comment #10
voleger#9 addressed all from #4
Tests pass
+1 for rtbc
Comment #11
alexpottThis can use an aggregate query. Ie.
return (int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max']
... and all the other places... it seems the only query this replaces is the max ones so we should be using
\Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')
so people learn the right way to do that.Comment #12
goodboyApply #11
Comment #14
alexpottUnfortunately re-executing an aggregate query appears not to work. Let's do
(int) \Drupal::entityQueryAggregate('file')->aggregate('fid', 'max')->execute()[0]['fid_max'];
each time and open a bug report about this as you would expect it to work (if there is no existing bug report).Comment #15
goodboyComment #17
goodboyComment #18
mondrakeLoogs good. Filed #3015691: entityQueryAggregate queries cannot be executed more than once.
Comment #19
alexpottCommitted c503bb6 and pushed to 8.7.x. Thanks!