Skip to content

Commit 0b065eb

Browse files
committed
Improve command
1 parent e2c0e4b commit 0b065eb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/Console/Commands/RemoveInvalidUploadDeleteActionLogItems.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,26 @@ public function handle()
2929
$invalidLogs = Actionlog::query()
3030
->where('action_type', 'upload deleted')
3131
->whereNull('filename')
32+
->withTrashed()
3233
->get();
3334

3435
$this->info("{$invalidLogs->count()} invalid log items found.");
3536

37+
if ($invalidLogs->count() === 0) {
38+
return 0;
39+
}
3640

37-
if ($invalidLogs->count() > 0 && $this->confirm("Do you wish to remove {$invalidLogs->count()} log items?")) {
38-
$invalidLogs->each(fn($log) => $log->delete());
41+
$this->table(['ID', 'Action Type', 'Item Type', 'Item ID', 'Created At', 'Deleted At'], $invalidLogs->map(fn($log) => [
42+
$log->id,
43+
$log->action_type,
44+
$log->item_type,
45+
$log->item_id,
46+
$log->created_at,
47+
$log->deleted_at,
48+
])->toArray());
49+
50+
if ($this->confirm("Do you wish to remove {$invalidLogs->count()} log items?")) {
51+
$invalidLogs->each(fn($log) => $log->forceDelete());
3952
}
4053

4154
return 0;

0 commit comments

Comments
 (0)