Commit b48e1e74 authored by catch's avatar catch

Issue #2873684 by voleger, longwave, jeetendrakumar, andypost, mondrake,...

Issue #2873684 by voleger, longwave, jeetendrakumar, andypost, mondrake, catch: Replace all calls to db_select, which is deprecated
parent 0a8ea5e4
......@@ -300,6 +300,7 @@ function db_truncate($table, array $options = []) {
* @see \Drupal\Core\Database\Connection::defaultOptions()
*/
function db_select($table, $alias = NULL, array $options = []) {
@trigger_error('db_select() 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 select() on it. For example, $injected_database->db_select($table, $alias, $options); See https://www.drupal.org/node/2993033', E_USER_DEPRECATED);
if (empty($options['target'])) {
$options['target'] = 'default';
}
......
......@@ -1286,7 +1286,7 @@ function hook_entity_predelete(Drupal\Core\Entity\EntityInterface $entity) {
// upon entity deletion.
$id = $entity->id();
$type = $entity->getEntityTypeId();
$count = db_select('example_entity_data')
$count = \Drupal::database()->select('example_entity_data')
->condition('type', $type)
->condition('id', $id)
->countQuery()
......@@ -1315,7 +1315,7 @@ function hook_ENTITY_TYPE_predelete(Drupal\Core\Entity\EntityInterface $entity)
// upon entity deletion.
$id = $entity->id();
$type = $entity->getEntityTypeId();
$count = db_select('example_entity_data')
$count = \Drupal::database()->select('example_entity_data')
->condition('type', $type)
->condition('id', $id)
->countQuery()
......
......@@ -28,6 +28,7 @@ public function testIPAddressValidation() {
$admin_user = $this->drupalCreateUser(['ban IP addresses']);
$this->drupalLogin($admin_user);
$this->drupalGet('admin/config/people/ban');
$connection = Database::getConnection();
// Ban a valid IP address.
$edit = [];
......@@ -78,13 +79,12 @@ public function testIPAddressValidation() {
// Test duplicate ip address are not present in the 'blocked_ips' table.
// when they are entered programmatically.
$connection = Database::getConnection();
$banIp = new BanIpManager($connection);
$ip = '1.0.0.0';
$banIp->banIp($ip);
$banIp->banIp($ip);
$banIp->banIp($ip);
$query = db_select('ban_ip', 'bip');
$query = $connection->select('ban_ip', 'bip');
$query->fields('bip', ['iid']);
$query->condition('bip.ip', $ip);
$ip_count = $query->execute()->fetchAll();
......@@ -92,7 +92,7 @@ public function testIPAddressValidation() {
$ip = '';
$banIp->banIp($ip);
$banIp->banIp($ip);
$query = db_select('ban_ip', 'bip');
$query = $connection->select('ban_ip', 'bip');
$query->fields('bip', ['iid']);
$query->condition('bip.ip', $ip);
$ip_count = $query->execute()->fetchAll();
......
......@@ -201,9 +201,10 @@ public function testFailedBlockCreation() {
$this->pass('Expected exception has been thrown.');
}
if (Database::getConnection()->supportsTransactions()) {
$connection = Database::getConnection();
if ($connection->supportsTransactions()) {
// Check that the block does not exist in the database.
$id = db_select('block_content_field_data', 'b')
$id = $connection->select('block_content_field_data', 'b')
->fields('b', ['id'])
->condition('info', 'fail_creation')
->execute()
......@@ -212,7 +213,7 @@ public function testFailedBlockCreation() {
}
else {
// Check that the block exists in the database.
$id = db_select('block_content_field_data', 'b')
$id = $connection->select('block_content_field_data', 'b')
->fields('b', ['id'])
->condition('info', 'fail_creation')
->execute()
......
......@@ -186,7 +186,7 @@ public function countOriginalLinkChildren($original) {
* {@inheritdoc}
*/
public function getBookSubtree($link, $max_depth) {
$query = db_select('book', 'b', ['fetch' => \PDO::FETCH_ASSOC]);
$query = $this->connection->select('book', 'b', ['fetch' => \PDO::FETCH_ASSOC]);
$query->fields('b');
$query->condition('b.bid', $link['bid']);
......
......@@ -2,6 +2,7 @@
namespace Drupal\comment\Plugin\views\filter;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
......@@ -18,7 +19,7 @@ class UserUid extends FilterPluginBase {
public function query() {
$this->ensureMyTable();
$subselect = db_select('comment_field_data', 'c');
$subselect = Database::getConnection()->select('comment_field_data', 'c');
$subselect->addField('c', 'cid');
$subselect->condition('c.uid', $this->value, $this->operator);
......
......@@ -68,7 +68,7 @@ function dblog_cron() {
// e.g. auto_increment value > 1 or rows deleted directly from the table.
if ($row_limit > 0) {
$connection = \Drupal::database();
$min_row = db_select('watchdog', 'w')
$min_row = $connection->select('watchdog', 'w')
->fields('w', ['wid'])
->orderBy('wid', 'DESC')
->range($row_limit - 1, 1)
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -186,7 +187,7 @@ public function testDeleteField() {
$table_mapping = $storage->getTableMapping();
$table = $table_mapping->getDedicatedDataTableName($field_storage);
$column = $table_mapping->getFieldColumnName($field_storage, 'value');
$result = db_select($table, 't')
$result = Database::getConnection()->select($table, 't')
->fields('t')
->execute();
foreach ($result as $row) {
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
......@@ -87,7 +88,7 @@ public function testEntityCountAndHasData() {
// Count the actual number of rows in the field table.
$table_mapping = $storage->getTableMapping();
$field_table_name = $table_mapping->getDedicatedDataTableName($field_storage);
$result = db_select($field_table_name, 't')
$result = Database::getConnection()->select($field_table_name, 't')
->fields('t')
->countQuery()
->execute()
......
......@@ -63,7 +63,7 @@ public function testAddUsage() {
$file_usage->add($file, 'testing', 'bar', 2);
$file_usage->add($file, 'testing', 'bar', 2);
$usage = db_select('file_usage', 'f')
$usage = Database::getConnection()->select('file_usage', 'f')
->fields('f')
->condition('f.fid', $file->id())
->execute()
......@@ -119,7 +119,7 @@ public function doTestRemoveUsage() {
// Normal decrement.
$file_usage->delete($file, 'testing', 'bar', 2);
$count = db_select('file_usage', 'f')
$count = $connection->select('file_usage', 'f')
->fields('f', ['count'])
->condition('f.fid', $file->id())
->execute()
......@@ -128,7 +128,7 @@ public function doTestRemoveUsage() {
// Multiple decrement and removal.
$file_usage->delete($file, 'testing', 'bar', 2, 2);
$count = db_select('file_usage', 'f')
$count = $connection->select('file_usage', 'f')
->fields('f', ['count'])
->condition('f.fid', $file->id())
->execute()
......@@ -137,7 +137,7 @@ public function doTestRemoveUsage() {
// Non-existent decrement.
$file_usage->delete($file, 'testing', 'bar', 2);
$count = db_select('file_usage', 'f')
$count = $connection->select('file_usage', 'f')
->fields('f', ['count'])
->condition('f.fid', $file->id())
->execute()
......
......@@ -2,6 +2,8 @@
namespace Drupal\forum\Plugin\Block;
use Drupal\Core\Database\Database;
/**
* Provides an 'Active forum topics' block.
*
......@@ -17,7 +19,7 @@ class ActiveTopicsBlock extends ForumBlockBase {
* {@inheritdoc}
*/
protected function buildForumQuery() {
return db_select('forum_index', 'f')
return Database::getConnection()->select('forum_index', 'f')
->fields('f')
->addTag('node_access')
->addMetaData('base_table', 'forum_index')
......
......@@ -2,6 +2,8 @@
namespace Drupal\forum\Plugin\Block;
use Drupal\Core\Database\Database;
/**
* Provides a 'New forum topics' block.
*
......@@ -17,7 +19,7 @@ class NewTopicsBlock extends ForumBlockBase {
* {@inheritdoc}
*/
protected function buildForumQuery() {
return db_select('forum_index', 'f')
return Database::getConnection()->select('forum_index', 'f')
->fields('f')
->addTag('node_access')
->addMetaData('base_table', 'forum_index')
......
......@@ -55,7 +55,7 @@ function locale_translate_batch_import_files(array $options, $force = FALSE) {
$files = locale_translate_get_interface_translation_files([], $langcodes);
if (!$force) {
$result = db_select('locale_file', 'lf')
$result = \Drupal::database()->select('locale_file', 'lf')
->fields('lf', ['langcode', 'uri', 'timestamp'])
->condition('langcode', $langcodes)
->execute()
......
......@@ -333,7 +333,7 @@ function locale_cron_fill_queue() {
return $project['status'] == 1;
});
$connection = \Drupal::database();
$files = db_select('locale_file', 'f')
$files = $connection->select('locale_file', 'f')
->condition('f.project', array_keys($projects), 'IN')
->condition('f.last_checked', $last, '<')
->fields('f', ['project', 'langcode'])
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\locale\Functional;
use Drupal\Core\Database\Database;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Language\LanguageInterface;
......@@ -232,7 +233,7 @@ public function testJavaScriptTranslation() {
// Retrieve the source string of the first string available in the
// {locales_source} table and translate it.
$query = db_select('locales_source', 's');
$query = Database::getConnection()->select('locales_source', 's');
$query->addJoin('INNER', 'locales_location', 'l', 's.lid = l.lid');
$source = $query->fields('s', ['source'])
->condition('l.type', 'javascript')
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\Config;
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\StatementInterface;
use Drupal\Core\Entity\EntityManagerInterface;
......@@ -438,7 +439,7 @@ public function updateIndex() {
// per cron run.
$limit = (int) $this->searchSettings->get('index.cron_limit');
$query = db_select('node', 'n', ['target' => 'replica']);
$query = Database::getConnection('replica')->select('node', 'n');
$query->addField('n', 'nid');
$query->leftJoin('search_dataset', 'sd', 'sd.sid = n.nid AND sd.type = :type', [':type' => $this->getPluginId()]);
$query->addExpression('CASE MAX(sd.reindex) WHEN NULL THEN 0 ELSE 1 END', 'ex');
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -251,9 +252,9 @@ public function testNodeAccessLanguageAwareCombination() {
$this->assertNodeAccess($expected_node_access_no_access, $this->nodes['private_no_language_public'], $this->webUser);
// Query the node table with the node access tag in several languages.
$connection = Database::getConnection();
// Query with no language specified. The fallback (hu or und) will be used.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addTag('node_access');
......@@ -268,7 +269,7 @@ public function testNodeAccessLanguageAwareCombination() {
$this->assertTrue(array_key_exists($this->nodes['public_no_language_public']->id(), $nids), 'Returned node ID is no language public node.');
// Query with Hungarian (hu) specified.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'hu')
......@@ -282,7 +283,7 @@ public function testNodeAccessLanguageAwareCombination() {
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
// Query with Catalan (ca) specified.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'ca')
......@@ -296,7 +297,7 @@ public function testNodeAccessLanguageAwareCombination() {
$this->assertTrue(array_key_exists($this->nodes['private_both_public']->id(), $nids), 'Returned node ID is both public non-language-aware private only node.');
// Query with German (de) specified.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'de')
......@@ -308,7 +309,7 @@ public function testNodeAccessLanguageAwareCombination() {
// Query the nodes table as admin user (full access) with the node access
// tag and no specific langcode.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->adminUser)
->addTag('node_access');
......@@ -319,7 +320,7 @@ public function testNodeAccessLanguageAwareCombination() {
// Query the nodes table as admin user (full access) with the node access
// tag and langcode de.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->adminUser)
->addMetaData('langcode', 'de')
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
......@@ -192,9 +193,9 @@ public function testNodeAccessLanguageAware() {
$this->assertNodeAccess($expected_node_access, $this->nodes['no_language_public'], $this->webUser);
// Query the node table with the node access tag in several languages.
$connection = Database::getConnection();
// Query with no language specified. The fallback (hu) will be used.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addTag('node_access');
......@@ -210,7 +211,7 @@ public function testNodeAccessLanguageAware() {
$this->assertTrue(array_key_exists($this->nodes['no_language_public']->id(), $nids), 'The node with no language is returned.');
// Query with Hungarian (hu) specified.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'hu')
......@@ -224,7 +225,7 @@ public function testNodeAccessLanguageAware() {
$this->assertTrue(array_key_exists($this->nodes['ca_private']->id(), $nids), 'The node with only the Catalan translation private is returned.');
// Query with Catalan (ca) specified.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'ca')
......@@ -238,7 +239,7 @@ public function testNodeAccessLanguageAware() {
$this->assertTrue(array_key_exists($this->nodes['hu_private']->id(), $nids), 'The node with only the Hungarian translation private is returned.');
// Query with German (de) specified.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->webUser)
->addMetaData('langcode', 'de')
......@@ -250,7 +251,7 @@ public function testNodeAccessLanguageAware() {
// Query the nodes table as admin user (full access) with the node access
// tag and no specific langcode.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->adminUser)
->addTag('node_access');
......@@ -261,7 +262,7 @@ public function testNodeAccessLanguageAware() {
// Query the nodes table as admin user (full access) with the node access
// tag and langcode de.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $this->adminUser)
->addMetaData('langcode', 'de')
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Functional;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
......@@ -201,9 +202,10 @@ public function testNodeAccessQueryTag() {
]);
$this->assertTrue($node_no_language->language()->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.');
$connection = Database::getConnection();
// Query the nodes table as the web user with the node access tag and no
// specific langcode.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $web_user)
->addTag('node_access');
......@@ -217,7 +219,7 @@ public function testNodeAccessQueryTag() {
// Query the nodes table as the web user with the node access tag and
// langcode de.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $web_user)
->addMetaData('langcode', 'de')
......@@ -229,7 +231,7 @@ public function testNodeAccessQueryTag() {
// Query the nodes table as admin user (full access) with the node access
// tag and no specific langcode.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $admin_user)
->addTag('node_access');
......@@ -240,7 +242,7 @@ public function testNodeAccessQueryTag() {
// Query the nodes table as admin user (full access) with the node access
// tag and langcode de.
$select = db_select('node', 'n')
$select = $connection->select('node', 'n')
->fields('n', ['nid'])
->addMetaData('account', $admin_user)
->addMetaData('langcode', 'de')
......
......@@ -78,7 +78,7 @@ public function testContentAdminSort() {
}
// Test that the default sort by node.changed DESC actually fires properly.
$nodes_query = db_select('node_field_data', 'n')
$nodes_query = $connection->select('node_field_data', 'n')
->fields('n', ['title'])
->orderBy('changed', 'DESC')
->execute()
......@@ -92,7 +92,7 @@ public function testContentAdminSort() {
// Compare the rendered HTML node list to a query for the nodes ordered by
// title to account for possible database-dependent sort order.
$nodes_query = db_select('node_field_data', 'n')
$nodes_query = $connection->select('node_field_data', 'n')
->fields('n', ['title'])
->orderBy('title')
->execute()
......
......@@ -55,7 +55,7 @@ protected function setUp() {
public function testNodeQueryAlterLowLevelWithAccess() {
// User with access should be able to view 4 nodes.
try {
$query = db_select('node', 'mytab')
$query = Database::getConnection()->select('node', 'mytab')
->fields('mytab');
$query->addTag('node_access');
$query->addMetaData('op', 'view');
......@@ -96,7 +96,7 @@ public function testNodeQueryAlterWithRevisions() {
public function testNodeQueryAlterLowLevelNoAccess() {
// User without access should be able to view 0 nodes.
try {
$query = db_select('node', 'mytab')
$query = Database::getConnection()->select('node', 'mytab')
->fields('mytab');
$query->addTag('node_access');
$query->addMetaData('op', 'view');
......@@ -119,7 +119,7 @@ public function testNodeQueryAlterLowLevelNoAccess() {
public function testNodeQueryAlterLowLevelEditAccess() {
// User with view-only access should not be able to edit nodes.
try {
$query = db_select('node', 'mytab')
$query = Database::getConnection()->select('node', 'mytab')
->fields('mytab');
$query->addTag('node_access');
$query->addMetaData('op', 'update');
......@@ -160,7 +160,7 @@ public function testNodeQueryAlterOverride() {
// privilege after adding the node_access record.
drupal_static_reset('node_access_view_all_nodes');
try {
$query = db_select('node', 'mytab')
$query = $connection->select('node', 'mytab')
->fields('mytab');
$query->addTag('node_access');
$query->addMetaData('op', 'view');
......@@ -182,7 +182,7 @@ public function testNodeQueryAlterOverride() {
\Drupal::state()->set('node_access_test.no_access_uid', $this->noAccessUser->id());
drupal_static_reset('node_access_view_all_nodes');
try {
$query = db_select('node', 'mytab')
$query = $connection->select('node', 'mytab')
->fields('mytab');
$query->addTag('node_access');
$query->addMetaData('op', 'view');
......
......@@ -224,7 +224,7 @@ public function testRevisions() {
// Verify that the non-default revision vid is greater than the default
// revision vid.
$default_revision = db_select('node', 'n')
$default_revision = $connection->select('node', 'n')
->fields('n', ['vid'])
->condition('nid', $node->id())
->execute()
......
......@@ -2,7 +2,9 @@
namespace Drupal\search\Plugin\views\argument;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\search\ViewsSearchQuery;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
......@@ -48,7 +50,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o
*/
protected function queryParseSearchExpression($input) {
if (!isset($this->searchQuery)) {
$this->searchQuery = db_select('search_index', 'i', ['target' => 'replica'])->extend('Drupal\search\ViewsSearchQuery');
$this->searchQuery = Database::getConnection('replica')->select('search_index', 'i')->extend(ViewsSearchQuery::class);
$this->searchQuery->searchExpression($input, $this->searchType);
$this->searchQuery->publicParseSearchExpression();
}
......
......@@ -2,8 +2,10 @@
namespace Drupal\search\Plugin\views\filter;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\search\ViewsSearchQuery;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
......@@ -120,7 +122,7 @@ public function validateExposed(&$form, FormStateInterface $form_state) {
protected function queryParseSearchExpression($input) {
if (!isset($this->searchQuery)) {
$this->parsed = TRUE;
$this->searchQuery = db_select('search_index', 'i', ['target' => 'replica'])->extend('Drupal\search\ViewsSearchQuery');
$this->searchQuery = Database::getConnection('replica')->select('search_index', 'i')->extend(ViewsSearchQuery::class);
$this->searchQuery->searchExpression($input, $this->searchType);
$this->searchQuery->publicParseSearchExpression();
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\search;
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\Query\SelectInterface;
......@@ -111,7 +112,7 @@ class SearchQuery extends SelectExtender {
* This is always used for the second step in the query, but is not part of
* the preparation step unless $this->simple is FALSE.
*
* @var DatabaseCondition
* @var Drupal\Core\Database\Query\ConditionInterface[]
*/
protected $conditions;
......@@ -621,7 +622,7 @@ public function countQuery() {
$expressions = [];
// Add sid as the only field and count them as a subquery.
$count = db_select($inner->fields('i', ['sid']), NULL, ['target' => 'replica']);
$count = Database::getConnection('replica')->select($inner->fields('i', ['sid']), NULL);
// Add the COUNT() expression.
$count->addExpression('COUNT(*)');
......
......@@ -216,7 +216,7 @@ public function testMultilingualSearch() {
// Save the node again. Verify that the request time on it is not updated.
$this->searchableNodes[1]->save();
$result = db_select('search_dataset', 'd')
$result = $connection->select('search_dataset', 'd')
->fields('d', ['reindex'])
->condition('type', 'node_search')
->condition('sid', $this->searchableNodes[1]->id())
......@@ -304,7 +304,8 @@ protected function assertIndexCounts($remaining, $total, $message) {
*/
protected function assertDatabaseCounts($count_node, $count_foo, $message) {
// Count number of distinct nodes by ID.
$results = db_select('search_dataset', 'i')
$connection = Database::getConnection();
$results = $connection->select('search_dataset', 'i')
->fields('i', ['sid'])
->condition('type', 'node_search')
->groupBy('sid')
......@@ -313,7 +314,7 @@ protected function assertDatabaseCounts($count_node, $count_foo, $message) {
$this->assertEqual($count_node, count($results), 'Node count was ' . $count_node . ' for ' . $message);
// Count number of "foo" records.
$results = db_select('search_dataset', 'i')
$results = $connection->select('search_dataset', 'i')
->fields('i', ['sid'])
->condition('type', 'foo')
->execute()
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\search\Kernel;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\LanguageInterface;
use Drupal\KernelTests\KernelTestBase;
......@@ -158,8 +159,9 @@ public function _testQueries() {
'xxxxx "minim am veniam es" OR dolore' => [],
'xx "minim am veniam es" OR dolore' => [],
];
$connection = Database::getConnection();
foreach ($queries as $query => $results) {
$result = db_select('search_index', 'i')
$result = $connection->select('search_index', 'i')
->extend('Drupal\search\SearchQuery')
->searchExpression($query, static::SEARCH_TYPE)
->execute();
......@@ -179,7 +181,7 @@ public function _testQueries() {
'germany' => [11, 12],
];
foreach ($queries as $query => $results) {
$result = db_select('search_index', 'i')
$result = $connection->select('search_index', 'i')
->extend('Drupal\search\SearchQuery')
->searchExpression($query, static::SEARCH_TYPE_2)
->execute();
......@@ -202,7 +204,7 @@ public function _testQueries() {
'ヒーキ' => [],
];
foreach ($queries as $query => $results) {
$result = db_select('search_index', 'i')
$result = $connection->select('search_index', 'i')
->extend('Drupal\search\SearchQuery')
->searchExpression($query, static::SEARCH_TYPE_JPN)
->execute();
......
......@@ -108,7 +108,7 @@ public function unassignUser($account) {
* {@inheritdoc}
*/
public function getAssignedToUser($account) {
$query = db_select('shortcut_set_users', 'ssu');
$query = $this->connection->select('shortcut_set_users', 'ssu');
$query->fields('ssu', ['set_name']);
$query->condition('ssu.uid', $account->id());
return $query->execute()->fetchField();
......
......@@ -99,7 +99,7 @@ function statistics_cron() {
function statistics_title_list($dbfield, $dbrows) {
@trigger_error('statistics_title_list() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\statistics\NodeStatisticsDatabaseStorage::fetchAll() instead.', E_USER_DEPRECATED);
if (in_array($dbfield, ['totalcount', 'daycount', 'timestamp'])) {
$query = db_select('node_field_data', 'n');
$query = \Drupal::database()->select('node_field_data', 'n');