]> git.localhorst.tv Git - alttp.git/commitdiff
periodically retrofit seed downloads
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 28 Nov 2025 19:46:58 +0000 (20:46 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 28 Nov 2025 19:46:58 +0000 (20:46 +0100)
app/Console/Commands/RoundSeedCleanup.php [new file with mode: 0644]
routes/console.php

diff --git a/app/Console/Commands/RoundSeedCleanup.php b/app/Console/Commands/RoundSeedCleanup.php
new file mode 100644 (file)
index 0000000..5d5ba27
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Events\ResultChanged;
+use App\Models\Round;
+use Illuminate\Console\Command;
+
+class RoundSeedCleanup extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'round:seed-cleanup';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Retrofit seeds to results where available';
+
+    /**
+     * Execute the console command.
+     */
+    public function handle()
+    {
+               $rounds = Round::query()->where('locked', '=', '0')->get();
+               foreach ($rounds as $round) {
+                       $missing = $round->results()->whereNull('got_seed_at')->get();
+                       foreach ($missing as $result) {
+                               $entry = $round->protocols()
+                                       ->where('user_id', '=', $result->user_id)
+                                       ->where('type', '=', 'round.getseed')
+                                       ->oldest()
+                                       ->first();
+                               if ($entry) {
+                                       $result->got_seed_at = $entry->created_at;
+                                       $result->save();
+                                       ResultChanged::dispatch($result);
+                               }
+                       }
+               }
+               return 0;
+    }
+}
index d2ce7c0066c77d24595fa0c0ba216e83e6427301..9aa4c99c04157c7a47d969794ef0c102fcf0e155 100644 (file)
@@ -46,3 +46,4 @@ Schedule::command('discord:episode-subscriptions')->everyMinute();
 Schedule::command('chat:evaluate 100')->everyMinute()->runInBackground();
 
 Schedule::command('guessing:clean')->everyFifteenMinutes();
+Schedule::command('round:seed-cleanup')->everyFifteenMinutes();