CommentFileSizeAuthor
#56 interdiff_53-55.txt1.46 KBmondrake
#56 2848952-55.patch16.41 KBmondrake
#54 interdiff_50-53.txt14.26 KBmondrake
#53 interdiff_50-53.txt16.25 KBmondrake
#53 2848952-53.patch16.25 KBmondrake
#50 2848952-db_merge-50.patch15.41 KBshashikant_chauhan
#46 interdiff-2848952-45-46.txt544 bytesvoleger
#46 2848952-db_merge-46.patch14.85 KBvoleger
#45 2848952-db_merge-45.patch14.85 KBvoleger
#45 interdiff-2848952-44-45.txt3.02 KBvoleger
#44 interdiff-37-44.txt4.58 KBpiggito
#44 2848952-db_merge-44.patch13.13 KBpiggito
#42 interdiff-2848817-39-42.txt4.17 KBvoleger
#42 2848817-db_table_exists-42.patch16.42 KBvoleger
#39 interdiff-2848817-37-39.txt521 bytesvoleger
#39 2848817-db_table_exists-39.patch12.75 KBvoleger
#37 interdiff-2848952-35-37.txt3.35 KBvoleger
#37 2848952-db_merge-37.patch8.7 KBvoleger
#35 2848952-db_merge-34.patch12.62 KBandypost
#35 2848952-interdiff-33.patch934 bytesandypost
#33 2848952-33.patch12.7 KBandypost
#33 2848952-interdiff-32.txt480 bytesandypost
#32 2848952-32.patch12.6 KBandypost
#32 2848952-interdiff-25.txt7.33 KBandypost
#25 interdiff-2848952-20-25.txt2.13 KBpk188
#25 replace_all_calls_to-2848952-25.patch9.63 KBpk188
#22 interdiff.txt381 bytesjeetendrakumar
#20 replace_all_calls_to-2848952-20.patch11.46 KBjeetendrakumar
#18 interdiff.txt2.13 KBjeetendrakumar
#18 replace_all_calls_to-2848952-18.patch11.45 KBjeetendrakumar
#16 replace_all_calls_to-2848952-16.patch9.68 KBhgunicamp
#16 interdiff-2848952-16.txt1.38 KBhgunicamp
#8 db_merge-2848952-8.patch9.65 KBdaffie
#4 replace_all_calls_to-2848952-4.patch7.39 KBjaykandari

Comments

JayKandari created an issue. See original summary.

jaykandari’s picture

Status: Needs work » Active
jaykandari’s picture

Title: Replace all calls to db_update, which is deprecated » Replace all calls to db_merge, which is deprecated
jaykandari’s picture

Assigned: jaykandari » Unassigned
Status: Active » Needs review
StatusFileSize
new7.39 KB
gaurav.kapoor’s picture

Status: Needs review » Reviewed & tested by the community

#4 solves the problem.Thanks

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

The meta issue reads: "...replace all usages of the function (except tests for the function itself)...". GarbageCollectionTest calls it.

xjm’s picture

Issue tags: +DrupalCampNJ2017
daffie’s picture

Status: Needs work » Needs review
StatusFileSize
new9.65 KB

This patch is originally written by @Pavan_B_S in #2856714-4: Replace all calls to db_merge, which is deprecated. So please give him credit for it.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

I have reviewed the patch from @Pavan_B_S in #2856714-5: Replace all calls to db_merge, which is deprecated and I came to the following conclusion:

All calls to db_merge() have been replaced.
The function has already been marked as deprecated.
There are no code references in D8.
The patch is RTBC for me.

daffie’s picture

Almost forgot: @chiranjeeb2410 created an interdiff.txt file for a patch. So he should also get a credit.

xjm credited Pavan B S.

xjm credited chiranjeeb.

xjm’s picture

xjm’s picture

Title: Replace all calls to db_merge, which is deprecated » Replace all calls to db_merge(), which is deprecated
Status: Reviewed & tested by the community » Needs review

Thanks everyone for working on this!

