diff --git a/core/lib/Drupal/Core/Batch/BatchStorage.php b/core/lib/Drupal/Core/Batch/BatchStorage.php index cce0379e2d6422d967cffbd6ff4a07510dfa0672..46f9fb97c0d6359da0cbd84279ba4bdd92b77523 100644 --- a/core/lib/Drupal/Core/Batch/BatchStorage.php +++ b/core/lib/Drupal/Core/Batch/BatchStorage.php @@ -42,10 +42,12 @@ public function load($id) { // Ensure that a session is started before using the CSRF token generator. $this->session->start(); try { - $batch = $this->connection->query("SELECT [batch] FROM {batch} WHERE [bid] = :bid AND [token] = :token", [ - ':bid' => $id, - ':token' => $this->csrfToken->get($id), - ])->fetchField(); + $batch = $this->connection->select('batch', 'b') + ->fields('b', ['batch']) + ->condition('bid', $id) + ->condition('token', $this->csrfToken->get($id)) + ->execute() + ->fetchField(); } catch (\Exception $e) { $this->catchException($e); diff --git a/core/lib/Drupal/Core/Queue/Batch.php b/core/lib/Drupal/Core/Queue/Batch.php index 53082a04df37029bfb1bfb991effa3f54c57fa60..1b71959ba20341d843fba1900ff6c4a1bb76a7fd 100644 --- a/core/lib/Drupal/Core/Queue/Batch.php +++ b/core/lib/Drupal/Core/Queue/Batch.php @@ -50,7 +50,13 @@ public function claimItem($lease_time = 0) { public function getAllItems() { $result = []; try { - $items = $this->connection->query('SELECT [data] FROM {queue} q WHERE [name] = :name ORDER BY [item_id] ASC', [':name' => $this->name])->fetchAll(); + $items = $this->connection->select('queue', 'q') + ->fields('q', ['data']) + ->condition('name', $this->name) + ->orderBy('item_id', 'ASC') + ->execute() + ->fetchAll(); + foreach ($items as $item) { $result[] = unserialize($item->data); } diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index 134bc225807ab6571c3bb3fbe1039fde72470525..505996b40b262c38b4163418991d2e0d458ae060 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -227,7 +227,12 @@ public function overview(Request $request) { * If no event found for the given ID. */ public function eventDetails($event_id) { - $dblog = $this->database->query('SELECT [w].*, [u].[uid] FROM {watchdog} [w] LEFT JOIN {users} [u] ON [u].[uid] = [w].[uid] WHERE [w].[wid] = :id', [':id' => $event_id])->fetchObject(); + $query = $this->database->select('watchdog', 'w') + ->fields('w') + ->condition('w.wid', $event_id); + $query->leftJoin('users', 'u', '[u].[uid] = [w].[uid]'); + $query->addField('u', 'uid', 'uid'); + $dblog = $query->execute()->fetchObject(); if (empty($dblog)) { throw new NotFoundHttpException(); diff --git a/core/modules/dblog/src/Plugin/rest/resource/DbLogResource.php b/core/modules/dblog/src/Plugin/rest/resource/DbLogResource.php index c3174469e5cff7e97dfdbb9e1b99049226733b61..d9de3987af980fdcd32118813db2a7b7d0f70b41 100644 --- a/core/modules/dblog/src/Plugin/rest/resource/DbLogResource.php +++ b/core/modules/dblog/src/Plugin/rest/resource/DbLogResource.php @@ -40,7 +40,10 @@ class DbLogResource extends ResourceBase { */ public function get($id = NULL) { if ($id) { - $record = Database::getConnection()->query("SELECT * FROM {watchdog} WHERE [wid] = :wid", [':wid' => $id]) + $record = Database::getConnection()->select('watchdog', 'w') + ->fields('w') + ->condition('wid', $id) + ->execute() ->fetchAssoc(); if (!empty($record)) { return new ResourceResponse($record); diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index b716792214989c961bc13510223064574ed7f7ce..7265819cf37028faeb8e11d19c45a11d766a4f30 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -291,7 +291,9 @@ protected function testMessageParsing(): void { ['foo' => 'bar', 'path' => '/baz', 'value' => 'horse'] ); // View the log page to verify it's correct. - $wid = \Drupal::database()->query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); + $query = Database::getConnection()->select('watchdog'); + $query->addExpression('MAX([wid])'); + $wid = $query->execute()->fetchField(); $this->drupalGet('admin/reports/dblog/event/' . $wid); $this->assertSession() ->responseContains('Incorrect parameter {bar} in path /baz: horse'); diff --git a/core/modules/history/history.module b/core/modules/history/history.module index f30ec39d880e8f1b12ce7fcd7aa6cac7e0dd668f..ca271da5a765a57ad187641c745f95303f43f238 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -81,10 +81,11 @@ function history_read_multiple($nids) { return $return; } - $result = \Drupal::database()->query('SELECT [nid], [timestamp] FROM {history} WHERE [uid] = :uid AND [nid] IN ( :nids[] )', [ - ':uid' => \Drupal::currentUser()->id(), - ':nids[]' => array_keys($nodes_to_read), - ]); + $result = \Drupal::database()->select('history', 'h') + ->fields('h', ['nid', 'timestamp']) + ->condition('uid', \Drupal::currentUser()->id()) + ->condition('nid', array_keys($nodes_to_read), 'IN') + ->execute(); foreach ($result as $row) { $nodes_to_read[$row->nid] = (int) $row->timestamp; } diff --git a/core/modules/history/tests/src/Functional/HistoryTest.php b/core/modules/history/tests/src/Functional/HistoryTest.php index 6b46431826a93485f4248d86501e96908a41c743..b2ef520f9fd7f4617de058ea16604ba9deb3bcc1 100644 --- a/core/modules/history/tests/src/Functional/HistoryTest.php +++ b/core/modules/history/tests/src/Functional/HistoryTest.php @@ -158,7 +158,10 @@ public function testHistory(): void { $this->assertEquals(403, $response->getStatusCode()); // Additional check to ensure that we did not forget to verify anything. - $rows = \Drupal::database()->query('SELECT * FROM {history}')->fetchAll(); + $rows = \Drupal::database()->select('history') + ->fields('history', ['nid', 'uid', 'timestamp']) + ->execute() + ->fetchAll(); $this->assertCount(1, $rows); $this->assertSame($this->user->id(), $rows[0]->uid); $this->assertSame($this->testNode->id(), $rows[0]->nid); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 88fbdfe04d5b4266aee34a92db106c35d7d18f11..9124aa29cc7b348eb91e86b7ce27b3e9ea19a0a9 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -781,7 +781,10 @@ function locale_translation_get_file_history() { if (empty($history)) { // Get file history from the database. - $result = \Drupal::database()->query('SELECT [project], [langcode], [filename], [version], [uri], [timestamp], [last_checked] FROM {locale_file}'); + $result = \Drupal::database()->select('locale_file') + ->fields('locale_file', ['project', 'langcode', 'filename', 'version', 'uri', 'timestamp', 'last_checked']) + ->execute() + ->fetchAll(); foreach ($result as $file) { $file->type = $file->timestamp ? LOCALE_TRANSLATION_CURRENT : ''; $history[$file->project][$file->langcode] = $file; diff --git a/core/modules/shortcut/src/ShortcutSetStorage.php b/core/modules/shortcut/src/ShortcutSetStorage.php index b68bf8b469b20fbae3729bc4dbea985b3d83eba6..c2bccb9387c72c0d3707147453ca96d7cf58f23b 100644 --- a/core/modules/shortcut/src/ShortcutSetStorage.php +++ b/core/modules/shortcut/src/ShortcutSetStorage.php @@ -138,7 +138,11 @@ public function getDisplayedToUser(AccountInterface $account): ShortcutSetInterf * {@inheritdoc} */ public function countAssignedUsers(ShortcutSetInterface $shortcut_set) { - return Database::getConnection()->query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE [set_name] = :name', [':name' => $shortcut_set->id()])->fetchField(); + return Database::getConnection()->select('shortcut_set_users') + ->condition('set_name', $shortcut_set->id()) + ->countQuery() + ->execute() + ->fetchField(); } /** diff --git a/core/tests/Drupal/FunctionalTests/Entity/RevisionDeleteFormTest.php b/core/tests/Drupal/FunctionalTests/Entity/RevisionDeleteFormTest.php index 16ff2a0103dc354f431848c873bcd8109bf19b30..e775b358550a326d10835a67a94c89e31034aa84 100644 --- a/core/tests/Drupal/FunctionalTests/Entity/RevisionDeleteFormTest.php +++ b/core/tests/Drupal/FunctionalTests/Entity/RevisionDeleteFormTest.php @@ -362,7 +362,11 @@ public static function providerSubmitForm(): array { * Watchdog entries. */ protected function getLogs(string $channel): array { - $logs = \Drupal::database()->query("SELECT * FROM {watchdog} WHERE type = :type", [':type' => $channel])->fetchAll(); + $logs = \Drupal::database()->select('watchdog') + ->fields('watchdog') + ->condition('type', $channel) + ->execute() + ->fetchAll(); return array_map(function (object $log) { return (string) new FormattableMarkup($log->message, unserialize($log->variables)); }, $logs); diff --git a/core/tests/Drupal/FunctionalTests/Entity/RevisionRevertFormTest.php b/core/tests/Drupal/FunctionalTests/Entity/RevisionRevertFormTest.php index 356f38cf8c86b82be8e412342356e7de0efa7462..c6ff4629fd9b7bb92a64d25152105849c2b1d4b4 100644 --- a/core/tests/Drupal/FunctionalTests/Entity/RevisionRevertFormTest.php +++ b/core/tests/Drupal/FunctionalTests/Entity/RevisionRevertFormTest.php @@ -347,7 +347,11 @@ protected function testPrepareRevision(): void { * Watchdog entries. */ protected function getLogs(string $channel): array { - $logs = \Drupal::database()->query("SELECT * FROM {watchdog} WHERE type = :type", [':type' => $channel])->fetchAll(); + $logs = \Drupal::database()->select('watchdog') + ->fields('watchdog') + ->condition('type', $channel) + ->execute() + ->fetchAll(); return array_map(function (object $log) { return (string) new FormattableMarkup($log->message, unserialize($log->variables)); }, $logs);