Added id to the audit logs table.
This commit is contained in:
parent
4a3d63c065
commit
a0f5444292
3 changed files with 28 additions and 7 deletions
13
database/2025_02_08_024836_added_log_entry_id_column.php
Normal file
13
database/2025_02_08_024836_added_log_entry_id_column.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,7 +65,13 @@ class AuditLogData {
|
||||||
$hasPagination = $pagination !== null;
|
$hasPagination = $pagination !== null;
|
||||||
|
|
||||||
$args = 0;
|
$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) {
|
if($hasUserInfo) {
|
||||||
++$args;
|
++$args;
|
||||||
$query .= ' WHERE user_id = ?';
|
$query .= ' WHERE user_id = ?';
|
||||||
|
|
|
@ -8,6 +8,7 @@ use Index\Db\DbResult;
|
||||||
class AuditLogInfo {
|
class AuditLogInfo {
|
||||||
/** @param scalar[] $params */
|
/** @param scalar[] $params */
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
public private(set) string $id,
|
||||||
public private(set) ?string $userId,
|
public private(set) ?string $userId,
|
||||||
public private(set) string $action,
|
public private(set) string $action,
|
||||||
public private(set) array $params,
|
public private(set) array $params,
|
||||||
|
@ -18,12 +19,13 @@ class AuditLogInfo {
|
||||||
|
|
||||||
public static function fromResult(DbResult $result): AuditLogInfo {
|
public static function fromResult(DbResult $result): AuditLogInfo {
|
||||||
return new AuditLogInfo(
|
return new AuditLogInfo(
|
||||||
userId: $result->getStringOrNull(0),
|
id: $result->getString(0),
|
||||||
action: $result->getString(1),
|
userId: $result->getStringOrNull(1),
|
||||||
params: json_decode($result->getString(2)),
|
action: $result->getString(2),
|
||||||
createdTime: $result->getInteger(3),
|
params: json_decode($result->getString(3)),
|
||||||
remoteAddress: $result->isNull(4) ? '::1' : $result->getString(4), // apparently this being NULL is possible?
|
createdTime: $result->getInteger(4),
|
||||||
countryCode: $result->getString(5),
|
remoteAddress: $result->isNull(5) ? '::1' : $result->getString(5), // apparently this being NULL is possible?
|
||||||
|
countryCode: $result->getString(6),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue