Skip to content

Commit

Permalink
Added developer feature to show the executed SQL queries
Browse files Browse the repository at this point in the history
Fixes #62
  • Loading branch information
MasterZydra committed Oct 3, 2024
1 parent d0fabeb commit cf1da85
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Types of changes: `Added`, `Changed`, `Deprecate`, `Removed`, `Fixed`, `Secruity

## [Unreleased]

### Added
- Added developer feature to show the executed SQL queries

## v2.6.1 - 03.10.2024 - Bugfix in 'Revenue and Profits' view

### Fixed
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/DeveloperToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function execute(): void

if (Http::requestMethod() === 'POST') {
DeveloperTools::setShowErrorMessages(Http::param('showErrorMessages') === '1');
DeveloperTools::setShowSqlQueries(Http::param('showSqlQueries') === '1');

Http::redirect('/');
}
Expand Down
7 changes: 7 additions & 0 deletions framework/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Framework\Database;

use Framework\Authentication\Session;
use Framework\Config\Config;
use Framework\Database\Interface\BlueprintInterface;
use Framework\Database\Interface\DatabaseInterface;
Expand Down Expand Up @@ -46,6 +47,9 @@ public static function executeBlueprint(BlueprintInterface $blueprint): ResultIn
public static function unprepared(string $query): ResultInterface|false
{
self::getDb();
if (Session::getValue('showSqlQueries') === 'true') {
echo $query . '<br>';
}
return self::$db->unprepared($query);
}

Expand All @@ -57,6 +61,9 @@ public static function unprepared(string $query): ResultInterface|false
public static function prepared(string $query, string $colTypes, ...$values): ResultInterface|false
{
self::getDb();
if (Session::getValue('showSqlQueries') === 'true') {
echo $query . '<br>';
}
return self::$db->prepared($query, $colTypes, ...$values);
}

Expand Down
22 changes: 22 additions & 0 deletions framework/Facades/DeveloperTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,26 @@ public static function setShowErrorMessages(bool $value): void
Session::setValue('showErrorMessages', null);
}
}

public static function showSqlQueries(): bool
{
if (!Auth::hasRole('Developer')) {
return false;
}

return Session::getValue('showSqlQueries') === 'true';
}

public static function setShowSqlQueries(bool $value): void
{
if (!Auth::hasRole('Developer')) {
return;
}

if ($value) {
Session::setValue('showSqlQueries', 'true');
} else {
Session::setValue('showSqlQueries', null);
}
}
}
1 change: 1 addition & 0 deletions resources/Lang/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
'ShowAllUsers' => 'Alle Benutzer anzeigen',
'ShowErrorMessages' => 'Fehlermeldungen anzeigen',
'ShowPayouts' => 'Auszahlungen anzeigen',
'ShowSqlQueries' => 'SQL-Abfragen anzeigen',
'ShowVolumeDistribution' => 'Mengenverteilung anzeigen',
'Street' => 'Straße',
'Subdistrict' => 'Gemarkung',
Expand Down
1 change: 1 addition & 0 deletions resources/Lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
'ShowDeliveryNotes' => 'Show all delivery notes',
'ShowErrorMessages' => 'Show error messages',
'ShowPayouts' => 'Show payouts',
'ShowSqlQueries' => 'Show SQL queries',
'ShowVolumeDistribution' => 'Show volume distribution',
'Street' => 'Street',
'Subdistrict' => 'Subdistrict',
Expand Down
9 changes: 9 additions & 0 deletions resources/Views/settings/devTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
<?= __('ShowErrorMessages') ?>
</label><br>

<label>
<input type="hidden" name="showSqlQueries" value="0">
<input type="checkbox" name="showSqlQueries" value="1"
<?php if (Session::getValue('showSqlQueries') === 'true') {
echo ' checked';
} ?>>
<?= __('ShowSqlQueries') ?>
</label><br>

<button><?= __('Save') ?></button>
</form>

Expand Down

0 comments on commit cf1da85

Please sign in to comment.