Last active
November 10, 2021 11:34
-
-
Save codebymikey/861fca170650b75dac20d352a116f457 to your computer and use it in GitHub Desktop.
Drupal 8 log queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: core/lib/Drupal/Core/Database/Query/Select.php | |
| Description: Log RAW SELECT queries in Drupal 9. | |
| IDEA additional info: | |
| Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
| <+>UTF-8 | |
| =================================================================== | |
| diff --git a/core/lib/Drupal/Core/Database/Query/Select.php b/core/lib/Drupal/Core/Database/Query/Select.php | |
| --- a//core/lib/Drupal/Core/Database/Query/Select.php | |
| +++ b//core/lib/Drupal/Core/Database/Query/Select.php (date 1636458764911) | |
| @@ -509,7 +509,33 @@ | |
| } | |
| $args = $this->getArguments(); | |
| - return $this->connection->query((string) $this, $args, $this->queryOptions); | |
| + $sql = (string) $this; | |
| + | |
| + if (\Drupal\Core\Site\Settings::get('log_queries', TRUE)) { | |
| + if (!isset($GLOBALS['zm_query_logs'])) { | |
| + $GLOBALS['zm_query_logs'] = []; | |
| + } | |
| + $connection = Database::getConnection(); | |
| + | |
| + $result = $connection->prefixTables($sql); | |
| + $quoted = []; | |
| + foreach ((array) $this->arguments() as $key => $data) { | |
| + if (substr($key, -2) === '[]') { | |
| + $values = []; | |
| + foreach (array_values($data) as $value) { | |
| + $values[] = $value === NULL ? 'NULL' : $connection->quote($value); | |
| + } | |
| + $quoted[$key] = implode(', ', $values); | |
| + } | |
| + else { | |
| + $quoted[$key] = $data === NULL ? 'NULL' : $connection->quote($data); | |
| + } | |
| + } | |
| + $result = $connection->quoteIdentifiers(strtr($result, $quoted)); | |
| + $GLOBALS['zm_query_logs'][] = $result; | |
| + } | |
| + | |
| + return $this->connection->query($sql, $args, $this->queryOptions); | |
| } | |
| /** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment