Skip to content

Commit b83ec9e

Browse files
authored
Merge pull request #1033 from cakephp/5.x-connection-role
add connection role to SQL Log Panel queries
2 parents cc0d0b9 + dd4ec06 commit b83ec9e

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
33
<file src="src/Database/Log/DebugLog.php">
44
<InternalMethod>
5+
<code><![CDATA[getContext]]></code>
56
<code><![CDATA[jsonSerialize]]></code>
67
</InternalMethod>
78
</file>

src/Database/Log/DebugLog.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public function totalTime(): float
134134
*/
135135
public function log($level, string|Stringable $message, array $context = []): void
136136
{
137+
/** @var \Cake\Database\Log\LoggedQuery|object|null $query */
137138
$query = $context['query'] ?? null;
138139

139140
if ($this->_logger) {
@@ -153,6 +154,9 @@ public function log($level, string|Stringable $message, array $context = []): vo
153154
], JSON_PRETTY_PRINT),
154155
'took' => $took,
155156
'rows' => $context['response']['hits']['total']['value'] ?? $context['response']['hits']['total'] ?? 0,
157+
'inTransaction' => $this->inTransaction,
158+
'isCommitOrRollback' => false,
159+
'role' => '',
156160
];
157161

158162
return;
@@ -183,6 +187,7 @@ public function log($level, string|Stringable $message, array $context = []): vo
183187
'rows' => $data['numRows'],
184188
'inTransaction' => $this->inTransaction,
185189
'isCommitOrRollback' => $isCommitOrRollback,
190+
'role' => $query->getContext()['role'],
186191
];
187192

188193
if ($isCommitOrRollback) {

templates/element/sql_log_panel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<th>Query</th>
7070
<th>Rows</th>
7171
<th>Took (ms)</th>
72+
<th>Role</th>
7273
</tr>
7374
</thead>
7475
<tbody>
@@ -90,6 +91,7 @@
9091
</td>
9192
<td><?= h($query['rows']) ?></td>
9293
<td><?= h($query['took']) ?></td>
94+
<td><?= h($query['role']) ?></td>
9395
</tr>
9496
<?php if ($query['isCommitOrRollback']): ?>
9597
<tr>

tests/TestCase/ToolbarServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function testSaveData()
260260
$this->assertSame('Timer', $result->panels[11]->panel);
261261
$this->assertSame('DebugKit.timer_panel', $result->panels[11]->element);
262262
$this->assertMatchesRegularExpression(
263-
'/\d+\.\d+\s[ms]+\s+\/\s+\d+\.\d+\s+[mbMB]+/',
263+
'/\d+\.\d+\s[ms]+\s+\/\s+\d+\.?\d+\s+[mbMB]+/',
264264
$result->panels[11]->summary
265265
);
266266
$this->assertSame('Timer', $result->panels[11]->title);

0 commit comments

Comments
 (0)