CommentFileSizeAuthor
#37 2848479-32-37.txt1.38 KBvoleger
#37 replace_all_db_drop_table_calls-2848479-37.patch6.05 KBvoleger
#32 replace_all_db_drop_table_calls-2848479-32.patch6.06 KBvoleger
#32 interdiff-2848479-28-32.txt19 bytesvoleger
#29 interdiff-2848479-22-28.txt4.35 KBvoleger
#28 replace_all_db_drop_table_calls-2848479-28.patch6.29 KBvoleger
#23 interdiff-2848479-20-22.txt3.59 KBvoleger
#22 interdiff-2848479-20-22.txt4.89 KBvoleger
#22 replace_all_db_drop_table_calls-2848479-22.patch1.57 KBvoleger
#20 replace_all_db_drop_table_calls-2848479-20.patch3.48 KBvoleger
#19 replace_all_db_drop_table_calls-2848479-19.patch33.57 KBvoleger
#15 replace_all_calls_to-2848479-15.patch3.48 KBhgunicamp
#12 interdiff-2848479-9-12.txt669 bytesyogeshmpawar
#12 replace_all_calls_to-2848479-12.patch2.56 KByogeshmpawar
#9 replace_all_calls_to-2848479-8.patch2.93 KByogeshmpawar
#8 interdiff-2848479-6-8.txt1.95 KByogeshmpawar
#8 replace_all_calls_to-2848479-8.patch2.93 KByogeshmpawar
#6 drupal-replacing-db_drop_table-with-new-syntax-2848479-6.patch1000 bytesmarvin_B8
#6 interdiff-2848479-2-6.txt536 bytesmarvin_B8
#2 drupal-replacing-db_drop_table-with-new-syntax-2848479-2.patch999 bytesgaurav.kapoor
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gaurav.kapoor created an issue. See original summary.

gaurav.kapoor’s picture

All the calls to db_drop_table replaced with new syntax.

cilefen’s picture

Category: Bug report » Task
Issue summary: View changes
Status: Active » Needs review
Parent issue: » #2848161: [meta] Replace calls to deprecated db_*() wrappers

Thank you! Link the parent issue when you make these, please. They are tasks, not bugs.

JayKandari’s picture

Status: Needs review » Reviewed & tested by the community

2 instances of "db_drop_table()" found in following:

core/includes/schema.inc:138:      db_drop_table($table['name']);
core/modules/simpletest/simpletest.module:672:      db_drop_table($matches[0]);

patch #2 covers both of them. Looks good!

Thanks !

cilefen’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/simpletest/simpletest.module
@@ -669,7 +669,7 @@ function simpletest_clean_database() {
-      db_drop_table($matches[0]);
+     \Drupal::database()->schema()->dropTable($matches[0]);

nitpick - the line indentation is wrong.

marvin_B8’s picture

daffie’s picture

Status: Needs review » Needs work

@marvin_B8: You forgot to replace some instances in Drupal\KernelTests\Core\Database\SchemaTest

yogeshmpawar’s picture

Updated patch as per comment #7 & also added interdiff.

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
2.93 KB

Same patch with added tests against 8.4.x branch.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes are good.
All instances of the usage of db_drop_table() are replaced.
The patch looks good to me.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -117,7 +117,7 @@ function testSchema() {
-    db_drop_table('test_table2');
+    \Drupal::database()->schema()->dropTable('test_table2');

At least this is the self-test of the function. The whole thing is the test for the schema. So I think we should leave the usages here and discuss what to do with it in phase 2 of this cleanup initiative.

Thanks!

yogeshmpawar’s picture

Status: Needs work » Needs review
FileSize
2.56 KB
669 bytes

Thanks @xjm, as per your comment #11 i have updated the patch & added a interdiff also.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

This is what @xjm wants. Back to RTBC.

xjm’s picture

Status: Reviewed & tested by the community » Needs review

This is what @xjm wants. Back to RTBC.

lol, that in itself is not the criterion for RTBC. :) I am often wrong. If you disagree it's always worth adding why.

However, what I was getting at in #11 is that it feels awkward and wrong to use \Drupal::database() in SchemaTest (that's the "whole thing" I was referring to; sorry for being ambiguous). We shouldn't be going to static methods on \Drupal to the container to the service to the class in order to test the class. This applies to numerous of these patches. So, my thought is that it would be better to create a single followup for updating the DB tests (especially SchemaTest) and discuss the best approach.

Again, though, I could be wrong. :)

hgunicamp’s picture

I have fixed the 'replace_all_calls_to-2848479-12.patch' patch because it was not applying any more because 'array()' notation has already been applied in the files affected by the patch.

hgunicamp’s picture

Issue tags: +ciandt-contrib

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

Reroll for 8.6.x
Patch is pretty small, so it could be ready to go.
+1 RTBC

voleger’s picture

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.

voleger’s picture

voleger’s picture

FileSize
3.59 KB

Upload the correct interdiff

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Used $schema instance in separate variable because we have another functions to replace that will use $schema instance

Nice!

Looks good to me, RTBC.

The last submitted patch, 20: replace_all_db_drop_table_calls-2848479-20.patch, failed testing. View results

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Can we add a deprecation trigger_error() - see db_set_active() for an example.