+++ b/core/tests/Drupal/KernelTests/Core/Database/MergeTest.php
@@ -18,7 +18,7 @@ class MergeTest extends DatabaseTestBase {
-    $result = db_merge('test_people')
+    $result = \Drupal::database()->merge('test_people')

@@ -201,7 +201,7 @@ function testInvalidMerge() {
-      db_merge('test_people', $options)
+      \Drupal::database()->merge('test_people', $options)

So, this and other calls in MergeTest are the tests for db_merge(), which does not actually exactly wrap the same service. That would be beyond the scope of not removing the self-tests. If it were a thin wrapper that would be one thing, but not much is testing the $options parameter, which is set to a different default in the procedural function:

  if (empty($options['target']) || $options['target'] == 'replica') {
    $options['target'] = 'default';
  }

I'm not sure how to handle that.

xjm’s picture

I think if this patch were completing the scope defined on the issue, it would not change the merge tests.

Here is the code related to the target in getConnection():

  // If the requested target does not exist, or if it is ignored, we fall back
  // to the default target. The target is typically either "default" or
  // "replica", indicating to use a replica SQL server if one is available. If
  // it's not available, then the default/primary server is the correct server
  // to use.
  if (!empty(self::$ignoreTargets[$key][$target]) || !isset(self::$databaseInfo[$key][$target])) {
    $target = 'default';
  }

So it could be that the hunk in db_merge() is just redundant anyway.

The question is whether we should remove all test coverage for db_merge(). I'm hesitant about that, so we could remove the MergeTest changes from this patch and discuss how to handle the testing in a followup. I don't think the correct way for Connection::merge() to be tested would be getting the service from the container so the followup should check whether it already has separate tests. We can and still should remove the others in this patch, though.

Thanks!

hgunicamp’s picture

Issue tags: +ciandt-contrib
StatusFileSize
new1.38 KB
new9.68 KB

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

cilefen’s picture

Status: Needs review » Needs work

Thank you for the continued work everyone.

+++ b/core/modules/shortcut/src/ShortcutSetStorage.php
@@ -71,7 +71,7 @@ public function deleteAssignedShortcutSets(ShortcutSetInterface $entity) {
-    db_merge('shortcut_set_users')
+    \Drupal::database()->merge('shortcut_set_users')

I think we need to inject the dependency.

jeetendrakumar’s picture

Status: Needs work » Needs review
StatusFileSize
new11.45 KB
new2.13 KB

As per comment #17 updated patch file.

tstoeckler’s picture

Status: Needs review » Needs work

Looks very nice, thanks!

I found one nitpick:

+++ b/core/modules/shortcut/src/ShortcutSetStorage.php
@@ -22,6 +23,13 @@ class ShortcutSetStorage extends ConfigEntityStorage implements ShortcutSetStora
+  ¶

Trailing whitespace.

jeetendrakumar’s picture

Status: Needs work » Needs review
StatusFileSize
new11.46 KB

Please find updated patch file.

cilefen’s picture

@jeetendrakumar Would you please post the interdiff on #20?

jeetendrakumar’s picture

StatusFileSize
new381 bytes

interdiff on #20

pk188’s picture

Status: Needs review » Reviewed & tested by the community

I applied the patch in #22. It applied cleanly and changes all the occurences.

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

Thank you for working on this everyone! I have some notes and suggestions for getting this one finished:

  • I asked for a constructor injection in #17, which was done quite properly by @jeetendrakumar in #18. But I was in error when I asked for it. The parent issue specifies "Open follow-up issues to inject dependencies as appropriate" and the Issue Scope Guidelines cite a similar change as an example of "bad scope".
  • Would a contributor please remove the injection in ShortcutSetStorage from this patch and return it to the static call?
  • Would a contributor please open a follow-up issue that is stalled on this issue to inject the dependency in ShortcutSetStorage?

Sorry for the confusion.

pk188’s picture

Status: Needs work » Needs review
StatusFileSize
new9.63 KB
new2.13 KB

Fixed #24.

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.

borisson_’s picture

Component: search.module » database system
Status: Needs review » Reviewed & tested by the community

This doesn't belong in the search.module component, I think database system is a better match.

The patch does apply, and it replaces all the calls to db_merge - the only remaining place where I can find it is in database.inc after applying the patch.

xjm’s picture

Issue tags: +Needs followup

My review in #14 is still not addressed. We also still need the followup in #24.

Thanks!

xjm’s picture

Status: Reviewed & tested by the community » Needs work

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.

andypost’s picture

Assigned: Unassigned » andypost
Issue tags: -Needs followup

Filed postponed follow-up for #14-#24 #2947769: Inject services after replacing all calls for db_merge()

Also db_merge() should trigger error like #2820179-18: Replace usages of deprecated method db_change_field(), working on it

andypost’s picture

Assigned: andypost » Unassigned
Status: Needs work » Needs review
StatusFileSize
new7.33 KB
new12.6 KB

Patch
- moves database connection service retrieval out of loops
- adds triggering deprecated error
- adds test for deprecated error
- adds todos to filed issues

Filed second follow-up for #14.2 #2947775: Move setting default target out of db_merge() and other deprecated db_* functions

andypost’s picture

StatusFileSize
new480 bytes
new12.7 KB

According #2820179-18: Replace usages of deprecated method db_change_field() test class should be annotated as @group legacy

The last submitted patch, 32: 2848952-32.patch, failed testing. View results

andypost’s picture

StatusFileSize
new934 bytes
new12.62 KB

annotation per method is a way

The last submitted patch, 35: 2848952-interdiff-33.patch, failed testing. View results

voleger’s picture

StatusFileSize
new8.7 KB
new3.35 KB

Addressing #14.1 - we should not make any changes in the self-tests as it defined in the parent issue.

Status: Needs review » Needs work

The last submitted patch, 37: 2848952-db_merge-37.patch, failed testing. View results

voleger’s picture

StatusFileSize
new12.75 KB
new521 bytes

Added expectedDeprecation for the legacy test.

voleger’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

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

voleger’s picture

Status: Needs work » Needs review
StatusFileSize
new16.42 KB
new4.17 KB

Oops. My bad

Status: Needs review » Needs work

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

piggito’s picture

Status: Needs work » Needs review
StatusFileSize
new13.13 KB
new4.58 KB

It seems like @voleger mixed up patch with changes for issue 2848817
I added expectedDeprecation annotation for legacy test using patch in #37 as baseline since this was the last not-mixed patch.

voleger’s picture

StatusFileSize
new3.02 KB
new14.85 KB

Added the possibility to reuse added database connection in further db_* function replacements.

voleger’s picture

StatusFileSize
new14.85 KB
new544 bytes

missed one replacement

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

+++ b/core/tests/Drupal/KernelTests/Core/Database/MergeTest.php
@@ -9,11 +9,14 @@
+ * @group legacy
...
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -39,6 +42,8 @@ public function testMergeInsert() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -67,6 +72,8 @@ public function testMergeUpdate() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -88,6 +95,8 @@ public function testMergeUpdateExcept() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -114,6 +123,8 @@ public function testMergeUpdateExplicit() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -143,6 +154,8 @@ public function testMergeUpdateExpression() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -162,6 +175,8 @@ public function testMergeInsertWithoutUpdate() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

@@ -194,6 +209,8 @@ public function testMergeUpdateWithoutUpdate() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);

+++ b/core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
@@ -59,6 +60,17 @@ public function testDBIndexExists() {
+   * @expectedDeprecation 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 and call merge() on it. For example, $injected_database->merge($table, $options);
+   */
+  public function testDBMergeIsDeprecated() {
+    $this->assertTrue(db_merge('test') instanceof Merge);

Why not move this to DatabaseLegacyTest.php and replace usage in MergeTest.php

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

patch does not apply

shashikant_chauhan’s picture

Status: Needs work » Needs review
StatusFileSize
new15.41 KB

Rerolled the patch.

andypost’s picture

Issue tags: -Needs reroll
mondrake’s picture

Assigned: Unassigned » mondrake
Status: Needs review » Needs work

NW to address #48. Working on it.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
StatusFileSize
new16.25 KB
new16.25 KB

Addressed #48, injected the db connection in ShortcutSetStorage.

This should be more or less ready - GarbageCollectionTest was using Database::getConnection() already; if that needs to be changed it will be done by a follow up of #2991337: Document the recommended ways to obtain the database connection object.

mondrake’s picture

StatusFileSize
new14.26 KB

Sorry wrong interdiff in #53, this should be ok.

Status: Needs review » Needs work

The last submitted patch, 53: 2848952-53.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new16.41 KB
new1.46 KB

$this->assertSame is strict on type.

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

The last submitted patch, 46: 2848952-db_merge-46.patch, failed testing. View results

  • catch committed 44b3b41 on 8.7.x
    Issue #2848952 by voleger, andypost, mondrake, jeetendrakumar, pk188,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 44b3b41 and pushed to 8.7.x. Thanks!

andypost’s picture

Status: Fixed » Needs review
+++ b/core/tests/Drupal/KernelTests/Core/Database/DatabaseLegacyTest.php
@@ -172,4 +171,22 @@ public function testDbCreateTable() {
+    $result = db_merge('test_people')
+      ->key('job', 'Presenter')
+      ->fields([
+        'age' => 31,
+        'name' => 'Tiffany',
+      ])
+      ->execute();

I'm sure it needs follow-up to change test to "instanceOf" assertion because we must test that this function returns declared object - but instead it tests that object works!
For that purpose we have DB api tests)

mondrake’s picture

#61: umm... how about to have both assertInstanceOf and the result of the operation? I think here it is not bad for contrib drivers to go through the actual operation.

andypost’s picture

Contrib db drivers has own testing for driver classes anyway, so IMO no reason to test what driver class does cos it's it totally different test

mondrake’s picture

Status: Needs review » Fixed

  • catch committed ac6cf4c on 8.7.x
    Issue #2994955 by andypost, mondrake: Followup to #2848952 - fix...

Status: Fixed » Closed (fixed)

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