fixup! implement audit logger
This commit is contained in:
parent
ad5ef3fd48
commit
8ed2f4c15c
@ -7,6 +7,7 @@ const ROOT = __DIR__;
|
|||||||
class Container
|
class Container
|
||||||
{
|
{
|
||||||
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
|
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
|
||||||
|
static SokoWeb\Interfaces\Database\IAuditLogger $auditLogger;
|
||||||
static SokoWeb\Routing\RouteCollection $routeCollection;
|
static SokoWeb\Routing\RouteCollection $routeCollection;
|
||||||
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
|
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
|
||||||
static SokoWeb\Interfaces\Request\IRequest $request;
|
static SokoWeb\Interfaces\Request\IRequest $request;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php namespace SokoWeb\Database;
|
<?php namespace SokoWeb\Database;
|
||||||
|
|
||||||
|
use SokoWeb\Interfaces\Database\IAuditLogger;
|
||||||
use SokoWeb\Interfaces\Database\IConnection;
|
use SokoWeb\Interfaces\Database\IConnection;
|
||||||
|
|
||||||
abstract class AuditLoggerBase
|
abstract class AuditLoggerBase implements IAuditLogger
|
||||||
{
|
{
|
||||||
const LOG_TYPE_INSERT = 'insert';
|
const LOG_TYPE_INSERT = 'insert';
|
||||||
const LOG_TYPE_UPDATE = 'update';
|
const LOG_TYPE_UPDATE = 'update';
|
||||||
@ -18,7 +19,7 @@ abstract class AuditLoggerBase
|
|||||||
$this->logTable = $logTable;
|
$this->logTable = $logTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logInsert(string $localTable, $localId)
|
public function logInsert(string $localTable, $localId): void
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'local_table' => $localTable,
|
'local_table' => $localTable,
|
||||||
@ -32,7 +33,7 @@ abstract class AuditLoggerBase
|
|||||||
$stmt->execute($data);
|
$stmt->execute($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logUpdate(string $localTable, $localId, array $diff)
|
public function logUpdate(string $localTable, $localId, array $diff): void
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'local_table' => $localTable,
|
'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 = [
|
$data = [
|
||||||
'local_table' => $localTable,
|
'local_table' => $localTable,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use SokoWeb\Interfaces\Database\IConnection;
|
use SokoWeb\Interfaces\Database\IConnection;
|
||||||
use SokoWeb\Database\Utils;
|
use SokoWeb\Database\Utils;
|
||||||
use SokoWeb\Database\AuditLoggerBase;
|
|
||||||
use SokoWeb\Interfaces\Database\IAuditLogger;
|
use SokoWeb\Interfaces\Database\IAuditLogger;
|
||||||
use SokoWeb\Interfaces\Database\IResultSet;
|
use SokoWeb\Interfaces\Database\IResultSet;
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ class Modify
|
|||||||
|
|
||||||
private string $table;
|
private string $table;
|
||||||
|
|
||||||
private ?AuditLoggerBase $auditLogger;
|
private ?IAuditLogger $auditLogger;
|
||||||
|
|
||||||
private string $idName = 'id';
|
private string $idName = 'id';
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ class Modify
|
|||||||
|
|
||||||
private ?array $diff = null;
|
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->connection = $connection;
|
||||||
$this->table = $table;
|
$this->table = $table;
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
interface IAuditLogger
|
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;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ class PersistentDataManager
|
|||||||
$modified = $model->toArray();
|
$modified = $model->toArray();
|
||||||
$id = $model->getId();
|
$id = $model->getId();
|
||||||
|
|
||||||
$modify = new Modify(\Container::$dbConnection, $model::getTable());
|
$modify = new Modify(\Container::$dbConnection, $model::getTable(), \Container::$auditLogger);
|
||||||
|
|
||||||
if ($id !== null) {
|
if ($id !== null) {
|
||||||
$original = $model->getSnapshot();
|
$original = $model->getSnapshot();
|
||||||
@ -149,7 +149,7 @@ class PersistentDataManager
|
|||||||
|
|
||||||
public function deleteFromDb(Model $model): void
|
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->setId($model->getId());
|
||||||
$modify->delete();
|
$modify->delete();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user