From d97e2980ecc2e127366df87d480d3408abeec42c Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Dec 2024 13:54:53 +0100 Subject: [PATCH 1/3] add styling for queries which are run inside a transaction --- src/Database/Log/DebugLog.php | 23 ++++++++++++++++++++++- templates/element/sql_log_panel.php | 10 ++++++++-- webroot/css/style.css | 6 ++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Database/Log/DebugLog.php b/src/Database/Log/DebugLog.php index 8403f1321..a9e6d22be 100644 --- a/src/Database/Log/DebugLog.php +++ b/src/Database/Log/DebugLog.php @@ -65,6 +65,13 @@ class DebugLog extends AbstractLogger */ protected bool $_includeSchema = false; + /** + * Whether a transaction is currently open or not. + * + * @var bool + */ + protected bool $inTransaction = false; + /** * Constructor * @@ -162,11 +169,25 @@ public function log($level, string|Stringable $message, array $context = []): vo $this->_totalTime += $data['took']; + $sql = (string)$query; + $isBegin = $sql === 'BEGIN'; + $isCommitOrRollback = $sql === 'COMMIT' || $sql === 'ROLLBACK'; + + if ($isBegin) { + $this->inTransaction = true; + } + $this->_queries[] = [ - 'query' => (string)$query, + 'query' => $sql, 'took' => $data['took'], 'rows' => $data['numRows'], + 'inTransaction' => $this->inTransaction, + 'isCommitOrRollback' => $isCommitOrRollback, ]; + + if ($isCommitOrRollback) { + $this->inTransaction = false; + } } /** diff --git a/templates/element/sql_log_panel.php b/templates/element/sql_log_panel.php index 4fbba0c93..1ab545a48 100644 --- a/templates/element/sql_log_panel.php +++ b/templates/element/sql_log_panel.php @@ -73,7 +73,7 @@ - + > + + + + + + @@ -99,6 +105,6 @@ -
No active database connections
+
No active database connections
diff --git a/webroot/css/style.css b/webroot/css/style.css index d6d1e894e..fa886deab 100644 --- a/webroot/css/style.css +++ b/webroot/css/style.css @@ -60,6 +60,8 @@ --packages-warning: #ffcc00; --packages-link: #000; + --sql-log-transaction: #d8d8d8; + --routes-btn-active-bg: #fff; --routes-btn-active-text: #555; --routes-btn-active-border: #6f6f6f; @@ -605,6 +607,10 @@ strong { box-shadow: 0 2px 0 var(--routes-btn-active-border); } +.c-sql-log-panel__entry .in-transaction { + background: var(--sql-log-transaction); +} + .c-toolbar { display: flex; background: var(--toolbar-bg); From 4bebabfacdb032f027dba91e91845dba13ff75d0 Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Dec 2024 14:34:16 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: ADmad --- templates/element/sql_log_panel.php | 2 +- webroot/css/style.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/element/sql_log_panel.php b/templates/element/sql_log_panel.php index 1ab545a48..7e6e6d52f 100644 --- a/templates/element/sql_log_panel.php +++ b/templates/element/sql_log_panel.php @@ -91,7 +91,7 @@ - + diff --git a/webroot/css/style.css b/webroot/css/style.css index fa886deab..ea077c46a 100644 --- a/webroot/css/style.css +++ b/webroot/css/style.css @@ -608,7 +608,7 @@ strong { } .c-sql-log-panel__entry .in-transaction { - background: var(--sql-log-transaction); + background: var(--cake-light-gray); } .c-toolbar { From 95c834a6830242cf7de25fdff3c0f8beade076aa Mon Sep 17 00:00:00 2001 From: Kevin Pfeifer Date: Sun, 29 Dec 2024 15:19:48 +0100 Subject: [PATCH 3/3] remove css variable --- webroot/css/style.css | 2 -- 1 file changed, 2 deletions(-) diff --git a/webroot/css/style.css b/webroot/css/style.css index ea077c46a..00ec962b2 100644 --- a/webroot/css/style.css +++ b/webroot/css/style.css @@ -60,8 +60,6 @@ --packages-warning: #ffcc00; --packages-link: #000; - --sql-log-transaction: #d8d8d8; - --routes-btn-active-bg: #fff; --routes-btn-active-text: #555; --routes-btn-active-border: #6f6f6f;