Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is because the Upsert::preExecute() method is protected.
If you use the upsert method and try to see the query with the devel function dpq() you get one error.
$query = $this->connection->upsert('forcontu_database_counter')
->fields([
'route' => $route,
'uid' => $uid,
'user_count' => 1,
'lastcount' => time(),
]);
$query->key('route');
$query->execute();
dpq($query);
Error: Call to protected method Drupal\Core\Database\Query\Upsert::preExecute() from context '' in dpq() (line 419 of /Users/adriancid/Sites/drupal82-test/modules/devel/devel.module) #0
But if you set to public the preExecute method you will see:
Error: Call to undefined method Drupal\Core\Database\Driver\mysql\Upsert::arguments() in dpq() (line 424 of /Users/adriancid/Sites/drupal82-test/modules/devel/devel.module) #0
Comment | File | Size | Author |
---|---|---|---|
#6 | devel-dpq-upsert-support-2847155-6-D8.patch | 933 bytes | jackson.cooper |
Comments
Comment #2
Znak CreditAttribution: Znak commentedComment #3
Znak CreditAttribution: Znak commentedYou are using this method in your custom module or theme?
Comment #4
adriancidcustom module, with the select and the update works fine
Comment #5
willzyx CreditAttribution: willzyx commentedComment #6
jackson.cooper CreditAttribution: jackson.cooper as a volunteer commentedThe method_exists() call can't simply be updated to is_callable(), because the Upsert class doesn't have an arguments() method. It does have a __toString() method that returns the query however. Here's a patch which casts the object to a string, if the __toString() method is callable.
Comment #7
lussolucaWe should have a test for this
Comment #8
willzyx CreditAttribution: willzyx commentedComment #9
moshe weitzman CreditAttribution: moshe weitzman commentedThis issue has moved to https://gitlab.com/drupalspoons/devel/-/issues/281