From a1e05da92053bc840fb042a6601df00de30c3750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Mon, 17 Apr 2023 01:55:37 +0200 Subject: [PATCH] add/modify template for audit logger --- templates/app.php.tpl | 2 ++ templates/database/database.sql.tpl | 13 +++++++++++++ templates/src/Database/AuditLogger.php.tpl | 11 +++++++++++ 3 files changed, 26 insertions(+) create mode 100644 templates/src/Database/AuditLogger.php.tpl diff --git a/templates/app.php.tpl b/templates/app.php.tpl index f3a2309..be77248 100644 --- a/templates/app.php.tpl +++ b/templates/app.php.tpl @@ -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 {app}\Database\AuditLogger(Container::$dbConnection, 'audit_log'); diff --git a/templates/database/database.sql.tpl b/templates/database/database.sql.tpl index 83f8ea7..40d34fc 100644 --- a/templates/database/database.sql.tpl +++ b/templates/database/database.sql.tpl @@ -13,3 +13,16 @@ CREATE TABLE `users` ( UNIQUE KEY `email` (`email`), UNIQUE KEY `google_sub` (`google_sub`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +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; diff --git a/templates/src/Database/AuditLogger.php.tpl b/templates/src/Database/AuditLogger.php.tpl new file mode 100644 index 0000000..221a412 --- /dev/null +++ b/templates/src/Database/AuditLogger.php.tpl @@ -0,0 +1,11 @@ +user()->getUniqueId(); + } +}