Enhance audit logging with detailed operator and entity information validation and logging
This commit is contained in:
parent
f341af7ea5
commit
f2ff7f1dc7
1 changed files with 28 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use FederationServer\Classes\DatabaseConnection;
|
use FederationServer\Classes\DatabaseConnection;
|
||||||
use FederationServer\Classes\Enums\AuditLogType;
|
use FederationServer\Classes\Enums\AuditLogType;
|
||||||
|
use FederationServer\Classes\Logger;
|
||||||
use FederationServer\Exceptions\DatabaseOperationException;
|
use FederationServer\Exceptions\DatabaseOperationException;
|
||||||
use FederationServer\Objects\AuditLogRecord;
|
use FederationServer\Objects\AuditLogRecord;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
@ -28,6 +29,33 @@
|
||||||
throw new InvalidArgumentException("Message cannot be empty.");
|
throw new InvalidArgumentException("Message cannot be empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($operator !== null && strlen($operator) === 0)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException("Operator UUID cannot be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if($entity !== null && strlen($entity) === 0)
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException("Entity UUID cannot be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if($operator !== null && $entity !== null)
|
||||||
|
{
|
||||||
|
Logger::log()->info(sprintf("Audit Entry [%s] %s by %s on %s", $type->value, $message, $operator, $entity));
|
||||||
|
}
|
||||||
|
elseif($operator !== null)
|
||||||
|
{
|
||||||
|
Logger::log()->info(sprintf("Audit Entry [%s] %s by %s", $type->value, $message, $operator));
|
||||||
|
}
|
||||||
|
elseif($entity !== null)
|
||||||
|
{
|
||||||
|
Logger::log()->info(sprintf("Audit Entry [%s] %s on %s", $type->value, $message, $entity));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::log()->info(sprintf("Audit Entry [%s] %s", $type->value, $message));
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$stmt = DatabaseConnection::getConnection()->prepare("INSERT INTO audit_log (type, message, operator, entity) VALUES (:type, :message, :operator, :entity)");
|
$stmt = DatabaseConnection::getConnection()->prepare("INSERT INTO audit_log (type, message, operator, entity) VALUES (:type, :message, :operator, :entity)");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue