From 8ed2f4c15c17b0cce1df3f76006416e770f5273e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Mon, 17 Apr 2023 02:04:29 +0200 Subject: [PATCH] fixup! implement audit logger --- dummy.php | 1 + src/Database/AuditLoggerBase.php | 9 +++++---- src/Database/Query/Modify.php | 5 ++--- src/Interfaces/Database/IAuditLogger.php | 6 +++--- src/PersistentData/PersistentDataManager.php | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dummy.php b/dummy.php index f3e0693..0437e18 100644 --- a/dummy.php +++ b/dummy.php @@ -7,6 +7,7 @@ const ROOT = __DIR__; 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; diff --git a/src/Database/AuditLoggerBase.php b/src/Database/AuditLoggerBase.php index d8310fa..e50f43c 100644 --- a/src/Database/AuditLoggerBase.php +++ b/src/Database/AuditLoggerBase.php @@ -1,8 +1,9 @@ logTable = $logTable; } - public function logInsert(string $localTable, $localId) + public function logInsert(string $localTable, $localId): void { $data = [ 'local_table' => $localTable, @@ -32,7 +33,7 @@ abstract class AuditLoggerBase $stmt->execute($data); } - public function logUpdate(string $localTable, $localId, array $diff) + public function logUpdate(string $localTable, $localId, array $diff): void { $data = [ 'local_table' => $localTable, @@ -55,7 +56,7 @@ abstract class AuditLoggerBase } } - public function logDelete(string $localTable, $localId, array $attributes) + public function logDelete(string $localTable, $localId, array $attributes): void { $data = [ 'local_table' => $localTable, diff --git a/src/Database/Query/Modify.php b/src/Database/Query/Modify.php index fa5d7a4..8246e0e 100755 --- a/src/Database/Query/Modify.php +++ b/src/Database/Query/Modify.php @@ -2,7 +2,6 @@ use SokoWeb\Interfaces\Database\IConnection; use SokoWeb\Database\Utils; -use SokoWeb\Database\AuditLoggerBase; use SokoWeb\Interfaces\Database\IAuditLogger; use SokoWeb\Interfaces\Database\IResultSet; @@ -12,7 +11,7 @@ class Modify private string $table; - private ?AuditLoggerBase $auditLogger; + private ?IAuditLogger $auditLogger; private string $idName = 'id'; @@ -24,7 +23,7 @@ class Modify private ?array $diff = null; - public function __construct(IConnection $connection, string $table, ?AuditLoggerBase $auditLogger = null) + public function __construct(IConnection $connection, string $table, ?IAuditLogger $auditLogger = null) { $this->connection = $connection; $this->table = $table; diff --git a/src/Interfaces/Database/IAuditLogger.php b/src/Interfaces/Database/IAuditLogger.php index e60d4cc..1bb8d6d 100644 --- a/src/Interfaces/Database/IAuditLogger.php +++ b/src/Interfaces/Database/IAuditLogger.php @@ -2,9 +2,9 @@ interface IAuditLogger { - public function auditInsert(): void; + public function logInsert(string $localTable, $localId): void; - public function auditUpdate(): void; + public function logUpdate(string $localTable, $localId, array $diff): void; - public function auditDelete(): void; + public function logDelete(string $localTable, $localId, array $attributes): void; } diff --git a/src/PersistentData/PersistentDataManager.php b/src/PersistentData/PersistentDataManager.php index b199548..42dcb33 100644 --- a/src/PersistentData/PersistentDataManager.php +++ b/src/PersistentData/PersistentDataManager.php @@ -117,7 +117,7 @@ class PersistentDataManager $modified = $model->toArray(); $id = $model->getId(); - $modify = new Modify(\Container::$dbConnection, $model::getTable()); + $modify = new Modify(\Container::$dbConnection, $model::getTable(), \Container::$auditLogger); if ($id !== null) { $original = $model->getSnapshot(); @@ -149,7 +149,7 @@ class PersistentDataManager public function deleteFromDb(Model $model): void { - $modify = new Modify(\Container::$dbConnection, $model::getTable()); + $modify = new Modify(\Container::$dbConnection, $model::getTable(), \Container::$auditLogger); $modify->setId($model->getId()); $modify->delete();