CommentFileSizeAuthor
#43 2848817-db_table_exists-42.patch10.59 KBvoleger
#43 interdiff-2848817-40-42.txt1.06 KBvoleger
#41 2848817-db_table_exists-40.patch10.42 KBvoleger
#37 interdiff-2848817-31-37.txt1.72 KBvoleger
#37 2848817-db_table_exists-37.patch12.11 KBvoleger
#3 drupal-replace-call-to-db_table_exists-2848817-2.patch476 bytespritamprasun
#7 interdiff-2848817-7.txt9.28 KBhgunicamp
#7 replace_all_calls_to-2848817-7.patch10.75 KBhgunicamp
#10 interdiff-2848817-10.txt8.58 KBhgunicamp
#10 replace_all_calls_to-2848817-10.patch9.91 KBhgunicamp
#15 replace_all_calls_to-2848817-15.patch9.97 KBJacobSanford
#15 interdiff-2848817-10-15.txt1.46 KBJacobSanford
#22 replace_all_db_table_exists_call-2848817-22-8.6.x.patch11.68 KBvoleger
#22 interdiff-2848817-15-22.txt1.49 KBvoleger
#25 replace_all_db_table_exists_call-2848817-25-8.6.x.patch11.65 KBvoleger
#25 interdiff-2848817-22-25.txt396 bytesvoleger
#28 2848817-28.patch12.82 KBandypost
#28 interdiff-2848817-25.txt6.46 KBandypost
#29 interdiff-2848817-28.txt437 bytesandypost
#29 2848817-29.patch12.87 KBandypost
#30 interdiff-2848817-29.txt2.53 KBandypost
#30 2848817-30.patch12.38 KBandypost
#31 2848817-interdiff30.txt961 bytesandypost
#31 2848817-31.patch12.25 KBandypost
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vidhatanand created an issue. See original summary.

vidhatanand’s picture

Issue summary: View changes
pritamprasun’s picture

vidhatanand’s picture

Status: Active » Needs review
JayKandari’s picture

Status: Needs review » Reviewed & tested by the community

#3 Looks good.
1 "db_table_exists()" call found in core/includes/schema.inc:137. Rest calls are in test files.

Thanks !

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

Read the meta issue carefully about test replacements.

hgunicamp’s picture

I'm sending a patch to replace the tests cases that use db_table_exists.

hgunicamp’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: replace_all_calls_to-2848817-7.patch, failed testing.

hgunicamp’s picture

Fixing my previous patch. Removing a wrong regression test.

Sharique’s picture

