CommentFileSizeAuthor
#51 interdiff-2873684.txt552 bytescatch
#49 interdiff.2873684.41-49.txt3.17 KBlongwave
#49 2873684-49.drupal.Replace-all-calls-to-dbselect-which-is-deprecated.patch103.75 KBlongwave
#41 interdiff-2873684-29-41.txt5 KBvoleger
#41 2873684-41.patch103.49 KBvoleger
#29 2873684-29.patch102.89 KBvoleger
#29 interdiff-2873684-27-29.txt4.59 KBvoleger
#27 2873684-27.patch102.8 KBvoleger
#27 interdiff2873684-23-27.txt947 bytesvoleger
#23 2873684-23.patch102.76 KBlongwave
#17 2873684-17.patch103.4 KBvoleger
#15 2873684-15.patch103.41 KBvoleger
#12 2873684-12.patch103.76 KBvoleger
#12 interdiff-2873684-11-12.txt555 bytesvoleger
#11 2873684-11.patch103.76 KBvoleger
#6 replace_all_db_select_calls-2873684-06-8.6.x.patch87.26 KBvoleger
#2 replace_all_calls_to-2873684-2.patch95.54 KBjeetendrakumar
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jeetendrakumar created an issue. See original summary.

jeetendrakumar’s picture

jeetendrakumar’s picture

Issue summary: View changes

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

voleger’s picture

joelpittet’s picture

There are a few comment references and core/tests/Drupal/KernelTests/Core/Database/SelectTest.php Are those meant to be replaced in this patch as well?

voleger’s picture

This is from meta issue #2848161: [meta] Replace calls to deprecated db_*() wrappers:

3. Open an issue (Category: Task, priority: Normal, make this issue the parent issue) to replace all usages of the function (except tests for the function itself) and link the issue below.

So, as I understand, calls inside tests that cover that function shouldn't be replaced.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
voleger’s picture

FileSize
555 bytes
103.76 KB

Status: Needs review » Needs work

The last submitted patch, 12: 2873684-12.patch, failed testing. View results

andypost’s picture

+++ b/core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
@@ -19,10 +20,11 @@ class DatabaseTestController {
+    $connection = Database::getConnection();

this is controller - needs DI

voleger’s picture

Status: Needs review » Needs work

The last submitted patch, 15: 2873684-15.patch, failed testing. View results

voleger’s picture

Status: Needs review » Needs work

The last submitted patch, 17: 2873684-17.patch, failed testing. View results

andypost’s picture

queued for retest mysql cos failure looks unrelated

longwave’s picture

Probably should postpone on #2853118: Replace all calls to db_insert, which is deprecated as it is just going to need another reroll, all these db_* deprecation patches keep clashing in DatabaseLegacyTest.

andypost’s picture

yep, better to reroll it after db_insert patch

voleger’s picture

longwave’s picture

db_insert is in, so rerolled this one hopefully for the final time.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Hope it is green!

andypost’s picture

Adjust credits - @jeetendrakumar somehow was excluded

The last submitted patch, 6: replace_all_db_select_calls-2873684-06-8.6.x.patch, failed testing. View results

mondrake’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/tests/Drupal/KernelTests/Core/Database/SelectComplexTest.php
@@ -343,12 +343,12 @@ public function testJoinSubquery() {
+    $query = $this->connection->select('test_task', 'tt', ['target' => 'replica']);

I am not so sure about this. The replica target is dealt with in db_select by selecting a different connection through Database::getConnection:

Database::getConnection($options['target'])->select($table, $alias, $options);

but

$this->connection->select('test_task', 'tt', ['target' => 'replica'])

is not changing the connection AFAICS.

We should address #2947775: Move setting default target out of db_merge() and other deprecated db_* functions first?

More eyes please...

longwave’s picture

Is it worth catching the 'target' option being accidentally passed to Query::_construct() and triggering an error on this? This would mean modifying all the deprecated db_*() functions slightly to remove that from the array, but it would catch bugs elsewhere now this parameter has moved.

andypost’s picture

+++ b/core/modules/search/src/Plugin/views/argument/Search.php
@@ -48,7 +48,7 @@
+      $this->searchQuery = \Drupal::database('replica')->select('search_index', 'i')->extend('Drupal\search\ViewsSearchQuery');

+++ b/core/modules/search/src/Plugin/views/filter/Search.php
@@ -120,7 +120,7 @@
+      $this->searchQuery = \Drupal::database('replica')->select('search_index', 'i')->extend('Drupal\search\ViewsSearchQuery');

as you affect this lines, please use ViewsSearchQuery::class directly instead of string

mondrake’s picture

#30 but that would practically mean that we are deprecating passing the 'target' key in the $options array, no? And creating a BC break.

IMHO we should try to address this in lower level in Connection::query / prepareQuery / prepare so that when the 'target' key is set, the statement is prepared against the target connection and not the default one. In other words, swap the used connection on lower level and keep BC.

andypost’s picture

@mondrake Good point about keeping BC

On one hand it is "strange" to change connection withing connection object
otoh functional wrappers were working this way... but "database::select/query" do not

So allowing changing connection through options is API addition and not very useful
But makes sense to update CR about that - db_select & database::select already works this way since 8.0

voleger’s picture

mondrake’s picture

Tagging "Needs framework manager review" as I think direction is needed here now.

mondrake’s picture

Title: Replace all calls to db_select, which is deprecated » [PP-1] Replace all calls to db_select, which is deprecated

Yes let's postpone.

mondrake’s picture

Status: Needs review » Postponed
voleger’s picture

longwave’s picture

#30 but that would practically mean that we are deprecating passing the 'target' key in the $options array, no? And creating a BC break.

Why is this a BC break? 'target' isn't currently supported anyway when called via the OO route, you have to explicitly specify the target when calling getConnection(). If not an error we could log a warning or a silenced error?

catch’s picture

Status: Postponed » Needs work
Issue tags: -Needs framework manager review

Unpostponing based on the discussion in #2947775: Move setting default target out of db_merge() and other deprecated db_* functions - using Database::getconnection() when you need to specify the target is fine for conversions.

voleger’s picture

longwave’s picture

Title: [PP-1] Replace all calls to db_select, which is deprecated » Replace all calls to db_select, which is deprecated
mondrake’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/tests/Drupal/KernelTests/Core/Database/SelectTest.php
@@ -258,11 +258,11 @@
    * that.
    */
   public function testUnion() {
-    $query_1 = $this->connection->select('test', 't')
+    $query_1 = db_select('test', 't')
       ->fields('t', ['name'])
       ->condition('age', [27, 28], 'IN');
 
-    $query_2 = $this->connection->select('test', 't')
+    $query_2 = db_select('test', 't')
       ->fields('t', ['name'])
       ->condition('age', 28);
 
@@ -281,11 +281,11 @@

@@ -281,11 +281,11 @@
    * Tests that we can UNION ALL multiple SELECT queries together.
    */
   public function testUnionAll() {
-    $query_1 = $this->connection->select('test', 't')
+    $query_1 = db_select('test', 't')
       ->fields('t', ['name'])
       ->condition('age', [27, 28], 'IN');
 
-    $query_2 = $this->connection->select('test', 't')
+    $query_2 = db_select('test', 't')
       ->fields('t', ['name'])
       ->condition('age', 28);
 

Strange it looks like in the interdiff these were reverted but it seems the patch is OK. Back to RTBC.

mondrake’s picture

Just confirming that applying the patch and checking with git grep db_select there are no more occurences in code. There's a bunch of leftover references in comments and in test messages but I suppose these can be addressed in a follow-up documentation issue.

andypost’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/search/src/Plugin/views/argument/Search.php
@@ -48,7 +49,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
+      $this->searchQuery = \Drupal::database('replica')->select('search_index', 'i')->extend(ViewsSearchQuery::class);

+++ b/core/modules/search/src/Plugin/views/filter/Search.php
@@ -120,7 +121,7 @@ public function validateExposed(&$form, FormStateInterface $form_state) {
+      $this->searchQuery = \Drupal::database('replica')->select('search_index', 'i')->extend(ViewsSearchQuery::class);

+++ b/core/modules/tracker/tracker.pages.inc
@@ -22,13 +22,13 @@
+    $query = \Drupal::database('replica')->select('tracker_node', 't')

This is no-go cos \Drupal::database() has no $target argument, so it needs to use other "factory"

mondrake’s picture

Title: Replace all calls to db_select, which is deprecated » [PP-2] Replace all calls to db_select, which is deprecated
Related issues: +#3000931: Connection::query() does not support 'target' option, +#3001216: Use the database.replica service where appropriate

This is postponed now.

mondrake’s picture

Status: Needs work » Postponed
catch’s picture

Title: [PP-2] Replace all calls to db_select, which is deprecated » Replace all calls to db_select, which is deprecated
Status: Postponed » Needs work

I don't think it needs to be postponed, we can use Database::getConnection() in the places that need it, then the database factory service issue can either convert or have a follow-up to convert those cases.

longwave’s picture

Changed replica connections to Database::getConnection() as per #48

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

catch’s picture

Status: Reviewed & tested by the community » Fixed
FileSize
552 bytes

Fixed this docs issue on commit, and pushed to 8.7.x, thanks! This issue flushed quite a lot of other issues out, see you in the follow-ups.

  • catch committed b48e1e7 on 8.7.x
    Issue #2873684 by voleger, longwave, jeetendrakumar, andypost, mondrake...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.