Skip to content

Commit

Permalink
Backport #85 and #88 from master (#89)
Browse files Browse the repository at this point in the history
* Adding microseconds for created_at property (#85)

(cherry picked from commit 4bac80b)

* Update audit clean to consider time argument as retention interval (#88)

(cherry picked from commit 61ac70d)

Co-authored-by: Samuel Chiriluta <[email protected]>
  • Loading branch information
DamienHarper and samuel4x4 authored Feb 10, 2022
1 parent 84f2e42 commit 93f7952
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private function audit(array $data): void
'blame_user_fqdn' => $data['blame']['user_fqdn'],
'blame_user_firewall' => $data['blame']['user_firewall'],
'ip' => $data['blame']['client_ip'],
'created_at' => $dt->format('Y-m-d H:i:s'),
'created_at' => $dt->format('Y-m-d H:i:s.u'),
];

// send an `AuditEvent` event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CleanAuditLogsCommand extends Command
{
use LockableTrait;

private const UNTIL_DATE_FORMAT = 'Y-m-d H:i:s';

protected static $defaultName = 'audit:clean';

/**
Expand Down Expand Up @@ -91,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$message = sprintf(
"You are about to clean audits created before <comment>%s</comment>: %d entities involved.\n Do you want to proceed?",
$until->format('Y-m-d'),
$until->format(self::UNTIL_DATE_FORMAT),
$count
);

Expand Down Expand Up @@ -122,11 +124,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$queryBuilder
->delete($auditTable)
->where('created_at < :until')
->setParameter(':until', $until->format('Y-m-d'))
->setParameter('until', $until->format(self::UNTIL_DATE_FORMAT))
;

if ($dumpSQL) {
$queries[] = str_replace(':until', "'".$until->format('Y-m-d')."'", $queryBuilder->getSQL());
$queries[] = str_replace(':until', "'".$until->format(self::UNTIL_DATE_FORMAT)."'", $queryBuilder->getSQL());
}

if (!$dryRun) {
Expand Down

0 comments on commit 93f7952

Please sign in to comment.