Commit 66dc5b71 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: rounds tab json_decode crash + players tab empty (UUID type mismatch)

1. pairings/results JSONB columns already decoded by Supabase — added
   is_array check before json_decode (same pattern as tiebreak fix).

2. Bot player_id was 'bot_xyz' string but column is UUID type — PostgREST
   silently rejected every insert. Now generates proper v4 UUIDs.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 3284fc48
...@@ -164,9 +164,16 @@ class BotSimulationService ...@@ -164,9 +164,16 @@ class BotSimulationService
$inserted = 0; $inserted = 0;
foreach ($players as $player) { foreach ($players as $player) {
$botUuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
random_int(0, 0xffff), random_int(0, 0xffff),
random_int(0, 0xffff),
random_int(0, 0x0fff) | 0x4000,
random_int(0, 0x3fff) | 0x8000,
random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff)
);
$db->insert('tournament_registrations', [ $db->insert('tournament_registrations', [
'tournament_id' => $tournamentId, 'tournament_id' => $tournamentId,
'player_id' => 'bot_' . uniqid(), 'player_id' => $botUuid,
'status' => 'registered', 'status' => 'registered',
'is_bot' => true, 'is_bot' => true,
'bot_metadata' => json_encode([ 'bot_metadata' => json_encode([
......
...@@ -311,8 +311,10 @@ $tabs['arbiter'] = 'أدوات الحكم'; ...@@ -311,8 +311,10 @@ $tabs['arbiter'] = 'أدوات الحكم';
<div class="round-pairings-container" id="roundPairings_<?= $round['id'] ?>"> <div class="round-pairings-container" id="roundPairings_<?= $round['id'] ?>">
<?php <?php
$pairingsJson = json_decode($round['pairings'] ?? '[]', true); $rawPairings = $round['pairings'] ?? '[]';
$results = json_decode($round['results'] ?? '[]', true); $pairingsJson = is_array($rawPairings) ? $rawPairings : (json_decode($rawPairings, true) ?? []);
$rawResults = $round['results'] ?? '[]';
$results = is_array($rawResults) ? $rawResults : (json_decode($rawResults, true) ?? []);
?> ?>
<?php if (!empty($results)): ?> <?php if (!empty($results)): ?>
<table class="data-table"> <table class="data-table">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment