generated from jric11/baseProject
Chat's updates for security, db and workflow
Security and workflow regressions / regression (push) Has been cancelled
Security and workflow regressions / regression (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
final class Audit {
|
||||
|
||||
public static function record(PDO $db, int $user, string $event): void {
|
||||
try {
|
||||
self::insert($db, $user, $event);
|
||||
} catch (Throwable $e) {
|
||||
error_log('Audit write failed: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function required(PDO $db, int $user, string $event): void {
|
||||
if (!$db->inTransaction())
|
||||
throw new LogicException('Required audit writes need a transaction.');
|
||||
self::insert($db, $user, $event);
|
||||
}
|
||||
|
||||
public static function insert(PDO $db, int $user, string $event): void {
|
||||
$stmt = $db->prepare('INSERT INTO journal(journal_origin,journal_ip,journal_entry) VALUES(?,?,?)');
|
||||
$stmt->execute([(string) $user, $_SERVER['REMOTE_ADDR'] ?? '', $user . ' ' . $event]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user