+++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
@@ -62,7 +62,7 @@ public function testSetUp() {
-    $this->assertFalse(db_table_exists($table), "'$table' database table not found.");

@@ -114,7 +114,7 @@ public function testEnableModulesInstall() {
+    $this->assertFalse(\Drupal::database()->schema()->tableExists($table), "'$table' database table not found.");

Instead use "Database::getConnection()->schema()->tableExists()" method,
check db_table_exists() implementation for details.

jeetendrakumar’s picture

@Sharique
I do not agree with you. "\Drupal::database()->schema()->tableExists($table)" will also work.

Sharique’s picture

To understand my point have a look at the implementation of db_table_exists here
https://api.drupal.org/api/drupal/core%21includes%21database.inc/functio...

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.

JacobSanford’s picture

@hgunicamp's patch in #10 no longer applied to 8.5.x. A reroll with no further modifications is attached.

JayKandari’s picture

Status: Needs work » Needs review

Changing status to review after #15.

The last submitted patch, 10: replace_all_calls_to-2848817-10.patch, failed testing. View results

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

Status: Needs review » Reviewed & tested by the community

Patch #15 still applies. Tested on 8.6.x
Looks good

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This patch should add an @trigger_error() to db_table_exists() so people can discover they need to replace the calls. See https://www.drupal.org/core/deprecation
This will also prove we've replaced all the usages in core.

alexpott’s picture

Will also need to add @group legacy and @expectedDeprecation ... to \Drupal\KernelTests\Core\Database\RegressionTest::testDBTableExists()

voleger’s picture

#20 #21 - added

apaderno’s picture

Status: Reviewed & tested by the community » Needs review
alexpott’s picture

Status: Needs review » Needs work
+++ b/core/includes/database.inc
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc

+++ b/core/includes/schema.inc
@@ -134,7 +134,7 @@ function drupal_uninstall_schema($module) {
   foreach ($schema as $table) {
-    if (db_table_exists($table['name'])) {
+    if (\Drupal::database()->schema()->tableExists($table['name'])) {
       db_drop_table($table['name']);
     }
   }

Instead of doing this we could do:

diff --git a/core/includes/schema.inc b/core/includes/schema.inc
index 443cbf1934..06864db44a 100644
--- a/core/includes/schema.inc
+++ b/core/includes/schema.inc
@@ -5,6 +5,8 @@
  * Schema API handling functions.
  */
 
+use Drupal\Core\Database\Database;
+
 /**
  * @addtogroup schemaapi
  * @{
@@ -133,8 +135,9 @@ function drupal_uninstall_schema($module) {
   $schema = drupal_get_module_schema($module);
   _drupal_schema_initialize($schema, $module, FALSE);
 
+  $database_schema = Database::getConnection()->schema();
   foreach ($schema as $table) {
-    if (db_table_exists($table['name'])) {
+    if ($database_schema->tableExists($table['name'])) {
       db_drop_table($table['name']);
     }
   }

But also weirdly the whole table exists check is not necessary. Every single db_drop_table() implementation does a table exists check so we are duplicating the query unnecessarily. This weird. I don't think db_drop_table should check existence. But doing the query twice is just wasteful. And the non-failure for table not existing is part of the API for drop table.

  /**
   * Drop a table.
   *
   * @param $table
   *   The table to be dropped.
   *
   * @return
   *   TRUE if the table was successfully dropped, FALSE if there was no table
   *   by that name to begin with.
   */
  abstract public function dropTable($table);

So tldr; let's just remove the check.

voleger’s picture

voleger’s picture

Status: Needs work » Needs review
voleger’s picture

Tests are green. So, back to RTBC?

andypost’s picture

Reroll + Patch moves service fetching out of loops, I bet now patch ready to go

PS: Looking at RegressionTest.php I gonna file follow-up to refactor it or maybe there's one already...

  1. +++ b/core/includes/schema.inc
    @@ -134,9 +134,7 @@ function drupal_uninstall_schema($module) {
    -    if (db_table_exists($table['name'])) {
    -      db_drop_table($table['name']);
    -    }
    +    db_drop_table($table['name']);
    

    cos patch does change that line makes sense to clean-up it as #24 said

  2. +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
    @@ -156,7 +156,7 @@ public function testInstallSchema() {
    +    $this->assertTrue(\Drupal::database()->schema()->tableExists($table), "'$table' database table found.");
    
    @@ -171,7 +171,7 @@ public function testInstallSchema() {
    +    $this->assertFalse(\Drupal::database()->schema()->tableExists($table), "'$table' database table not found.");
    
    @@ -185,14 +185,14 @@ public function testInstallSchema() {
    +    $this->assertFalse(\Drupal::database()->schema()->tableExists($table), "'$table' database table not found.");
    ...
    +    $this->assertTrue(\Drupal::database()->schema()->tableExists($table), "'$table' database table found.");
    
    @@ -206,7 +206,7 @@ public function testInstallEntitySchema() {
    +    $this->assertTrue(\Drupal::database()->schema()->tableExists($entity), "'$entity' database table found.");
    

    all ones inside one function in kernel test, I thought they needs common method or variable as @alexpott pointed for old function

    But then it's clear that modules [un]install rebuilds container so we can't store nether schema no Database service so fine

andypost’s picture

FileSize
437 bytes
12.87 KB

And better to have this comment instead of check

andypost’s picture

FileSize
2.53 KB
12.38 KB

Oh this functions were deprecated on 8.0.x so revert version

andypost’s picture

FileSize
12.25 KB
961 bytes

annotation better to stick per method to prevent collision with other patches

apaderno’s picture

Status: Needs review » Needs work
+  @trigger_error(
+    "Deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call tableExists() on it. For example, \$injected_database->schema()->tableExists(\$table);",

The trigger message should be similar to the following one (https://www.drupal.org/core/deprecation).

@trigger_error('baz() is deprecated in Drupal 8.3.0 and will be removed before Drupal 9.0.0. Use \Drupal\Foo\Bar::baz() instead. See http://drupal.org/node/the-change-notice-nid.');
  • The message should report the function that is deprecated
  • The Drupal version should be 8.6.0, not 8.0.x
  • The message should report the full-qualified name of the class to use
  • Every other details should be given in a change record the message links
andypost’s picture

Status: Needs work » Needs review

This functions were deprecated before 8.0, so we just add triggering error here

voleger’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

It would be great is there was a CR to link to be there does not appear to be. Re #32 is correct that the format of the deprecation message is not quite right. See the other deprecation in this file:
@trigger_error('db_set_active() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2944084.', E_USER_DEPRECATED);
So let's take the opportunity to repurpose the linked CR to be about all the deprecated methods in database.inc and then link it from this @trigger_error. That will help all the related issues too.

voleger’s picture

voleger’s picture

Status: Needs work » Needs review
FileSize
12.11 KB
1.72 KB

Changed deprecation message.

andypost’s picture

Sure it needs broader change record about all db_* functions cos it's missing since 8.0 release

I filed #2947946: Create change record for all deprecated db_* functions to identify main troubles on a way to iterate with db layer, actually 2 blockers - missing CR & performance impact from additional @trigger_error, bonus is "default target" #2947775: Move setting default target out of db_merge() and other deprecated db_* functions

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

Reverted changes in SchemaTest. See #2987856: Followup: Update Schema test.
Rerolled.

voleger’s picture

Status: Needs review » Needs work

The last submitted patch, 41: 2848817-db_table_exists-40.patch, failed testing. View results

voleger’s picture

Status: Needs work » Needs review
FileSize
1.06 KB
10.59 KB
andypost’s picture

Looks great to go, but needs one more pair of eye on it

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Second pair of eyes to confirm.

I tested this with $ ag "db_table_exists" and the only remaining mentions are in database.inc and in the RegressionTest.

The last submitted patch, 37: 2848817-db_table_exists-37.patch, failed testing. View results

The last submitted patch, 37: 2848817-db_table_exists-37.patch, failed testing. View results

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Giving issue credit to all comments that helped move this issue along.

Also committed to 8.6.x as there is no risk in the single runtime change and I think maintaining out-of-sync tests for the 8.6.x / 8.7.x cycle is more costly.

Committed and pushed 27bc1f74cb to 8.7.x and 6173d84367 to 8.6.x. Thanks!

  • alexpott committed 27bc1f7 on 8.7.x
    Issue #2848817 by voleger, andypost, hgunicamp, JacobSanford, techtud,...

  • alexpott committed 6173d84 on 8.6.x
    Issue #2848817 by voleger, andypost, hgunicamp, JacobSanford, techtud,...
mondrake’s picture

I find confusing to use the RegressionTest class for deprecation tests. Here the testDbTableExist method has been changed to track deprecation, which means AFAICS that it will be dropped in 9.0 when the wrappers will be remived frin code. But that test is pre-existing and should not be dropped.

I suggest adding a LegacyTest class for deprecation tests only, and move the tests already coded there.

alexpott’s picture

@mondrake nice spot - can you create a issue to do that?

alexpott’s picture

@mondrake actually only the methods marked with @legacy will be dropped and I think that is okay since \Drupal\KernelTests\Core\Database\SchemaTest tests the actual methods. I agree we need to be careful not to remove \Drupal\KernelTests\Core\Database\RegressionTest::testRegression_310447 but that is not marked with @legacy. So moving the other methods to a legacy test is probably a good idea but what's happened here is not wrong - it just can be better.

voleger’s picture

mondrake’s picture

Status: Fixed » Closed (fixed)

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

quietone’s picture

publish change record