fixup! implement audit logger

This commit is contained in:
Bence Pőcze 2023-04-17 02:04:29 +02:00
parent ad5ef3fd48
commit 8ed2f4c15c
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D
5 changed files with 13 additions and 12 deletions

View File

@ -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;

View File

@ -1,8 +1,9 @@
<?php namespace SokoWeb\Database;
use SokoWeb\Interfaces\Database\IAuditLogger;
use SokoWeb\Interfaces\Database\IConnection;
abstract class AuditLoggerBase
abstract class AuditLoggerBase implements IAuditLogger
{
const LOG_TYPE_INSERT = 'insert';
const LOG_TYPE_UPDATE = 'update';
@ -18,7 +19,7 @@ abstract class AuditLoggerBase
$this->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,

View File

@ -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;

View File

@ -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;
}

View File

@ -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();