student_id-FK-Migration Stufe 1+2: Name-Joins -> student_sessions.student_id
- student_sessions: neue Spalte student_id (+Index), backfilled aus (class_id,display_name) - Session::createStudent setzt student_id (per Lookup, falls nicht uebergeben) - alle Joins students<->student_sessions von display_name auf student_id umgestellt: Benchmark.php, live.php (5x), results.php (4x + runs), modules.php, profile.php, progress.php (answers+runs) - verlustfrei verifiziert (alt-Join == neu-Join, class 99/102) Robuster gegen Umbenennung/Doppelnamen, indexierbare Joins. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+13
-4
@@ -20,8 +20,10 @@ class Session {
|
||||
return $_COOKIE[self::COOKIE_NAME] ?? null;
|
||||
}
|
||||
|
||||
/** Neue Schueler-Session erstellen */
|
||||
public static function createStudent(int $classId, string $displayName = ''): string {
|
||||
/** Neue Schueler-Session erstellen. student_id wird direkt gesetzt (per FK
|
||||
* statt fragilem display_name-Join) — falls nicht übergeben, aus
|
||||
* (class_id, display_name) aufgelöst. */
|
||||
public static function createStudent(int $classId, string $displayName = '', ?int $studentId = null): string {
|
||||
$uuid = sprintf('%s-%s-%s-%s-%s',
|
||||
bin2hex(random_bytes(4)),
|
||||
bin2hex(random_bytes(2)),
|
||||
@@ -31,9 +33,16 @@ class Session {
|
||||
);
|
||||
|
||||
$db = Database::get();
|
||||
if ($studentId === null && $displayName !== '') {
|
||||
$row = $db->fetchOne(
|
||||
'SELECT id FROM students WHERE class_id = ? AND display_name = ? AND deleted_at IS NULL',
|
||||
[$classId, $displayName]
|
||||
);
|
||||
if ($row) $studentId = (int)$row['id'];
|
||||
}
|
||||
$db->execute(
|
||||
'INSERT INTO student_sessions (id, class_id, display_name) VALUES (?, ?, ?)',
|
||||
[$uuid, $classId, $displayName]
|
||||
'INSERT INTO student_sessions (id, class_id, display_name, student_id) VALUES (?, ?, ?, ?)',
|
||||
[$uuid, $classId, $displayName, $studentId]
|
||||
);
|
||||
|
||||
setcookie(self::COOKIE_NAME, $uuid, [
|
||||
|
||||
Reference in New Issue
Block a user