Skip to content

Commit 1217a02

Browse files
authored
Merge pull request #17992 from marcusmoore/17963-undelete-files-command
Added command to remove invalid "upload deleted" entries from the action log
2 parents 49ecc93 + 5a13d5e commit 1217a02

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Actionlog;
6+
use Illuminate\Console\Command;
7+
8+
class RemoveInvalidUploadDeleteActionLogItems extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'snipeit:remove-invalid-upload-delete-action-log-items';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Permanently remove invalid "upload deleted" action log items that have a null filename. This command can potentially result in deleted files being "resurrected" in the UI.';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
$invalidLogs = Actionlog::query()
30+
->where('action_type', 'upload deleted')
31+
->whereNull('filename')
32+
->withTrashed()
33+
->get();
34+
35+
$this->info("{$invalidLogs->count()} invalid log items found.");
36+
37+
if ($invalidLogs->count() === 0) {
38+
return 0;
39+
}
40+
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());
52+
}
53+
54+
return 0;
55+
}
56+
}

0 commit comments

Comments
 (0)