forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteResultsData.php
More file actions
56 lines (47 loc) · 1.36 KB
/
DeleteResultsData.php
File metadata and controls
56 lines (47 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace App\Jobs;
use App\Models\Result;
use App\Models\User;
use Filament\Notifications\Notification;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\DB;
class DeleteResultsData implements ShouldBeUnique, ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Execute the job.
*/
public function handle(): void
{
$count = Result::count();
$recipient = User::first();
try {
DB::table('results')->truncate();
} catch (\Throwable $th) {
Notification::make()
->title('There was a problem deleting speedtest results data')
->body('Check the logs.')
->danger()
->sendToDatabase($recipient);
return;
}
Notification::make()
->title('Speedtest results deleted')
->body($count.' speedtest results were deleted from the database.')
->success()
->sendToDatabase($recipient);
}
}