Files
erp_naurua/modules/system/audit.php
T

31 lines
935 B
PHP

<?php
declare(strict_types=1);
function system_write_audit_log(
PDO $pdo,
string $entityName,
string $entityId,
string $action,
?string $changedBy,
array $beforeData,
array $afterData,
array $context = []
): void {
$stmt = $pdo->prepare(
"INSERT INTO audit_log (
entity_name, entity_id, action, changed_by, before_data, after_data, context
) VALUES (
:entity_name, :entity_id, :action, :changed_by, :before_data::jsonb, :after_data::jsonb, :context::jsonb
)"
);
$stmt->execute([
':entity_name' => $entityName,
':entity_id' => $entityId,
':action' => $action,
':changed_by' => $changedBy,
':before_data' => json_encode($beforeData, JSON_THROW_ON_ERROR),
':after_data' => json_encode($afterData, JSON_THROW_ON_ERROR),
':context' => json_encode($context, JSON_THROW_ON_ERROR),
]);
}