Skip to content

Commit 703c865

Browse files
authored
[Bug] Added fix result statuses command (alexjustesen#1197)
1 parent 86f8b07 commit 703c865

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace App\Console\Commands\Maintenance;
4+
5+
use App\Enums\ResultStatus;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Database\Query\Builder;
8+
use Illuminate\Support\Facades\DB;
9+
10+
class FixResultStatuses extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'app:fix-result-statuses';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Reviews the data payload of each result and corrects the status attribute.';
25+
26+
/**
27+
* Execute the console command.
28+
*/
29+
public function handle()
30+
{
31+
$this->newLine();
32+
33+
$this->info('This will check each result and correct the status to "completed" or "failed" based on the data column.');
34+
$this->info('📖 Read the docs: https://docs.speedtest-tracker.dev/other/commands');
35+
36+
if (! $this->confirm('Do you want to continue?')) {
37+
return Command::FAILURE;
38+
}
39+
40+
/**
41+
* Update completed status
42+
*/
43+
DB::table('results')
44+
->where(function (Builder $query) {
45+
$query->where('service', '=', 'ookla')
46+
->whereNull('data->level')
47+
->whereNull('data->message');
48+
})
49+
->update([
50+
'status' => ResultStatus::Completed,
51+
]);
52+
53+
/**
54+
* Update failed status.
55+
*/
56+
DB::table('results')
57+
->where(function (Builder $query) {
58+
$query->where('service', '=', 'ookla')
59+
->where('data->level', '=', 'error')
60+
->whereNotNull('data->message');
61+
})
62+
->update([
63+
'status' => ResultStatus::Failed,
64+
]);
65+
66+
$this->line('✅ finished!');
67+
68+
return Command::SUCCESS;
69+
}
70+
}

0 commit comments

Comments
 (0)