From 65464cd4a302edf8be3a4e576aa5f09a9be0b7ff Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 5 Apr 2025 09:49:04 +0200 Subject: [PATCH 1/2] fix: debugbar when maxHistory is set to 0 --- system/Debug/Toolbar.php | 2 +- system/Debug/Toolbar/Views/toolbar.js | 22 +++++++++++---------- user_guide_src/source/changelogs/v4.6.1.rst | 2 ++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 9a884b60f5b3..7900c7c780c5 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -512,7 +512,7 @@ protected function format(string $data, string $format = 'html'): string { $data = json_decode($data, true); - if ($this->config->maxHistory !== 0 && preg_match('/\d+\.\d{6}/s', (string) service('request')->getGet('debugbar_time'), $debugbarTime)) { + if (preg_match('/\d+\.\d{6}/s', (string) service('request')->getGet('debugbar_time'), $debugbarTime)) { $history = new History(); $history->setFiles( $debugbarTime[0], diff --git a/system/Debug/Toolbar/Views/toolbar.js b/system/Debug/Toolbar/Views/toolbar.js index 54fe3d69f106..4be9e6e4f1d0 100644 --- a/system/Debug/Toolbar/Views/toolbar.js +++ b/system/Debug/Toolbar/Views/toolbar.js @@ -27,11 +27,13 @@ var ciDebugBar = { .getElementById("debug-icon-link") .addEventListener("click", ciDebugBar.toggleToolbar, true); - // Allows to highlight the row of the current history request - var btn = this.toolbar.querySelector( - 'button[data-time="' + localStorage.getItem("debugbar-time") + '"]' - ); - ciDebugBar.addClass(btn.parentNode.parentNode, "current"); + if (this.toolbar.querySelector(".ci-history-load")) { + // Allows highlighting the row of the current history request + var btn = this.toolbar.querySelector( + 'button[data-time="' + localStorage.getItem("debugbar-time") + '"]' + ); + ciDebugBar.addClass(btn.parentNode.parentNode, "current"); + } historyLoad = this.toolbar.getElementsByClassName("ci-history-load"); @@ -77,14 +79,14 @@ var ciDebugBar = { links[i].addEventListener("click", function() { ciDebugBar.toggleDataTable(datatable) }, true); - + } else if (toggleData === "childrows") { let child = links[i].getAttribute("data-child"); links[i].addEventListener("click", function() { ciDebugBar.toggleChildRows(child) }, true); - + } else { links[i].addEventListener("click", ciDebugBar.toggleRows, true); } @@ -174,10 +176,10 @@ var ciDebugBar = { ); if (target.classList.contains("debug-bar-ndisplay")) { - ciDebugBar.switchClass(target, "debug-bar-ndisplay", "debug-bar-dtableRow"); + ciDebugBar.switchClass(target, "debug-bar-ndisplay", "debug-bar-dtableRow"); } else { ciDebugBar.switchClass(target, "debug-bar-dtableRow", "debug-bar-ndisplay"); - } + } } }, @@ -261,7 +263,7 @@ var ciDebugBar = { } else { ciDebugBar.switchClass(ciDebugBar.icon, "debug-bar-dinlineBlock", "debug-bar-ndisplay"); ciDebugBar.switchClass(ciDebugBar.toolbar, "debug-bar-ndisplay", "debug-bar-dinlineBlock"); - } + } }, toggleViewsHints: function () { diff --git a/user_guide_src/source/changelogs/v4.6.1.rst b/user_guide_src/source/changelogs/v4.6.1.rst index 77fa4799e37e..495fcd1b3af5 100644 --- a/user_guide_src/source/changelogs/v4.6.1.rst +++ b/user_guide_src/source/changelogs/v4.6.1.rst @@ -35,6 +35,8 @@ Bugs Fixed - **Database:** Fixed a bug in ``Postgre`` and ``SQLite3`` handlers where composite unique keys were not fully taken into account for ``upsert`` type of queries. - **Database:** Fixed a bug in the ``OCI8`` and ``SQLSRV`` drivers where ``getVersion()`` returned an empty string when the database connection was not yet established. - **Logger:** Fixed a bug where the ``{line}`` variable couldn't be used without specifying the ``{file}`` variable when logging the message. +- **Toolbar:** Fixed a bug where setting ``maxHistory`` to ``0`` would produce a JavaScript error in the Debug Toolbar. +- **Toolbar:** Fixed a bug where setting ``maxHistory`` to ``0`` prevented log files from being properly cleared. See the repo's `CHANGELOG.md `_ From 353c0e3703d8ff4bd4b6eaf2594bd3ddba0512c6 Mon Sep 17 00:00:00 2001 From: michalsn Date: Sat, 5 Apr 2025 13:18:13 +0200 Subject: [PATCH 2/2] apply code suggestion - make use of the historyLoad variable --- system/Debug/Toolbar/Views/toolbar.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/system/Debug/Toolbar/Views/toolbar.js b/system/Debug/Toolbar/Views/toolbar.js index 4be9e6e4f1d0..ddaa2386f260 100644 --- a/system/Debug/Toolbar/Views/toolbar.js +++ b/system/Debug/Toolbar/Views/toolbar.js @@ -27,24 +27,25 @@ var ciDebugBar = { .getElementById("debug-icon-link") .addEventListener("click", ciDebugBar.toggleToolbar, true); - if (this.toolbar.querySelector(".ci-history-load")) { + historyLoad = this.toolbar.getElementsByClassName("ci-history-load"); + + if (historyLoad.length) { // Allows highlighting the row of the current history request var btn = this.toolbar.querySelector( - 'button[data-time="' + localStorage.getItem("debugbar-time") + '"]' + 'button[data-time="' + localStorage.getItem("debugbar-time-new") + '"]' ); ciDebugBar.addClass(btn.parentNode.parentNode, "current"); - } - historyLoad = this.toolbar.getElementsByClassName("ci-history-load"); - for (var i = 0; i < historyLoad.length; i++) { - historyLoad[i].addEventListener( - "click", - function () { - loadDoc(this.getAttribute("data-time")); - }, - true - ); + for (var i = 0; i < historyLoad.length; i++) { + historyLoad[i].addEventListener( + "click", + function () { + loadDoc(this.getAttribute("data-time")); + }, + true + ); + } } // Display the active Tab on page load