Update Saqel Platform: 2026-09-08 18:55:21

This commit is contained in:
Hamza-Ayed
2026-09-08 18:55:21 +03:00
parent 9198a2f974
commit 590326baa0
6 changed files with 283 additions and 107 deletions
+17 -1
View File
@@ -92,7 +92,23 @@ class VideoController
$subject = Database::selectOne(
"SELECT id FROM subjects WHERE name = ? ORDER BY id LIMIT 1",
[$subjectName]
) ?: Database::selectOne("SELECT id FROM subjects ORDER BY id LIMIT 1");
);
if (!$subject && $subjectName !== '') {
// The curriculum tree is the source of truth. When its
// subject has not yet been seeded into SQL, create the
// minimal canonical subject record instead of attaching
// the teacher's lesson to an unrelated first subject.
$subjectCode = 'CURR-' . strtoupper(substr(hash('sha256', $subjectName), 0, 12));
try {
$subjectId = (int)Database::insert(
"INSERT INTO subjects (name, code, stream, is_active) VALUES (?, ?, 'common', 1)",
[$subjectName, $subjectCode]
);
$subject = ['id' => $subjectId];
} catch (\Throwable $e) {
$subject = Database::selectOne("SELECT id FROM subjects WHERE name = ? LIMIT 1", [$subjectName]);
}
}
if (!$subject) {
$response->status(409)->json(['status' => 'error', 'message' => 'لا يوجد مبحث معرف لربط الفيديو به']);
return;