Fix MySQL scope ENUM to unit_exam in AiQuestionBankGeneratorService and ExamController

This commit is contained in:
Hamza-Ayed
2026-09-03 16:44:37 +03:00
parent 8d7ffcf2eb
commit be4fe3dabf
2 changed files with 11 additions and 6 deletions
+8 -3
View File
@@ -414,6 +414,11 @@ class ExamController
if (!$colCheck) {
Database::query("ALTER TABLE exam_attempts ADD COLUMN completed_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP AFTER ai_diagnostic_report");
}
// Safely ensure scope ENUM covers unit_comprehensive if ever passed
try {
Database::query("ALTER TABLE exams MODIFY COLUMN scope ENUM('in_video_checkpoint', 'lesson_exam', 'unit_exam', 'unit_comprehensive', 'semester_final') NOT NULL DEFAULT 'in_video_checkpoint'");
} catch (\Throwable $ign) {}
} catch (\Throwable $e) {
error_log("ExamController ensureSchema notice: " . $e->getMessage());
}
@@ -424,18 +429,18 @@ class ExamController
self::ensureSchema();
$exam = Database::selectOne(
"SELECT id FROM exams WHERE (scope = 'unit_comprehensive' OR scope = 'unit_exam' OR id = 1) AND (title LIKE '%الوحدة الأولى%' OR id = 1) LIMIT 1"
"SELECT id FROM exams WHERE (scope = 'unit_exam' OR scope = 'unit_comprehensive' OR id = 1) AND (title LIKE '%الوحدة الأولى%' OR id = 1) LIMIT 1"
);
$examId = $exam ? (int)$exam['id'] : 0;
if (!$examId) {
$examId = (int)Database::insert(
"INSERT INTO exams (uuid, course_id, lesson_id, creator_type, scope, title, passing_percentage, total_points, duration_minutes, is_mandatory, is_published)
VALUES (UUID(), 1, 0, 'ai_adaptive', 'unit_comprehensive', 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', 70.00, 100, 45, 1, 1)"
VALUES (UUID(), 1, 0, 'ai_adaptive', 'unit_exam', 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', 70.00, 100, 45, 1, 1)"
);
} else {
Database::query(
"UPDATE exams SET title = 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', duration_minutes = 45, total_points = 100, passing_percentage = 70.00, is_published = 1 WHERE id = ?",
"UPDATE exams SET title = 'اختبار الفهم الشامل: الوحدة الأولى — أنظمة المعادلات', duration_minutes = 45, total_points = 100, passing_percentage = 70.00, scope = 'unit_exam', is_published = 1 WHERE id = ?",
[$examId]
);
}