]> git.localhorst.tv Git - alttp.git/commitdiff
result changes recalculation
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Nov 2025 11:53:07 +0000 (12:53 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Nov 2025 11:53:07 +0000 (12:53 +0100)
app/Console/Commands/RecalculateResultChanges.php [new file with mode: 0644]

diff --git a/app/Console/Commands/RecalculateResultChanges.php b/app/Console/Commands/RecalculateResultChanges.php
new file mode 100644 (file)
index 0000000..71061a5
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\Models\Result;
+use Illuminate\Console\Command;
+
+class RecalculateResultChanges extends Command
+{
+       /**
+        * The name and signature of the console command.
+        *
+        * @var string
+        */
+       protected $signature = 'result:recalc-changes';
+
+       /**
+        * The console command description.
+        *
+        * @var string
+        */
+       protected $description = 'Command description';
+
+       /**
+        * Execute the console command.
+        */
+       public function handle()
+       {
+               $results = Result::all();
+               foreach ($results as $result) {
+                       $reports = $result->round->protocols()
+                               ->where('type', '=', 'result.report')
+                               ->where('user_id', '=', $result->user_id)
+                               ->count();
+                       if ($reports > 1) {
+                               $result->changed = $reports - 1;
+                               $result->save();
+                       }
+               }
+       }
+}