diff --git a/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php index 803689b..abecfd6 100644 --- a/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -523,7 +523,7 @@ public function makeComment($comments) { * * For example, the comment: * @code - * db_update('example') + * \Drupal::database()->update('example') * ->condition('id', $id) * ->fields(array('field2' => 10)) * ->comment('Exploit * / DROP TABLE node; --') diff --git a/core/lib/Drupal/Core/Database/database.api.php b/core/lib/Drupal/Core/Database/database.api.php index 45a5618..0339ce3 100644 --- a/core/lib/Drupal/Core/Database/database.api.php +++ b/core/lib/Drupal/Core/Database/database.api.php @@ -127,7 +127,7 @@ * INSERT, UPDATE, and DELETE queries need special care in order to behave * consistently across databases; you should never use db_query() to run * an INSERT, UPDATE, or DELETE query. Instead, use functions db_insert(), - * db_update(), and db_delete() to obtain a base query on your table, and then + * \Drupal::database()->update(), and db_delete() to obtain a base query on your table, and then * add dynamic conditions (as illustrated in @ref sec_dynamic above). * * As a note, db_insert() and similar functions are wrappers on connection @@ -190,7 +190,7 @@ * // The transaction is still open here. * * if ($id % 2 == 0) { - * db_update('example') + * \Drupal::database()->update('example') * ->condition('id', $id) * ->fields(array('field2' => 10)) * ->execute(); diff --git a/core/lib/Drupal/Core/Entity/entity.api.php b/core/lib/Drupal/Core/Entity/entity.api.php index 5387c7e..19d4161 100644 --- a/core/lib/Drupal/Core/Entity/entity.api.php +++ b/core/lib/Drupal/Core/Entity/entity.api.php @@ -991,7 +991,7 @@ function hook_ENTITY_TYPE_insert(Drupal\Core\Entity\EntityInterface $entity) { */ function hook_entity_update(Drupal\Core\Entity\EntityInterface $entity) { // Update the entity's entry in a fictional table of all entities. - db_update('example_entity') + \Drupal::database()->update('example_entity') ->fields([ 'updated' => REQUEST_TIME, ]) @@ -1015,7 +1015,7 @@ function hook_entity_update(Drupal\Core\Entity\EntityInterface $entity) { */ function hook_ENTITY_TYPE_update(Drupal\Core\Entity\EntityInterface $entity) { // Update the entity's entry in a fictional table of this type of entity. - db_update('example_entity') + \Drupal::database()->update('example_entity') ->fields([ 'updated' => REQUEST_TIME, ]) diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php index bb7c90a..54bba32 100644 --- a/core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php +++ b/core/modules/aggregator/tests/src/Functional/AggregatorCronTest.php @@ -29,7 +29,7 @@ public function testCron() { // Test feed locking when queued for update. $this->deleteFeedItems($feed); - db_update('aggregator_feed') + \Drupal::database()->update('aggregator_feed') ->condition('fid', $feed->id()) ->fields([ 'queued' => REQUEST_TIME, @@ -37,7 +37,7 @@ public function testCron() { ->execute(); $this->cronRun(); $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', [':fid' => $feed->id()])->fetchField()); - db_update('aggregator_feed') + \Drupal::database()->update('aggregator_feed') ->condition('fid', $feed->id()) ->fields([ 'queued' => 0, diff --git a/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php b/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php index b850ca9..7d521bf 100644 --- a/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php +++ b/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php @@ -49,7 +49,7 @@ public function testUpdateFeedItem() { // Sleep for 3 second. sleep(3); - db_update('aggregator_feed') + \Drupal::database()->update('aggregator_feed') ->condition('fid', $feed->id()) ->fields([ 'checked' => 0, diff --git a/core/modules/contact/tests/drupal-7.contact.database.php b/core/modules/contact/tests/drupal-7.contact.database.php index bd36384..ca61c0c 100644 --- a/core/modules/contact/tests/drupal-7.contact.database.php +++ b/core/modules/contact/tests/drupal-7.contact.database.php @@ -10,7 +10,7 @@ */ // Update the default category to that it is not selected. -db_update('contact') +\Drupal::database()->update('contact') ->fields(['selected' => '0']) ->condition('cid', '1') ->execute(); diff --git a/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php index 7b7b4d3..6ed7d39 100644 --- a/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -10,6 +10,7 @@ * @group file */ class FileFieldRevisionTest extends FileFieldTestBase { + /** * Tests creating multiple revisions of a node and managing attached files. * @@ -112,7 +113,7 @@ public function testRevisions() { // Call file_cron() to clean up the file. Make sure the changed timestamp // of the file is older than the system.file.temporary_maximum_age // configuration value. - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields([ 'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1), ]) @@ -128,7 +129,7 @@ public function testRevisions() { // Call file_cron() to clean up the file. Make sure the changed timestamp // of the file is older than the system.file.temporary_maximum_age // configuration value. - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields([ 'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1), ]) diff --git a/core/modules/file/tests/src/Kernel/DeleteTest.php b/core/modules/file/tests/src/Kernel/DeleteTest.php index 3b868c0..c139d41 100644 --- a/core/modules/file/tests/src/Kernel/DeleteTest.php +++ b/core/modules/file/tests/src/Kernel/DeleteTest.php @@ -55,7 +55,7 @@ public function testInUse() { // Call file_cron() to clean up the file. Make sure the changed timestamp // of the file is older than the system.file.temporary_maximum_age // configuration value. - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields([ 'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1), ]) diff --git a/core/modules/file/tests/src/Kernel/UsageTest.php b/core/modules/file/tests/src/Kernel/UsageTest.php index 672de0f..fc84e3c 100644 --- a/core/modules/file/tests/src/Kernel/UsageTest.php +++ b/core/modules/file/tests/src/Kernel/UsageTest.php @@ -127,7 +127,7 @@ public function testRemoveUsage() { public function createTempFiles() { // Temporary file that is old. $temp_old = file_save_data(''); - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields([ 'status' => 0, 'changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1, @@ -138,7 +138,7 @@ public function createTempFiles() { // Temporary file that is new. $temp_new = file_save_data(''); - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields(['status' => 0]) ->condition('fid', $temp_new->id()) ->execute(); @@ -146,7 +146,7 @@ public function createTempFiles() { // Permanent file that is old. $perm_old = file_save_data(''); - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields(['changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1]) ->condition('fid', $temp_old->id()) ->execute(); diff --git a/core/modules/locale/locale.translation.inc b/core/modules/locale/locale.translation.inc index 571f7d2..8dd2552 100644 --- a/core/modules/locale/locale.translation.inc +++ b/core/modules/locale/locale.translation.inc @@ -342,7 +342,7 @@ function locale_cron_fill_queue() { // Update the last_checked timestamp of the project+language that will // be checked for updates. - db_update('locale_file') + \Drupal::database()->update('locale_file') ->fields(['last_checked' => REQUEST_TIME]) ->condition('project', $file->project) ->condition('langcode', $file->langcode) diff --git a/core/modules/locale/src/Tests/LocaleUpdateCronTest.php b/core/modules/locale/src/Tests/LocaleUpdateCronTest.php index 78a14ec..b994fab 100644 --- a/core/modules/locale/src/Tests/LocaleUpdateCronTest.php +++ b/core/modules/locale/src/Tests/LocaleUpdateCronTest.php @@ -47,7 +47,7 @@ public function testUpdateCron() { // Prepare for test: Simulate that the file has not been checked for a long // time. Set the last_check timestamp to zero. - $query = db_update('locale_file'); + $query = \Drupal::database()->update('locale_file'); $query->fields(['last_checked' => 0]); $query->condition('project', 'contrib_module_two'); $query->condition('langcode', 'de'); diff --git a/core/modules/node/src/Tests/NodeRevisionsTest.php b/core/modules/node/src/Tests/NodeRevisionsTest.php index 1982266..449a779 100644 --- a/core/modules/node/src/Tests/NodeRevisionsTest.php +++ b/core/modules/node/src/Tests/NodeRevisionsTest.php @@ -200,7 +200,7 @@ public function testRevisions() { // Set the revision timestamp to an older date to make sure that the // confirmation message correctly displays the stored revision date. $old_revision_date = REQUEST_TIME - 86400; - db_update('node_revision') + \Drupal::database()->update('node_revision') ->condition('vid', $nodes[2]->getRevisionId()) ->fields([ 'revision_timestamp' => $old_revision_date, diff --git a/core/modules/node/tests/src/Functional/NodeAdminTest.php b/core/modules/node/tests/src/Functional/NodeAdminTest.php index 24a50cf..71f83f5 100644 --- a/core/modules/node/tests/src/Functional/NodeAdminTest.php +++ b/core/modules/node/tests/src/Functional/NodeAdminTest.php @@ -69,7 +69,7 @@ public function testContentAdminSort() { foreach (['dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB'] as $prefix) { $changed += 1000; $node = $this->drupalCreateNode(['title' => $prefix . $this->randomMachineName(6)]); - db_update('node_field_data') + \Drupal::database()->update('node_field_data') ->fields(['changed' => $changed]) ->condition('nid', $node->id()) ->execute(); diff --git a/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php b/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php index ad3613d..e69d905 100644 --- a/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php +++ b/core/modules/node/tests/src/Functional/NodeBlockFunctionalTest.php @@ -70,13 +70,13 @@ public function testRecentNodeBlock() { $node3 = $this->drupalCreateNode($default_settings); // Change the changed time for node so that we can test ordering. - db_update('node_field_data') + \Drupal::database()->update('node_field_data') ->fields([ 'changed' => $node1->getChangedTime() + 100, ]) ->condition('nid', $node2->id()) ->execute(); - db_update('node_field_data') + \Drupal::database()->update('node_field_data') ->fields([ 'changed' => $node1->getChangedTime() + 200, ]) diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php index 7e71847..005aba3 100644 --- a/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php +++ b/core/modules/node/tests/src/Functional/NodeRevisionsAllTest.php @@ -166,7 +166,7 @@ public function testRevisions() { // Set the revision timestamp to an older date to make sure that the // confirmation message correctly displays the stored revision date. $old_revision_date = REQUEST_TIME - 86400; - db_update('node_revision') + \Drupal::database()->update('node_revision') ->condition('vid', $nodes[2]->getRevisionId()) ->fields([ 'revision_timestamp' => $old_revision_date, diff --git a/core/modules/path/path.api.php b/core/modules/path/path.api.php index df20b95..429c1e1 100644 --- a/core/modules/path/path.api.php +++ b/core/modules/path/path.api.php @@ -39,7 +39,7 @@ function hook_path_insert($path) { */ function hook_path_update($path) { if ($path['alias'] != $path['original']['alias']) { - db_update('mytable') + \Drupal::database()->update('mytable') ->fields(['alias' => $path['alias']]) ->condition('pid', $path['pid']) ->execute(); diff --git a/core/modules/search/search.module b/core/modules/search/search.module index ae99a87..8eeb41c 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -571,7 +571,7 @@ function search_index($type, $sid, $langcode, $text) { * $type and $sid is marked. */ function search_mark_for_reindex($type = NULL, $sid = NULL, $langcode = NULL) { - $query = db_update('search_dataset') + $query = \Drupal::database()->update('search_dataset') ->fields(['reindex' => REQUEST_TIME]) // Only mark items that were not previously marked for reindex, so that // marked items maintain their priority by request time. diff --git a/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php b/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php index 3dfc117..108d646 100644 --- a/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php +++ b/core/modules/search/tests/src/Functional/SearchMultilingualEntityTest.php @@ -206,7 +206,7 @@ public function testMultilingualSearch() { // previously. $current = REQUEST_TIME; $old = $current - 10; - db_update('search_dataset') + \Drupal::database()->update('search_dataset') ->fields(['reindex' => $old]) ->condition('reindex', $current, '>=') ->execute(); diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index bf40dc1..66e20cd 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -279,7 +279,7 @@ function _tracker_add($nid, $uid, $changed) { ]) ->execute(); // Update the times for all the other users tracking the post. - db_update('tracker_user') + \Drupal::database()->update('tracker_user') ->condition('nid', $nid) ->fields([ 'changed' => $changed, @@ -363,14 +363,14 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) { // And then we push the out the new changed timestamp to our denormalized // tables. - db_update('tracker_node') + \Drupal::database()->update('tracker_node') ->fields([ 'changed' => $changed, 'published' => $node->isPublished(), ]) ->condition('nid', $nid) ->execute(); - db_update('tracker_node') + \Drupal::database()->update('tracker_node') ->fields([ 'changed' => $changed, 'published' => $node->isPublished(), diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/src/Tests/UserBlocksTest.php index 0a4c619..bfc3d66 100644 --- a/core/modules/user/src/Tests/UserBlocksTest.php +++ b/core/modules/user/src/Tests/UserBlocksTest.php @@ -157,7 +157,7 @@ public function testWhosOnlineBlock() { * Updates the access column for a user. */ private function updateAccess($uid, $access = REQUEST_TIME) { - db_update('users_field_data') + \Drupal::database()->update('users_field_data') ->condition('uid', $uid) ->fields(['access' => $access]) ->execute(); diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/src/Tests/UserPasswordResetTest.php index 528d38b..c887a71 100644 --- a/core/modules/user/src/Tests/UserPasswordResetTest.php +++ b/core/modules/user/src/Tests/UserPasswordResetTest.php @@ -60,7 +60,7 @@ protected function setUp() { // Set the last login time that is used to generate the one-time link so // that it is definitely over a second ago. $account->login = REQUEST_TIME - mt_rand(10, 100000); - db_update('users_field_data') + \Drupal::database()->update('users_field_data') ->fields(['login' => $account->getLastLoginTime()]) ->condition('uid', $account->id()) ->execute(); @@ -316,7 +316,7 @@ public function testResetImpersonation() { // Unique password hashes are automatically generated, the only way to // change that is to update it directly in the database. - db_update('users_field_data') + \Drupal::database()->update('users_field_data') ->fields(['pass' => NULL]) ->condition('uid', [$user1->id(), $user2->id()], 'IN') ->execute(); diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index 6d546f0..c53bece 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -63,7 +63,7 @@ public function testCreateDeletePicture() { // Call file_cron() to clean up the file. Make sure the timestamp // of the file is older than the system.file.temporary_maximum_age // configuration value. - db_update('file_managed') + \Drupal::database()->update('file_managed') ->fields([ 'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1), ]) diff --git a/core/modules/user/tests/src/Functional/UserCancelTest.php b/core/modules/user/tests/src/Functional/UserCancelTest.php index 83020b4..1794ba9 100644 --- a/core/modules/user/tests/src/Functional/UserCancelTest.php +++ b/core/modules/user/tests/src/Functional/UserCancelTest.php @@ -107,7 +107,7 @@ public function testUserCancelUid1() { ]; // We cannot use $account->save() here, because this would result in the // password being hashed again. - db_update('users_field_data') + \Drupal::database()->update('users_field_data') ->fields($account) ->condition('uid', 1) ->execute(); diff --git a/core/modules/user/tests/src/Kernel/TempStoreDatabaseTest.php b/core/modules/user/tests/src/Kernel/TempStoreDatabaseTest.php index b3d7ff1..187ecad 100644 --- a/core/modules/user/tests/src/Kernel/TempStoreDatabaseTest.php +++ b/core/modules/user/tests/src/Kernel/TempStoreDatabaseTest.php @@ -134,7 +134,7 @@ public function testUserTempStore() { // Now manually expire the item (this is not exposed by the API) and then // assert it is no longer accessible. - db_update('key_value_expire') + \Drupal::database()->update('key_value_expire') ->fields(['expire' => REQUEST_TIME - 1]) ->condition('collection', "user.shared_tempstore.$collection") ->condition('name', $key) diff --git a/core/modules/user/user.api.php b/core/modules/user/user.api.php index 364dd1a..6f509d8 100644 --- a/core/modules/user/user.api.php +++ b/core/modules/user/user.api.php @@ -55,7 +55,7 @@ function hook_user_cancel($edit, $account, $method) { ->execute(); node_mass_update($nodes, ['uid' => 0], NULL, TRUE); // Anonymize old revisions. - db_update('node_field_revision') + \Drupal::database()->update('node_field_revision') ->fields(['uid' => 0]) ->condition('uid', $account->id()) ->execute(); diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index 8b591f4..0ed4e8d 100644 --- a/core/scripts/generate-d7-content.sh +++ b/core/scripts/generate-d7-content.sh @@ -290,27 +290,27 @@ $node->log = "added a broken node"; $node->path = array('alias' => "content/1263769200"); node_save($node); -db_update('node') +\Drupal::database()->update('node') ->fields(array( 'type' => $node_type, )) ->condition('nid', $node->nid) ->execute(); -db_update('field_data_body') +\Drupal::database()->update('field_data_body') ->fields(array( 'bundle' => $node_type, )) ->condition('entity_id', $node->nid) ->condition('entity_type', 'node') ->execute(); -db_update('field_revision_body') +\Drupal::database()->update('field_revision_body') ->fields(array( 'bundle' => $node_type, )) ->condition('entity_id', $node->nid) ->condition('entity_type', 'node') ->execute(); -db_update('field_config_instance') +\Drupal::database()->update('field_config_instance') ->fields(array( 'bundle' => $node_type, )) diff --git a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php index 0aecc72..915a240 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/Storage/DatabaseStorageTest.php @@ -34,7 +34,7 @@ protected function insert($name, $data) { } protected function update($name, $data) { - db_update('config')->fields(['data' => $data])->condition('name', $name)->execute(); + \Drupal::database()->update('config')->fields(['data' => $data])->condition('name', $name)->execute(); } protected function delete($name) { diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php index 69d5d5d..f17879d 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateComplexTest.php @@ -15,7 +15,7 @@ class UpdateComplexTest extends DatabaseTestBase { * Tests updates with OR conditionals. */ public function testOrConditionUpdate() { - $update = db_update('test') + $update = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition((new Condition('OR')) ->condition('name', 'John') @@ -32,7 +32,7 @@ public function testOrConditionUpdate() { * Tests WHERE IN clauses. */ public function testInConditionUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition('name', ['John', 'Paul'], 'IN') ->execute(); @@ -48,7 +48,7 @@ public function testInConditionUpdate() { public function testNotInConditionUpdate() { // The o is lowercase in the 'NoT IN' operator, to make sure the operators // work in mixed case. - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition('name', ['John', 'Paul', 'George'], 'NoT IN') ->execute(); @@ -62,7 +62,7 @@ public function testNotInConditionUpdate() { * Tests BETWEEN conditional clauses. */ public function testBetweenConditionUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition('age', [25, 26], 'BETWEEN') ->execute(); @@ -76,7 +76,7 @@ public function testBetweenConditionUpdate() { * Tests LIKE conditionals. */ public function testLikeConditionUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition('name', '%ge%', 'LIKE') ->execute(); @@ -91,7 +91,7 @@ public function testLikeConditionUpdate() { */ public function testUpdateExpression() { $before_age = db_query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchField(); - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->condition('name', 'Ringo') ->fields(['job' => 'Musician']) ->expression('age', 'age + :age', [':age' => 4]) @@ -112,7 +112,7 @@ public function testUpdateExpression() { */ public function testUpdateOnlyExpression() { $before_age = db_query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'])->fetchField(); - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->condition('name', 'Ringo') ->expression('age', 'age + :age', [':age' => 4]) ->execute(); @@ -131,7 +131,7 @@ public function testSubSelectUpdate() { // Clone this to make sure we are running a different query when // asserting. $select = clone $subselect; - $query = db_update('test') + $query = \Drupal::database()->update('test') ->expression('age', $subselect) ->condition('name', 'Ringo'); // Save the number of rows that updated for assertion later. diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php index 501f918..8a813a4 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateLobTest.php @@ -20,7 +20,7 @@ public function testUpdateOneBlob() { ->execute(); $data .= $data; - db_update('test_one_blob') + \Drupal::database()->update('test_one_blob') ->condition('id', $id) ->fields(['blob1' => $data]) ->execute(); @@ -40,7 +40,7 @@ public function testUpdateMultipleBlob() { ]) ->execute(); - db_update('test_two_blobs') + \Drupal::database()->update('test_two_blobs') ->condition('id', $id) ->fields(['blob1' => 'and so', 'blob2' => 'is this']) ->execute(); diff --git a/core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php b/core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php index 6bc9131..181ef1a 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/UpdateTest.php @@ -13,7 +13,7 @@ class UpdateTest extends DatabaseTestBase { * Confirms that we can update a single record successfully. */ public function testSimpleUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['name' => 'Tiffany']) ->condition('id', 1) ->execute(); @@ -28,7 +28,7 @@ public function testSimpleUpdate() { */ public function testSimpleNullUpdate() { $this->ensureSampleDataNull(); - $num_updated = db_update('test_null') + $num_updated = \Drupal::database()->update('test_null') ->fields(['age' => NULL]) ->condition('name', 'Kermit') ->execute(); @@ -42,7 +42,7 @@ public function testSimpleNullUpdate() { * Confirms that we can update multiple records successfully. */ public function testMultiUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition('job', 'Singer') ->execute(); @@ -56,7 +56,7 @@ public function testMultiUpdate() { * Confirms that we can update multiple records with a non-equality condition. */ public function testMultiGTUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->condition('age', 26, '>') ->execute(); @@ -70,7 +70,7 @@ public function testMultiGTUpdate() { * Confirms that we can update multiple records with a where call. */ public function testWhereUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->where('age > :age', [':age' => 26]) ->execute(); @@ -84,7 +84,7 @@ public function testWhereUpdate() { * Confirms that we can stack condition and where calls. */ public function testWhereAndConditionUpdate() { - $update = db_update('test') + $update = \Drupal::database()->update('test') ->fields(['job' => 'Musician']) ->where('age > :age', [':age' => 26]) ->condition('name', 'Ringo'); @@ -101,7 +101,7 @@ public function testWhereAndConditionUpdate() { public function testExpressionUpdate() { // Ensure that expressions are handled properly. This should set every // record's age to a square of itself. - $num_rows = db_update('test') + $num_rows = \Drupal::database()->update('test') ->expression('age', 'age * age') ->execute(); $this->assertIdentical($num_rows, 4, 'Updated 4 records.'); @@ -120,7 +120,7 @@ public function testUpdateAffectedRows() { // them actually don't have to be changed because their value was already // 'sleep'. Still, execute() should return 5 affected rows, not only 3, // because that's cross-db expected behavior. - $num_rows = db_update('test_task') + $num_rows = \Drupal::database()->update('test_task') ->condition('priority', 1, '<>') ->fields(['task' => 'sleep']) ->execute(); @@ -131,7 +131,7 @@ public function testUpdateAffectedRows() { * Confirm that we can update the primary key of a record successfully. */ public function testPrimaryKeyUpdate() { - $num_updated = db_update('test') + $num_updated = \Drupal::database()->update('test') ->fields(['id' => 42, 'name' => 'John']) ->condition('id', 1) ->execute(); @@ -145,7 +145,7 @@ public function testPrimaryKeyUpdate() { * Confirm that we can update values in a column with special name. */ public function testSpecialColumnUpdate() { - $num_updated = db_update('test_special_columns') + $num_updated = \Drupal::database()->update('test_special_columns') ->fields(['offset' => 'New offset value']) ->condition('id', 1) ->execute();