diff --git a/app/Console/Commands/Maintenance/FixResultStatuses.php b/app/Console/Commands/Maintenance/FixResultStatuses.php new file mode 100644 index 000000000..6089bef3f --- /dev/null +++ b/app/Console/Commands/Maintenance/FixResultStatuses.php @@ -0,0 +1,70 @@ +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 Command::FAILURE; + } + + /** + * 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!'); + + return Command::SUCCESS; + } +}