test data import fix for scoring
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
2026-06-08 19:44:58 +02:00
parent 3211d35b43
commit d16bd1b3c4
5 changed files with 85 additions and 22 deletions

View File

@ -16,6 +16,7 @@ const QDB_DEV_GLASS_POINTS = [
require_once __DIR__ . '/app_answers.php';
require_once __DIR__ . '/submissions.php';
require_once __DIR__ . '/scoring.php';
/**
* @return array{imported: array, skipped: array, errors: string[]}
@ -36,6 +37,7 @@ function qdb_import_dev_fixture(PDO $pdo, array $fixture): array
'completions' => 0,
'submissions' => 0,
'answers' => 0,
'scoringRecomputed' => 0,
];
$skipped = [
'admins' => 0,
@ -48,6 +50,7 @@ function qdb_import_dev_fixture(PDO $pdo, array $fixture): array
$coachIdByUsername = [];
$supervisorIdByUsername = [];
$affectedClients = [];
$hash = password_hash($password, PASSWORD_DEFAULT);
$now = time();
@ -218,9 +221,23 @@ function qdb_import_dev_fixture(PDO $pdo, array $fixture): array
}
$imported['completions']++;
$affectedClients[$clientCode] = true;
$variant++;
}
$upperPrefix = strtoupper(rtrim($prefix, '_'));
$devClientStmt = $pdo->prepare('SELECT clientCode FROM client WHERE clientCode LIKE :pfx');
$devClientStmt->execute([':pfx' => $upperPrefix . '%']);
foreach ($devClientStmt->fetchAll(PDO::FETCH_COLUMN) as $cc) {
$affectedClients[(string)$cc] = true;
}
if ($affectedClients !== []) {
$imported['scoringRecomputed'] = qdb_recompute_scores_for_clients(
$pdo,
array_keys($affectedClients)
);
}
$pdo->commit();
} catch (Throwable $e) {
if ($pdo->inTransaction()) {