alexpott’s picture

Wrt to SchemaTest we can replace the calls to drop_table() with Database::getConnection()->schema()->dropTable() -we're already using Database::getConnection() in that test and its fine since refactoring the Database static is really not in scope of this work or any other of the remove usages of db_* functions.

voleger’s picture

Status: Needs work » Needs review
FileSize
6.29 KB

Added change notice https://www.drupal.org/node/2987737
Added Regression test.
Added replacements in the Schema tests.

voleger’s picture

FileSize
4.35 KB

Status: Needs review » Needs work

The last submitted patch, 28: replace_all_db_drop_table_calls-2848479-28.patch, failed testing. View results

mondrake’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -71,4 +71,18 @@ public function testDBIsActive() {
+  /**
+   * Tests the db_create_table() and db_drop_table() function.
+   *
+   * @group legacy
+   *
+   * @expectedDeprecation db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737
+   */
+  public function testDBCreateDropTable() {
+    $table = 'temp_test_table';
+    db_create_table($table, []);
+    $this->assertTrue(db_drop_table($table));
+    $this->assertFalse(db_drop_table($table));
+  }
+

I think it would be enough just to test db_drop_table on a non-existing table - we are just testing that the deprecation exception is thrown here, and dropTable implementations take care of returning FALSE if the table is missing.

Also, in the SchemaTest class I think it would make sense to have the $connection and the $schema variables as class properties, initialised at setup, instead of figuring out in each method. Only the testFindTables test is playing around with the connection in this test class, and it could be managed as a special case. AFAICS all the other tests just use the connection set up for the Kernel test. But out of this issue's scope.

voleger’s picture

Thank's for the review @mondrake

alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
    @@ -71,4 +71,15 @@ public function testDBIsActive() {
    +   * Tests the db_create_table() and db_drop_table() function.
    

    db_create_table() is no longer tested.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
    @@ -71,4 +71,15 @@ public function testDBIsActive() {
    +   * @expectedDeprecation db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737
    +   */
    +  public function testDBCreateDropTable() {
    +    $this->assertFalse(db_drop_table('temp_test_table'));
    +  }
    

    +1

  3. +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
    @@ -23,6 +23,27 @@ class SchemaTest extends KernelTestBase {
    +
    +  protected function setUp() {
    +    parent::setUp();
    +    $this->connection = $this->container->get('database');
    +    $this->schema = $this->connection->schema();
    +  }
    

    I like it +1

    But needs a {@inheritdoc}

mondrake’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -71,4 +71,15 @@ public function testDBIsActive() {
+  /**
+   * Tests the db_create_table() and db_drop_table() function.
+   *
+   * @group legacy
+   *
+   * @expectedDeprecation db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737
+   */
+  public function testDBCreateDropTable() {
+    $this->assertFalse(db_drop_table('temp_test_table'));

Both docblock and test method name need to be updated as table is no longer created.

@voleger interdiff in #32 is incorrect

mondrake’s picture

Also, nitpick - testDBCreateDropTable(): according to CS should be 'testDb*' with lower 'b'. So in this case just testDbDropTable.

mondrake’s picture

+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -23,6 +23,27 @@ class SchemaTest extends KernelTestBase {
+  /**
+   * Database schema instance.
+   *
+   * @var \Drupal\Core\Database\Schema
+   */
+  protected $schema;
+
+  protected function setUp() {
+    parent::setUp();
+    $this->connection = $this->container->get('database');
+    $this->schema = $this->connection->schema();
+  }
+
+

There's an extra white line before next method. Also, I suggest to use

    $this->connection = Database::getConnection();

instead of the container - that's how DatabaseTestBase initialises the connection property, and how it is setup in KernelTestBase.

(Sorry for feedback in bits and pieces)

voleger’s picture

@mondrake np, it's ok. I really happy to see that the db_* replacement issues has some attention from reviewers.

Addressed #33, #34, #35, #36

voleger’s picture

Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -23,6 +23,30 @@ class SchemaTest extends KernelTestBase {
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $this->connection = Database::getConnection();
+    $this->schema = $this->connection->schema();
+  }
+
+

There is still a double newline after the setUp method, but I think it's RTBC now, it could be fixed on commit.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Can someone file a quick issue to change just SchemaTest to use the new protected properties as that will make the rest of go much quicker. Thanks!

Committed and pushed ead36d31b8 to 8.7.x and ab302cc34c to 8.6.x. Thanks!

voleger’s picture

Created followup: #2987856: Followup: Update Schema test

I had tried to pull the latest changes but not saw changes in SchemaTest.
Wondering, would those ead36d31b8 and ab302cc34c commits be available in the near future?

  • alexpott committed ead36d3 on 8.7.x
    Issue #2848479 by voleger, yogeshmpawar, marvin_B8, gaurav.kapoor,...

  • alexpott committed ab302cc on 8.6.x
    Issue #2848479 by voleger, yogeshmpawar, marvin_B8, gaurav.kapoor,...
alexpott’s picture

@voleger oops pushed now. Sorry.

Status: Fixed » Closed (fixed)

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