diff -u b/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php --- b/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -1202,10 +1202,10 @@ */ function hook_entity_delete(Drupal\Core\Entity\EntityInterface $entity) { // Delete the entity's entry from a fictional table of all entities. - $query = \Drupal::database()->delete('example_entity'); - $query->condition('type',$entity->getEntityTypeId()); - $query->condition('id',$entity->id()); - $query->execute(); + \Drupal::database()->delete('example_entity') + ->condition('type', $entity->getEntityTypeId()) + ->condition('id', $entity->id()) + ->execute(); } /** @@ -1221,10 +1221,10 @@ */ function hook_ENTITY_TYPE_delete(Drupal\Core\Entity\EntityInterface $entity) { // Delete the entity's entry from a fictional table of all entities. - $query = \Drupal::database()->delete('example_entity'); - $query->condition('type',$entity->getEntityTypeId()); - $query->condition('id',$entity->id()); - $query->execute(); + \Drupal::database()->delete('example_entity') + ->condition('type', $entity->getEntityTypeId()) + ->condition('id', $entity->id()) + ->execute(); } /** reverted: --- b/core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php +++ a/core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php @@ -83,7 +83,7 @@ $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')->fetchField(); $this->assertEqual($before, $after, 'No feeds were added during the two last form submissions.'); + db_delete('aggregator_feed')->execute(); - \Drupal::database()->delete('aggregator_feed')->execute(); $feeds[0] = $this->getFeedEditArray(); $feeds[1] = $this->getFeedEditArray(); diff -u b/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module --- b/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -73,9 +73,9 @@ // Delete all table entries older than the nth row, if nth row was found. if ($min_row) { - $query = \Drupal::database()->delete('watchdog'); - $query->condition('wid', $min_row, '<'); - $query->execute(); + \Drupal::database()->delete('watchdog') + ->condition('wid', $min_row, '<') + ->execute(); } } } reverted: --- b/core/modules/dblog/src/Tests/DbLogTest.php +++ a/core/modules/dblog/src/Tests/DbLogTest.php @@ -602,7 +602,7 @@ $this->drupalLogin($this->adminUser); // Clear the log to ensure that only generated entries will be found. + db_delete('watchdog')->execute(); - \Drupal::database()->delete('watchdog')->execute(); // Generate 9 random watchdog entries. $type_names = []; diff -u b/core/modules/field/field.api.php b/core/modules/field/field.api.php --- b/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -283,9 +283,9 @@ * The field storage being purged. */ function hook_field_purge_field_storage(\Drupal\field\Entity\FieldStorageConfig $field_storage) { - $query = \Drupal::database()->delete('my_module_field_storage_info'); - $query->condition('uuid', $field_storage->uuid()); - $query->execute(); + \Drupal::database()->delete('my_module_field_storage_info') + ->condition('uuid', $field_storage->uuid()) + ->execute(); } /** @@ -300,9 +300,9 @@ * The field being purged. */ function hook_field_purge_field(\Drupal\field\Entity\FieldConfig $field) { - $query = \Drupal::database()->delete('my_module_field_info'); - $query->condition('id', $field->id()); - $query->execute(); + \Drupal::database()->delete('my_module_field_info') + ->condition('id', $field->id()) + ->execute(); } /** diff -u b/core/modules/history/history.module b/core/modules/history/history.module --- b/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -124,9 +124,9 @@ * Implements hook_cron(). */ function history_cron() { - $query = \Drupal::database()->delete('history'); - $query->condition('timestamp', HISTORY_READ_LIMIT, '<'); - $query->execute(); + \Drupal::database()->delete('history') + ->condition('timestamp', HISTORY_READ_LIMIT, '<') + ->execute(); } /** @@ -151,9 +151,9 @@ * Implements hook_ENTITY_TYPE_delete() for node entities. */ function history_node_delete(EntityInterface $node) { - $query = \Drupal::database()->delete('history'); - $query->condition('nid', $node->id()); - $query->execute(); + \Drupal::database()->delete('history') + ->condition('nid', $node->id()) + ->execute(); } /** @@ -162,9 +162,9 @@ function history_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': - $query = \Drupal::database()->delete('history'); - $query->condition('uid', $account->id()); - $query->execute(); + \Drupal::database()->delete('history') + ->condition('uid', $account->id()) + ->execute(); break; } } @@ -173,9 +173,9 @@ * Implements hook_ENTITY_TYPE_delete() for user entities. */ function history_user_delete($account) { - $query = \Drupal::database()->delete('history'); - $query->condition('uid', $account->id()); - $query->execute(); + \Drupal::database()->delete('history') + ->condition('uid', $account->id()) + ->execute(); } /** diff -u b/core/modules/path/path.api.php b/core/modules/path/path.api.php --- b/core/modules/path/path.api.php +++ b/core/modules/path/path.api.php @@ -56,9 +56,9 @@ * @see \Drupal\Core\Path\PathInterface::delete() */ function hook_path_delete($path) { - $query = \Drupal::database()->delete('mytable'); - $query->condition('pid', $path['pid']); - $query->execute(); + \Drupal::database()->delete('mytable') + ->condition('pid', $path['pid']) + ->execute(); } /** diff -u b/core/modules/search/search.module b/core/modules/search/search.module --- b/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -224,9 +224,9 @@ $or->condition('word', $word->realword); } if (count($or) > 0) { - $query = \Drupal::database()->delete('search_total'); - $query->condition($or); - $query->execute(); + \Drupal::database()->delete('search_total') + ->condition($or) + ->execute(); } } diff -u b/core/modules/shortcut/src/ShortcutSetStorage.php b/core/modules/shortcut/src/ShortcutSetStorage.php --- b/core/modules/shortcut/src/ShortcutSetStorage.php +++ b/core/modules/shortcut/src/ShortcutSetStorage.php @@ -9,6 +9,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Database\Connection; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -24,6 +25,13 @@ protected $moduleHandler; /** + * The database connection. + * + * @var \Drupal\Core\Database\Connection + */ + protected $database; + + /** * Constructs a ShortcutSetStorageController object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_info @@ -37,10 +45,11 @@ * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. */ - public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { + public function __construct(EntityTypeInterface $entity_info, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, Connection $database) { parent::__construct($entity_info, $config_factory, $uuid_service, $language_manager); $this->moduleHandler = $module_handler; + $this->database = $database; } /** @@ -52,7 +61,8 @@ $container->get('config.factory'), $container->get('uuid'), $container->get('module_handler'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('database') ); } @@ -62,9 +72,9 @@ public function deleteAssignedShortcutSets(ShortcutSetInterface $entity) { // First, delete any user assignments for this set, so that each of these // users will go back to using whatever default set applies. - $query = \Drupal::database()->delete('shortcut_set_users'); - $query->condition('set_name', $entity->id()); - $query->execute(); + $this->database->delete('shortcut_set_users') + ->condition('set_name', $entity->id()) + ->execute(); } /** @@ -82,9 +92,9 @@ * {@inheritdoc} */ public function unassignUser($account) { - $deleted = \Drupal::database()->delete('shortcut_set_users'); - $deleted->condition('uid', $account->id()); - $deleted->execute(); + $deleted = $this->database->delete('shortcut_set_users') + ->condition('uid', $account->id()) + ->execute(); return (bool) $deleted; } diff -u b/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module --- b/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -567,9 +567,7 @@ */ function taxonomy_delete_node_index(EntityInterface $node) { if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) { - $query = \Drupal::database()->delete('taxonomy_index'); - $query->condition('nid', $node->id()); - $query->execute(); + \Drupal::database()->delete('taxonomy_index')->condition('nid', $node->id())->execute(); } } @@ -579,9 +577,7 @@ function taxonomy_taxonomy_term_delete(Term $term) { if (\Drupal::config('taxonomy.settings')->get('maintain_index_table')) { // Clean up the {taxonomy_index} table when terms are deleted. - $query = \Drupal::database()->delete('taxonomy_index'); - $query->condition('nid', $term->id()); - $query->execute(); + \Drupal::database()->delete('taxonomy_index')->condition('tid', $term->id())->execute(); } } reverted: --- b/core/modules/tracker/tests/src/Functional/TrackerTest.php +++ a/core/modules/tracker/tests/src/Functional/TrackerTest.php @@ -365,9 +365,9 @@ \Drupal::state()->set('tracker.index_nid', 3); // Clear the current tracker tables and rebuild them. + db_delete('tracker_node') - \Drupal::database()->delete('tracker_node') ->execute(); + db_delete('tracker_user') - \Drupal::database()->delete('tracker_user') ->execute(); tracker_cron(); diff -u b/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module --- b/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -61,13 +61,12 @@ $changed = _tracker_calculate_changed($node); // Remove existing data for this node. - $query = \Drupal::database()->delete('tracker_node'); - $query->condition('nid',$nid); - $query->execute(); - - $query = \Drupal::database()->delete('tracker_user'); - $query->condition('nid',$nid); - $query->execute(); + \Drupal::database()->delete('tracker_node') + ->condition('nid', $nid) + ->execute(); + \Drupal::database()->delete('tracker_user') + ->condition('nid', $nid) + ->execute(); // Insert the node-level data. db_insert('tracker_node') @@ -190,13 +189,12 @@ * Deletes tracking information for a node. */ function tracker_node_predelete(EntityInterface $node, $arg = 0) { - $query = \Drupal::database()->delete('tracker_node'); - $query->condition('nid',$node->id()); - $query->execute(); - - $query = \Drupal::database()->delete('tracker_user'); - $query->condition('nid',$node->id()); - $query->execute(); + \Drupal::database()->delete('tracker_node') + ->condition('nid', $node->id()) + ->execute(); + \Drupal::database()->delete('tracker_user') + ->condition('nid', $node->id()) + ->execute(); } /** @@ -335,10 +333,10 @@ // If we haven't found a reason to keep the user's subscription, delete it. if (!$keep_subscription) { - $query = \Drupal::database()->delete('tracker_user'); - $query->condition('nid',$nid); - $query->condition('uid',$uid); - $query->execute(); + \Drupal::database()->delete('tracker_user') + ->condition('nid', $nid) + ->condition('uid', $uid) + ->execute(); } // Now we need to update the (possibly) changed timestamps for other users @@ -374,11 +372,10 @@ else { // If the node doesn't exist, remove everything. - $query = \Drupal::database()->delete('tracker_node'); - $query->condition('nid',$nid); - $query->execute(); - - $query = \Drupal::database()->delete('tracker_user'); - $query->condition('nid',$nid); - $query->execute(); + \Drupal::database()->delete('tracker_node') + ->condition('nid', $nid) + ->execute(); + \Drupal::database()->delete('tracker_user') + ->condition('nid', $nid) + ->execute(); } } reverted: --- b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php +++ a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php @@ -38,7 +38,7 @@ } protected function delete($name) { + db_delete('config')->condition('name', $name)->execute(); - \Drupal::database()->delete('config')->condition('name', $name)->execute(); } } reverted: --- b/core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php +++ a/core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php @@ -27,7 +27,7 @@ $subquery = db_select('test', 't') ->fields('t', ['id']) ->condition('t.id', [$pid_to_delete], 'IN'); + $delete = db_delete('test_task') - $delete = \Drupal::database()->delete('test_task') ->condition('task', 'sleep') ->condition('pid', $subquery, 'IN'); @@ -44,7 +44,7 @@ public function testSimpleDelete() { $num_records_before = db_query('SELECT COUNT(*) FROM {test}')->fetchField(); + $num_deleted = db_delete('test') - $num_deleted = \Drupal::database()->delete('test') ->condition('id', 1) ->execute(); $this->assertIdentical($num_deleted, 1, 'Deleted 1 record.'); @@ -72,7 +72,7 @@ public function testSpecialColumnDelete() { $num_records_before = db_query('SELECT COUNT(*) FROM {test_special_columns}')->fetchField(); + $num_deleted = db_delete('test_special_columns') - $num_deleted = \Drupal::database()->delete('test_special_columns') ->condition('id', 1) ->execute(); $this->assertIdentical($num_deleted, 1, 'Deleted 1 special column record.');