]> git.localhorst.tv Git - alttp.git/commitdiff
track result changes
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Nov 2025 11:10:36 +0000 (12:10 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 29 Nov 2025 11:10:36 +0000 (12:10 +0100)
app/Http/Controllers/ResultController.php
database/migrations/2025_11_29_105122_result_change_tracking.php [new file with mode: 0644]

index 14f92de4492080581bb2af53801cfa0153ffc289..563fdd6cf0eb0d36bd6e3912233ba275355e3937 100644 (file)
@@ -30,13 +30,16 @@ class ResultController extends Controller
                        $this->authorize('create', Result::class);
                }
 
-               $result = Result::firstOrCreate([
+               $result = Result::firstOrNew([
                        'round_id' => $validatedData['round_id'],
                        'user_id' => $validatedData['user_id'],
                ]);
                if (!$round->locked && !$result->verified_at) {
                        if (isset($validatedData['forfeit'])) $result->forfeit = $validatedData['forfeit'];
                        if (isset($validatedData['time'])) $result->time = $validatedData['time'];
+                       if ($result->id && $result->isDirty(['forfeit', 'time'])) {
+                               ++$result->changed;
+                       }
                }
                $result->comment = !empty($validatedData['comment']) ? $validatedData['comment'] : null;
                if (!$result->verified_at) {
diff --git a/database/migrations/2025_11_29_105122_result_change_tracking.php b/database/migrations/2025_11_29_105122_result_change_tracking.php
new file mode 100644 (file)
index 0000000..444e934
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+       /**
+        * Run the migrations.
+        */
+       public function up(): void
+       {
+               Schema::table('results', function (Blueprint $table) {
+                       $table->unsignedInteger('changed')->default(0);
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        */
+       public function down(): void
+       {
+               Schema::table('results', function (Blueprint $table) {
+                       $table->dropColumn('changed');
+               });
+       }
+};