Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ private function castDatetimeUTC($model, $value)
}

if (preg_match('/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/', $value)) {
return Date::instance(Carbon::createFromFormat('Y-m-d H:i:s', $value, Date::now('UTC')->getTimezone()));
$date = Carbon::createFromFormat('Y-m-d H:i:s', $value, Date::now('UTC')->getTimezone());

if (! $date) {
return $value;
}

return Date::instance($date);
}

try {
Expand Down
16 changes: 6 additions & 10 deletions src/Drivers/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ public function prune(Auditable $model): bool
if (($threshold = $model->getAuditThreshold()) > 0) {
$auditClass = get_class($model->audits()->getModel());
$auditModel = new $auditClass;
$keyName = $auditModel->getKeyName();

return $model->audits()
->leftJoinSub(
$model->audits()->getQuery()
->select($auditModel->getKeyName())->limit($threshold)->latest(),
$model->audits()->getQuery()->select($keyName)->limit($threshold)->latest(),
'audit_threshold',
function ($join) use ($auditModel) {
$join->on(
$auditModel->gettable().'.'.$auditModel->getKeyName(),
'=',
'audit_threshold.'.$auditModel->getKeyName()
);
}
fn ($join) => $join->on(
$auditModel->getTable().".$keyName", '=', "audit_threshold.$keyName"
)
)
->whereNull('audit_threshold.'.$auditModel->getKeyName())
->whereNull("audit_threshold.$keyName")
->delete() > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resolvers/UrlResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static function resolve(Auditable $auditable): string
public static function resolveCommandLine(): string
{
$command = Request::server('argv', null);
if (is_array($command)) {
if (is_array($command)) { // @phpstan-ignore function.impossibleType
return implode(' ', $command);
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Functional/AuditingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ public function test_it_will_remove_older_audits_above_the_threshold(): void
]);

foreach (range(1, 20) as $count) {
if ($count === 11) {
sleep(1);
}
Carbon::setTestNow(now()->addSeconds($count));

$article->update([
'title' => 'Title #'.$count,
Expand Down