Commit eadaeb9a authored by catch's avatar catch

Issue #2848137 by gaurav.kapoor, voleger, hgunicamp, andypost,...

Issue #2848137 by gaurav.kapoor, voleger, hgunicamp, andypost, shashikant_chauhan, brahmjeet789, pk188, cilefen, daffie: Replace all calls to db_update, which is deprecated
parent cd9f5a7d
......@@ -210,6 +210,7 @@ function db_merge($table, array $options = []) {
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_update($table, array $options = []) {
@trigger_error('db_update() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call call update() on it. For example, $injected_database->update($table, $options); See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
......
......@@ -524,7 +524,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; --')
......
......@@ -1129,7 +1129,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,
])
......@@ -1153,7 +1153,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,
])
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Core\Database\Database;
use Drupal\Tests\Traits\Core\CronRunTrait;
/**
......@@ -29,7 +30,8 @@ public function testCron() {
// Test feed locking when queued for update.
$this->deleteFeedItems($feed);
db_update('aggregator_feed')
$connection = Database::getConnection();
$connection->update('aggregator_feed')
->condition('fid', $feed->id())
->fields([
'queued' => REQUEST_TIME,
......@@ -37,7 +39,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')
$connection->update('aggregator_feed')
->condition('fid', $feed->id())
->fields([
'queued' => 0,
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\aggregator\Functional;
use Drupal\aggregator\Entity\Feed;
use Drupal\Core\Database\Database;
/**
* Update feed items from a feed.
......@@ -43,6 +44,7 @@ public function testUpdateFeedItem() {
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
$this->assert(isset($view_link), 'The message area contains a link to a feed');
$connection = Database::getConnection();
$fid = db_query("SELECT fid FROM {aggregator_feed} WHERE url = :url", [':url' => $edit['url[0][value]']])->fetchField();
$feed = Feed::load($fid);
......@@ -51,7 +53,7 @@ public function testUpdateFeedItem() {
// Sleep for 3 second.
sleep(3);
db_update('aggregator_feed')
$connection->update('aggregator_feed')
->condition('fid', $feed->id())
->fields([
'checked' => 0,
......
......@@ -9,8 +9,9 @@
* the database structure expected in tests altogether.
*/
$connection = \Drupal::database();
// Update the default category to that it is not selected.
db_update('contact')
$connection->update('contact')
->fields(['selected' => '0'])
->condition('cid', '1')
->execute();
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\file\Functional;
use Drupal\Core\Database\Database;
use Drupal\file\Entity\File;
/**
......@@ -118,7 +119,8 @@ 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')
$connection = Database::getConnection();
$connection->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
])
......@@ -134,7 +136,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')
$connection->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
])
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\file\Kernel;
use Drupal\Core\Database\Database;
use Drupal\file\Entity\File;
/**
......@@ -61,7 +62,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')
Database::getConnection()->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
])
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\file\Kernel;
use Drupal\Core\Database\Database;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -152,7 +153,8 @@ public function doTestRemoveUsage() {
public function createTempFiles() {
// Temporary file that is old.
$temp_old = file_save_data('');
db_update('file_managed')
$connection = Database::getConnection();
$connection->update('file_managed')
->fields([
'status' => 0,
'changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1,
......@@ -163,7 +165,7 @@ public function createTempFiles() {
// Temporary file that is new.
$temp_new = file_save_data('');
db_update('file_managed')
$connection->update('file_managed')
->fields(['status' => 0])
->condition('fid', $temp_new->id())
->execute();
......@@ -171,7 +173,7 @@ public function createTempFiles() {
// Permanent file that is old.
$perm_old = file_save_data('');
db_update('file_managed')
$connection->update('file_managed')
->fields(['changed' => REQUEST_TIME - $this->config('system.file')->get('temporary_maximum_age') - 1])
->condition('fid', $temp_old->id())
->execute();
......
......@@ -332,6 +332,7 @@ function locale_cron_fill_queue() {
$projects = array_filter($projects, function ($project) {
return $project['status'] == 1;
});
$connection = \Drupal::database();
$files = db_select('locale_file', 'f')
->condition('f.project', array_keys($projects), 'IN')
->condition('f.last_checked', $last, '<')
......@@ -342,7 +343,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')
$connection->update('locale_file')
->fields(['last_checked' => REQUEST_TIME])
->condition('project', $file->project)
->condition('langcode', $file->langcode)
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\locale\Functional;
use Drupal\Core\Database\Database;
use Drupal\Tests\Traits\Core\CronRunTrait;
/**
......@@ -51,7 +52,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 = Database::getConnection()->update('locale_file');
$query->fields(['last_checked' => 0]);
$query->condition('project', 'contrib_module_two');
$query->condition('langcode', 'de');
......
......@@ -2,6 +2,7 @@
namespace Drupal\node\Tests;
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -204,13 +205,14 @@ public function testRevisions() {
'@type' => 'Basic page',
'%title' => $nodes[1]->label(),
]), 'Revision deleted.');
$connection = Database::getConnection();
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Revision not found.');
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', [':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0, 'Field revision not found.');
// 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')
$connection->update('node_revision')
->condition('vid', $nodes[2]->getRevisionId())
->fields([
'revision_timestamp' => $old_revision_date,
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Database\Database;
use Drupal\user\RoleInterface;
/**
......@@ -66,10 +67,11 @@ public function testContentAdminSort() {
$this->drupalLogin($this->adminUser);
$changed = REQUEST_TIME;
$connection = Database::getConnection();
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')
$connection->update('node_field_data')
->fields(['changed' => $changed])
->condition('nid', $node->id())
->execute();
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\node\Functional;
use Drupal\block\Entity\Block;
use Drupal\Core\Database\Database;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\user\RoleInterface;
......@@ -69,14 +70,15 @@ public function testRecentNodeBlock() {
$node2 = $this->drupalCreateNode($default_settings);
$node3 = $this->drupalCreateNode($default_settings);
$connection = Database::getConnection();
// Change the changed time for node so that we can test ordering.
db_update('node_field_data')
$connection->update('node_field_data')
->fields([
'changed' => $node1->getChangedTime() + 100,
])
->condition('nid', $node2->id())
->execute();
db_update('node_field_data')
$connection->update('node_field_data')
->fields([
'changed' => $node1->getChangedTime() + 200,
])
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Database\Database;
use Drupal\node\NodeInterface;
/**
......@@ -177,6 +178,7 @@ public function testRevisions() {
'%title' => $nodes[1]->getTitle(),
]),
'Revision deleted.');
$connection = Database::getConnection();
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid',
[':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()])->fetchField() == 0,
'Revision not found.');
......@@ -184,7 +186,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')
$connection->update('node_revision')
->condition('vid', $nodes[2]->getRevisionId())
->fields([
'revision_timestamp' => $old_revision_date,
......
......@@ -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();
......
......@@ -587,7 +587,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.
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\search\Functional;
use Drupal\Core\Database\Database;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
......@@ -207,7 +208,8 @@ public function testMultilingualSearch() {
// previously.
$current = REQUEST_TIME;
$old = $current - 10;
db_update('search_dataset')
$connection = Database::getConnection();
$connection->update('search_dataset')
->fields(['reindex' => $old])
->condition('reindex', $current, '>=')
->execute();
......
......@@ -280,7 +280,7 @@ function _tracker_add($nid, $uid, $changed) {
])
->execute();
// Update the times for all the other users tracking the post.
db_update('tracker_user')
$connection->update('tracker_user')
->condition('nid', $nid)
->fields([
'changed' => $changed,
......@@ -323,6 +323,7 @@ function _tracker_calculate_changed($node) {
*/
function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
$node = Node::load($nid);
$connection = \Drupal::database();
// The user only keeps their subscription if the node exists.
if ($node) {
......@@ -364,14 +365,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')
$connection->update('tracker_node')
->fields([
'changed' => $changed,
'published' => $node->isPublished(),
])
->condition('nid', $nid)
->execute();
db_update('tracker_node')
$connection->update('tracker_node')
->fields([
'changed' => $changed,
'published' => $node->isPublished(),
......
......@@ -3,6 +3,7 @@
namespace Drupal\user\Tests\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Database\Database;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Core\Url;
use Drupal\Tests\system\Functional\Cache\PageCacheTagsTestBase;
......@@ -54,7 +55,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')
Database::getConnection()->update('users_field_data')
->fields(['login' => $account->getLastLoginTime()])
->condition('uid', $account->id())
->execute();
......@@ -302,7 +303,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')
Database::getConnection()->update('users_field_data')
->fields(['pass' => NULL])
->condition('uid', [$user1->id(), $user2->id()], 'IN')
->execute();
......
......@@ -2,6 +2,7 @@
namespace Drupal\user\Tests\FunctionalJavascript;
use Drupal\Core\Database\Database;
use Drupal\Core\Test\AssertMailTrait;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
......@@ -65,7 +66,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')
Database::getConnection()->update('users_field_data')
->fields(['login' => $account->getLastLoginTime()])
->condition('uid', $account->id())
->execute();
......
......@@ -2,6 +2,7 @@
namespace Drupal\user\Tests;
use Drupal\Core\Database\Database;
use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber;
use Drupal\simpletest\WebTestBase;
......@@ -125,7 +126,7 @@ public function testUserLoginBlock() {
* Updates the access column for a user.
*/
private function updateAccess($uid, $access = REQUEST_TIME) {
db_update('users_field_data')
Database::getConnection()->update('users_field_data')
->condition('uid', $uid)
->fields(['access' => $access])
->execute();
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\user\Functional;
use Drupal\Core\Database\Database;
use Drupal\image\Entity\ImageStyle;
use Drupal\Tests\BrowserTestBase;
use Drupal\file\Entity\File;
......@@ -74,7 +75,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')
Database::getConnection()->update('file_managed')
->fields([
'changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1),
])
......
......@@ -138,7 +138,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')
Database::getConnection()->update('key_value_expire')
->fields(['expire' => REQUEST_TIME - 1])
->condition('collection', "user.shared_tempstore.$collection")
->condition('name', $key)
......
......@@ -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();
......
......@@ -3,6 +3,7 @@
namespace Drupal\KernelTests\Core\Config\Storage;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Database\Database;
/**
* Tests DatabaseStorage operations.
......@@ -34,7 +35,7 @@ protected function insert($name, $data) {
}
protected function update($name, $data) {
db_update('config')->fields(['data' => $data])->condition('name', $name)->execute();
Database::getConnection()->update('config')->fields(['data' => $data])->condition('name', $name)->execute();
}
protected function delete($name) {
......
......@@ -3,6 +3,7 @@
namespace Drupal\KernelTests\Core\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\Update;
use Drupal\Core\Database\Transaction;
use Drupal\Core\Database\Database;
......@@ -206,4 +207,13 @@ public function testDbMerge() {
$this->assertSame($num_records_before + 1, $num_records_after, 'Merge inserted properly.');
}
/**
* Tests the db_update() function.
*
* @expectedDeprecation db_update() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call call update() on it. For example, $injected_database->update($table, $options); See https://www.drupal.org/node/2993033
*/
public function testDbUpdate() {
$this->assertInstanceOf(Update::class, db_update('test'));
}
}
......@@ -15,7 +15,7 @@ class UpdateComplexTest extends DatabaseTestBase {
* Tests updates with OR conditionals.
*/
public function testOrConditionUpdate() {
$update = db_update('test')
$update = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->update('test')
->expression('age', $subselect)
->condition('name', 'Ringo');
// Save the number of rows that updated for assertion later.
......
......@@ -20,7 +20,7 @@ public function testUpdateOneBlob() {
->execute();
$data .= $data;
db_update('test_one_blob')
$this->connection->update('test_one_blob')
->condition('id', $id)
->fields(['blob1' => $data])
->execute();
......@@ -40,7 +40,7 @@ public function testUpdateMultipleBlob() {
])
->execute();
db_update('test_two_blobs')
$this->connection->update('test_two_blobs')
->condition('id', $id)
->fields(['blob1' => 'and so', 'blob2' => 'is this'])
->execute();
......
......@@ -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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->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 = $this->connection->update('test_special_columns')
->fields(['offset' => 'New offset value'])
->condition('id', 1)
->execute();
......
......@@ -63,7 +63,8 @@ protected function setUp() {
*/
public function testSharedTempStore() {
// Create a key/value collection.
$factory = new SharedTempStoreFactory(new KeyValueExpirableFactory(\Drupal::getContainer()), new DatabaseLockBackend(Database::getConnection()), $this->container->get('request_stack'));
$database = Database::getConnection();
$factory = new SharedTempStoreFactory(new KeyValueExpirableFactory(\Drupal::getContainer()), new DatabaseLockBackend($database), $this->container->get('request_stack'));
$collection = $this->randomMachineName();