Files
speedtest-tracker/app/Console/Commands/Maintenance/FixResultStatuses.php
T
Alex Justesen ce21ae24db Laravel 11.x Shift (#1389)
Co-authored-by: Shift <shift@laravelshift.com>
2024-05-06 08:00:29 -04:00

69 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands\Maintenance;
use App\Enums\ResultStatus;
use Illuminate\Console\Command;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
class FixResultStatuses extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:fix-result-statuses';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Reviews the data payload of each result and corrects the status attribute.';
/**
* Execute the console command.
*/
public function handle(): void
{
$this->newLine();
$this->info('This will check each result and correct the status to "completed" or "failed" based on the data column.');
$this->info('📖 Read the docs: https://docs.speedtest-tracker.dev/other/commands');
if (! $this->confirm('Do you want to continue?')) {
return;
}
/**
* Update completed status
*/
DB::table('results')
->where(function (Builder $query) {
$query->where('service', '=', 'ookla')
->whereNull('data->level')
->whereNull('data->message');
})
->update([
'status' => ResultStatus::Completed,
]);
/**
* Update failed status.
*/
DB::table('results')
->where(function (Builder $query) {
$query->where('service', '=', 'ookla')
->where('data->level', '=', 'error')
->whereNotNull('data->message');
})
->update([
'status' => ResultStatus::Failed,
]);
$this->line('✅ finished!');
}
}