Robo-Admin: Team-Zuordnung beim Bearbeiten von Spielen mitschreiben
Game::update() löst team1_id/team2_id über den Alias-Abgleich neu auf, der Ergebnis-Fetcher zieht fehlende Zuordnungen zur Laufzeit nach. Bisher hat die Rundenpflege im Admin nur die Namen gespeichert; ohne Zuordnung hat der Fetcher die Spiele stumm übersprungen (seit Runde 986 keine Erkennung/Ergebnisse).
This commit is contained in:
parent
6766c50aa7
commit
7ad388bc29
3 changed files with 60 additions and 8 deletions
|
|
@ -10,7 +10,7 @@ Diese Datei ersetzt die Erkundung. Erst hier nachschlagen, dann gezielt mit
|
|||
Abschnitt zu lesen. `docs/legacy/` ist absichtlich ausgeblendet (siehe
|
||||
`.ignore`); dort liegt der alte Laravel-Stand.
|
||||
|
||||
Umfang: 11697 Zeilen in 66 Dateien.
|
||||
Umfang: 11749 Zeilen in 66 Dateien.
|
||||
|
||||
## Einstiegspunkte
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ ohne View.
|
|||
| `tippspiel/src/Core/ErrorLog.php` | 52 | PHP-Fehlerdatei außerhalb des Web-Roots, Rotation bei 5 MB | `path()`, `rotateIfNeeded($maxBytes)` |
|
||||
| `tippspiel/src/Core/Iban.php` | 51 | IBAN normalisieren und prüfen | `normalize($value)`, `isValid($value)` |
|
||||
| `tippspiel/src/Core/Mailer.php` | 167 | Minimaler SMTP-Client ohne externe Abhängigkeiten | `send($recipients, $subject, $html, $replyTo, …)` |
|
||||
| `tippspiel/src/Core/ResultFetcher.php` | 535 | Ergebnisse von openligadb und API-Football holen und eintragen | `openligadb($apply, $check)`, `apifootball($apply, $check)` |
|
||||
| `tippspiel/src/Core/ResultFetcher.php` | 580 | Ergebnisse von openligadb und API-Football holen und eintragen | `openligadb($apply, $check)`, `apifootball($apply, $check)` |
|
||||
| `tippspiel/src/Core/WebPush.php` | 446 | Web-Push (VAPID, RFC 8291) ohne externe Abhängigkeiten | `isConfigured()`, `publicKey()`, `subject()`, `isValidEndpoint($endpoint)`, `isValidKeyMaterial($p256dh, $auth)`, `send($subscription, $payload)`, `encrypt($payload, $p256dh, $auth, $salt, …)` |
|
||||
|
||||
## Models (`App\Models`)
|
||||
|
|
@ -79,7 +79,7 @@ ohne View.
|
|||
| Datei | Zeilen | Zweck | öffentliche Methoden |
|
||||
|---------------------------------------------|--------|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `tippspiel/src/Models/FetcherLog.php` | 65 | Protokoll des Ergebnis-Fetchers | `create($action, $message)`, `getRange($fromDate, $toDate)`, `deleteOld()` |
|
||||
| `tippspiel/src/Models/Game.php` | 93 | Spiele lesen, Sperre 1 Minute vor Anpfiff, Ergebnisse | `isLocked($kickoffTime)`, `getResultString($score1, $score2, $kickoffTime)`, `getGamesByRound($roundId)`, `getById($id)`, `update($id, $data)` |
|
||||
| `tippspiel/src/Models/Game.php` | 100 | Spiele lesen, Sperre 1 Minute vor Anpfiff, Ergebnisse | `isLocked($kickoffTime)`, `getResultString($score1, $score2, $kickoffTime)`, `getGamesByRound($roundId)`, `getById($id)`, `update($id, $data)` |
|
||||
| `tippspiel/src/Models/Payment.php` | 44 | Zahlungen je Saison (user_id -> paid_date) | `getPaymentsBySeason($seasonId)`, `setPaidStatus($userId, $seasonId, $hasPaid)` |
|
||||
| `tippspiel/src/Models/PushSubscription.php` | 195 | Push-Abos der Spieler | `isAvailable()`, `hasSubscription($userId)`, `save($userId, $endpoint, $p256dh, $auth)`, `findForUserAndEndpoint($userId, $endpoint)`, `deleteForUser($userId)`, `deleteByEndpoint($endpoint)`, `getForUsers($userIds)`, `sendReminder($userIds, $payload)` |
|
||||
| `tippspiel/src/Models/Question.php` | 164 | Spielerfragen an die Admins inklusive Antworten | `create($userId, $question)`, `findByUser($userId)`, `findAllForAdmin()`, `findById($id)`, `answer($id, $answer, $adminId)`, `hasNewAnswer($userId)`, `hasOpenQuestion()`, `markAnswersSeen($userId)`, … |
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ class ResultFetcher {
|
|||
$stmt = $db->prepare(
|
||||
"SELECT g.id, g.team1, g.team2, g.kickoff, g.score1, g.score2, g.fetcher_matched,
|
||||
r.name AS round_name, s.name AS season_name,
|
||||
t1.key AS k1, t2.key AS k2, t1.type AS t1t, t2.type AS t2t
|
||||
t1.key AS k1, t2.key AS k2, t1.type AS t1t, t2.type AS t2t,
|
||||
g.team1_id, g.team2_id
|
||||
FROM games g
|
||||
JOIN rounds r ON r.id = g.round_id
|
||||
JOIN seasons s ON s.id = r.season_id
|
||||
|
|
@ -64,7 +65,7 @@ class ResultFetcher {
|
|||
ORDER BY g.kickoff"
|
||||
);
|
||||
$stmt->execute([$from, $to]);
|
||||
$games = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$games = self::syncTeams($stmt->fetchAll(\PDO::FETCH_ASSOC));
|
||||
|
||||
$targets = [];
|
||||
foreach ($games as $g) {
|
||||
|
|
@ -305,7 +306,8 @@ class ResultFetcher {
|
|||
$stmt = $db->prepare(
|
||||
"SELECT g.id, g.team1, g.team2, g.kickoff, g.score1, g.score2, g.fetcher_matched,
|
||||
r.name AS round_name, s.name AS season_name,
|
||||
t1.key AS k1, t2.key AS k2, t1.type AS t1t, t2.type AS t2t
|
||||
t1.key AS k1, t2.key AS k2, t1.type AS t1t, t2.type AS t2t,
|
||||
g.team1_id, g.team2_id
|
||||
FROM games g
|
||||
JOIN rounds r ON r.id = g.round_id
|
||||
JOIN seasons s ON s.id = r.season_id
|
||||
|
|
@ -315,7 +317,7 @@ class ResultFetcher {
|
|||
ORDER BY g.kickoff"
|
||||
);
|
||||
$stmt->execute([$from, $to]);
|
||||
$games = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$games = self::syncTeams($stmt->fetchAll(\PDO::FETCH_ASSOC));
|
||||
|
||||
$targets = [];
|
||||
foreach ($games as $g) {
|
||||
|
|
@ -473,6 +475,49 @@ class ResultFetcher {
|
|||
return implode("\n", $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ergänzt fehlende Team-Zuordnungen (games.team1_id/team2_id) über den
|
||||
* Namensabgleich und schreibt sie zurück. Nötig, weil die Rundenpflege im
|
||||
* Admin nur die Namen schreibt (Game::update) – ohne Zuordnung würde der
|
||||
* Fetcher das Spiel stumm überspringen (kein Roboter-Symbol, kein Ergebnis).
|
||||
*
|
||||
* @param array $games Zeilen der Fetcher-Abfrage
|
||||
* @return array Zeilen mit vollständigem k1/k2/t1t/t2t
|
||||
*/
|
||||
private static function syncTeams(array $games): array {
|
||||
$db = Database::getConnection();
|
||||
$update = $db->prepare("UPDATE games SET team1_id = ?, team2_id = ? WHERE id = ?");
|
||||
|
||||
foreach ($games as $i => $g) {
|
||||
$id1 = isset($g['team1_id']) && $g['team1_id'] !== null ? (int)$g['team1_id'] : null;
|
||||
$id2 = isset($g['team2_id']) && $g['team2_id'] !== null ? (int)$g['team2_id'] : null;
|
||||
if ($id1 !== null && $id2 !== null) {
|
||||
continue;
|
||||
}
|
||||
if ($id1 === null) {
|
||||
$team = Team::resolve((string)$g['team1']);
|
||||
if ($team) {
|
||||
$id1 = (int)$team['id'];
|
||||
$games[$i]['k1'] = $team['key'];
|
||||
$games[$i]['t1t'] = $team['type'];
|
||||
}
|
||||
}
|
||||
if ($id2 === null) {
|
||||
$team = Team::resolve((string)$g['team2']);
|
||||
if ($team) {
|
||||
$id2 = (int)$team['id'];
|
||||
$games[$i]['k2'] = $team['key'];
|
||||
$games[$i]['t2t'] = $team['type'];
|
||||
}
|
||||
}
|
||||
if ($id1 !== null || $id2 !== null) {
|
||||
$update->execute([$id1, $id2, $g['id']]);
|
||||
}
|
||||
}
|
||||
|
||||
return $games;
|
||||
}
|
||||
|
||||
private static function openligaGet(string $path): ?array {
|
||||
$json = @file_get_contents(self::OPENLIGADB . $path);
|
||||
if ($json === false) {
|
||||
|
|
|
|||
|
|
@ -72,18 +72,25 @@ class Game {
|
|||
* Aktualisiert Paarung, Anstoß und Ergebnis eines Spiels (Legacy GamesController::store).
|
||||
* Ein fehlendes Ergebnis wird als -1:-1 gespeichert.
|
||||
*
|
||||
* Die Team-IDs werden dabei neu aufgelöst: Der Ergebnis-Fetcher erkennt nur
|
||||
* Spiele mit zugeordneten Mannschaften, sonst überspringt er sie stumm.
|
||||
*
|
||||
* @param int $id
|
||||
* @param array $data ['team1', 'team2', 'kickoff' (Y-m-d H:i:s), 'score1', 'score2']
|
||||
* @return bool
|
||||
*/
|
||||
public static function update($id, array $data) {
|
||||
$db = Database::getConnection();
|
||||
$team1 = Team::resolve($data['team1']);
|
||||
$team2 = Team::resolve($data['team2']);
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE games SET team1 = ?, team2 = ?, kickoff = ?, score1 = ?, score2 = ?, updated_at = NOW() WHERE id = ?"
|
||||
"UPDATE games SET team1 = ?, team2 = ?, team1_id = ?, team2_id = ?, kickoff = ?, score1 = ?, score2 = ?, updated_at = NOW() WHERE id = ?"
|
||||
);
|
||||
return $stmt->execute([
|
||||
$data['team1'],
|
||||
$data['team2'],
|
||||
$team1 ? (int)$team1['id'] : null,
|
||||
$team2 ? (int)$team2['id'] : null,
|
||||
$data['kickoff'],
|
||||
(int)$data['score1'],
|
||||
(int)$data['score2'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue