From 656ce219ef817c5d12d3f1d6a5f4d2e13b126b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 18 Apr 2023 23:31:58 +0200 Subject: [PATCH 1/3] add class AuditLogger --- src/Database/AuditLogger.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/Database/AuditLogger.php diff --git a/src/Database/AuditLogger.php b/src/Database/AuditLogger.php new file mode 100644 index 0000000..2e32009 --- /dev/null +++ b/src/Database/AuditLogger.php @@ -0,0 +1,15 @@ +user(); + if ($user === null) { + return null; + } + return $user->getUniqueId(); + } +} -- 2.45.2 From 89b0ce768b65746bd2f0a8673a801b41d912612e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 18 Apr 2023 23:32:14 +0200 Subject: [PATCH 2/3] add db table for audit log --- .../migrations/structure/20230417_0158_audit_log.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 database/migrations/structure/20230417_0158_audit_log.sql diff --git a/database/migrations/structure/20230417_0158_audit_log.sql b/database/migrations/structure/20230417_0158_audit_log.sql new file mode 100644 index 0000000..7e97a07 --- /dev/null +++ b/database/migrations/structure/20230417_0158_audit_log.sql @@ -0,0 +1,12 @@ +CREATE TABLE `audit_log` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `local_table` varchar(255) NOT NULL, + `local_id` int(10) unsigned NOT NULL, + `type` enum('insert','update','delete') NOT NULL, + `date` timestamp NOT NULL DEFAULT current_timestamp(), + `modifier_id` int(10) unsigned NULL, + `column` varchar(255) NULL, + `old` text NULL, + `new` text NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; -- 2.45.2 From cac30c92031bf693f05db30b553b527a110bbcc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 18 Apr 2023 23:35:17 +0200 Subject: [PATCH 3/3] add auditLogger instance to app container --- app.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.php b/app.php index f3a2309..d73a4f2 100644 --- a/app.php +++ b/app.php @@ -15,9 +15,11 @@ $dotenv->load(); class Container { static SokoWeb\Interfaces\Database\IConnection $dbConnection; + static SokoWeb\Interfaces\Database\IAuditLogger $auditLogger; static SokoWeb\Routing\RouteCollection $routeCollection; static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler; static SokoWeb\Interfaces\Request\IRequest $request; } Container::$dbConnection = new SokoWeb\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']); +Container::$auditLogger = new RVR\Database\AuditLogger(Container::$dbConnection, 'audit_log'); -- 2.45.2