Added id to the audit logs table.

This commit is contained in:
flash 2025-02-08 02:51:03 +00:00
parent 4a3d63c065
commit a0f5444292
3 changed files with 28 additions and 7 deletions

View file

@ -0,0 +1,13 @@
<?php
use Index\Db\DbConnection;
use Index\Db\Migration\DbMigration;
final class AddedLogEntryIdColumn_20250208_024836 implements DbMigration {
public function migrate(DbConnection $conn): void {
$conn->execute(<<<SQL
ALTER TABLE msz_audit_log
ADD COLUMN log_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT FIRST,
ADD PRIMARY KEY (log_id);
SQL);
}
}

View file

@ -65,7 +65,13 @@ class AuditLogData {
$hasPagination = $pagination !== null;
$args = 0;
$query = 'SELECT user_id, log_action, log_params, UNIX_TIMESTAMP(log_created), INET6_NTOA(log_remote_addr), log_country FROM msz_audit_log';
$query = <<<SQL
SELECT log_id, user_id, log_action, log_params,
UNIX_TIMESTAMP(log_created),
INET6_NTOA(log_remote_addr),
log_country
FROM msz_audit_log
SQL;
if($hasUserInfo) {
++$args;
$query .= ' WHERE user_id = ?';

View file

@ -8,6 +8,7 @@ use Index\Db\DbResult;
class AuditLogInfo {
/** @param scalar[] $params */
public function __construct(
public private(set) string $id,
public private(set) ?string $userId,
public private(set) string $action,
public private(set) array $params,
@ -18,12 +19,13 @@ class AuditLogInfo {
public static function fromResult(DbResult $result): AuditLogInfo {
return new AuditLogInfo(
userId: $result->getStringOrNull(0),
action: $result->getString(1),
params: json_decode($result->getString(2)),
createdTime: $result->getInteger(3),
remoteAddress: $result->isNull(4) ? '::1' : $result->getString(4), // apparently this being NULL is possible?
countryCode: $result->getString(5),
id: $result->getString(0),
userId: $result->getStringOrNull(1),
action: $result->getString(2),
params: json_decode($result->getString(3)),
createdTime: $result->getInteger(4),
remoteAddress: $result->isNull(5) ? '::1' : $result->getString(5), // apparently this being NULL is possible?
countryCode: $result->getString(6),
);
}