Problem/Motivation
The views module allows a view to be to an external database. And the external database does not have to be of the same type as the default database. For instance the default database is MySQL and the view get its data from a Microsoft SQL Server (a.k.a. the external database). The class Drupal\views\Plugin\views\query\Sql uses the correct database connection for the query. A number of views plugins that need a database connection, only use the default database connection. As long as the methods that they use from the database connection have the same implementation for all databases, then there is no problem. Unfortionally is this not always the case. The 2 databases from the example have a different implementations for conditions. See: #3130655: Deprecate creating an instance of the class Drupal\Core\Database\Query\Condition with the new keyword and #2031261: Make SQLite faster by combining multiple inserts and updates in a single query. Plugins therfor need to use the database connection from the class Drupal\views\Plugin\views\query\Sql. Plugins can only do that when there is a public method that will return the correct database connection.
Proposed resolution
Create a new public method Drupal\views\Plugin\views\query\Sql::getConnection() that will return the correct database connection for the view.
Remaining tasks
TBD
User interface changes
None
API changes
API addition with the new public method Drupal\views\Plugin\views\query\Sql::getConnection()
Data model changes
None
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3139353-17.patch | 4.87 KB | lendude |
| #17 | interdiff-3139353-13-17.txt | 852 bytes | lendude |
Comments
Comment #2
daffie commentedComment #3
andypostLet's use more readable code as the method is new, also fix CS
Comment #4
daffie commented@andypost: Thank you. Your patch makes the code more readable!
Comment #5
beakerboyThis new function fulfills the needs, and the tests provide suitable code coverage.
Comment #6
xjmThis seems like a fine refactoring and also a nice code cleanup at the same time. When I read the title I thought we should have a subsystem maintainer sign off on the change, but I'm a Views subsystem maintainer and this seems totally a safe change for me. Good test coverage, also. I have just a few nitpicks for us to address:
Should be "Gets".
This should have a one-line summary.
"Clean up" (two words).
Thank you!
Comment #7
mrinalini9 commentedComment #8
mrinalini9 commentedUpdated patch as per the changes suggested in #6, please review.
Comment #9
beakerboyAll recommendations for changes to comments have been made. No changes to code so back to RTBC.
Comment #10
xjmThanks for the quick fixes for my nitpicks. :) One point needs a little more work:
This change is not quite right. :) The full paragraph here is necessary and useful.
What's missing is a one-line summary above the
@coversthat describes what the method does. This should be followed by the full detail of the existing paragraph, and then the@coversgoes below that.Thanks!
Comment #11
andypost@xjm For tests @covers should be enough https://www.drupal.org/node/1354#tests (there was policy accepted at least for phpunit tests)
@covers is self explanatory - means testing specific method
Comment #12
xjmI pointed out to @andypost that that bullet links a reference that only allows omitting a one-line summary for a class in lieu of just using
@coversDefaultClass. There's nothing about@coversreplacing the one-line summary for methods; in fact, it says:https://www.drupal.org/node/2116043#s-examples--3
Nothing about skipping it for
@covers. Even if there were, though, this particular method is way longer than just a 1:1 test of a simple method and required a whole paragraph to explain, so I would still ask for a one-line summary here that's more human-readable.Also NW still because #8 is definitely not right regardless; we shouldn't be deleting most of the useful paragraph. My review meant add a sentence at the top.
Comment #13
daffie commentedFor #12: Fixed. I think that we have the information about which method is being tested double. The link that is given by @xjm in comment #12 is only about docblock for by the class definition and how it should work for methods is not available. Maybe we should fix this. There are a lot of test methods in core that only have an
@coversannotation and to me that is more then enough.Comment #14
andypostAs I got we should use
@coversonly for unittests which has@coversDefaultClassSo make sense to file follow-up and maybe policy to introduce sniff in coder
Comment #15
lendudeNitpick. it is a PHPUnit test, just not a Unit test.....strictly speaking it should probably say something like 'This is a kernel test because....'
Great to see test coverage for this!
Comment #16
xjmOops, yep, let's fix #15. If it were just swapping one word I might fix it on commit, but rewrapping whole paragraphs on commit is error-prone. NW for that too. Thanks @Lendude!
Comment #17
lendudeSo, that would be something like this
Comment #18
daffie commentedI was just about to fix the remark of comment #15.
The fix looks good.
Back to RTBC.
@lendude: Thanks.
Comment #20
xjmPushed to 9.1.x and published the CR. Thanks!
Comment #21
daffie commentedComment #23
taran2lThis issue continues work started in #3113403: Make Drupal\Core\Database\Query\Condition driver overridable and finished in #3130655: Deprecate creating an instance of the class Drupal\Core\Database\Query\Condition with the new keyword, however, it has not been committed to 8.9.x despite #3113403: Make Drupal\Core\Database\Query\Condition driver overridable has been, so again supporting a single codebase for D8 and D9 is not possible, but it can be with a little effort.
I can provide a backported patch for D8.9, anyone interested (i.e. will it be committed)?