Update Saqel Platform: 2026-09-02 07:52:23

This commit is contained in:
Hamza-Ayed
2026-09-02 07:52:24 +03:00
parent 739f934a26
commit 36939a50c1
8 changed files with 38 additions and 22 deletions
@@ -9,6 +9,10 @@ use App\Services\CurriculumService;
echo "=== SAQEL ENTERPRISE CURRICULUM DATABASE SYNC ===\n";
// Keep an existing production database compatible with the canonical
// curriculum-key linkage before querying or inserting synchronized lessons.
\App\Services\VideoService::ensureSchema();
$manifestFile = __DIR__ . '/../storage/curriculum/manifest.json';
if (!file_exists($manifestFile)) {
die("Error: manifest.json not found at $manifestFile\n");
@@ -99,24 +103,24 @@ foreach ($manifest as $gradeKey => $grade) {
$cheatSheet = $les['cheat_sheet'] ?? null;
$socraticQuiz = isset($les['socratic_quiz']) ? json_encode($les['socratic_quiz'], JSON_UNESCAPED_UNICODE) : null;
// Match existing lesson by course_id and title or file path
// The manifest file path is the canonical, globally unique lesson key.
$dbLesson = Database::selectOne(
"SELECT id FROM lessons WHERE course_id = ? AND title = ? LIMIT 1",
[$courseId, $lessonTitle]
"SELECT id FROM lessons WHERE curriculum_key = ? OR (course_id = ? AND title = ?) LIMIT 1",
[$filePath, $courseId, $lessonTitle]
);
if (!$dbLesson) {
$lesId = Database::insert(
"INSERT INTO lessons (course_id, title, sequence_order, ai_video_url, markdown_content, cheat_sheet_markdown, socratic_quiz_json, is_free_preview)
VALUES (?, ?, ?, ?, ?, ?, ?, 1)",
[$courseId, $lessonTitle, $seqOrder, $aiVideoUrl, $mdContent, $cheatSheet, $socraticQuiz]
"INSERT INTO lessons (course_id, title, curriculum_key, sequence_order, ai_video_url, markdown_content, cheat_sheet_markdown, socratic_quiz_json, is_free_preview)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1)",
[$courseId, $lessonTitle, $filePath, $seqOrder, $aiVideoUrl, $mdContent, $cheatSheet, $socraticQuiz]
);
echo " 📄 [NEW] Lesson inserted: {$lessonTitle} (ID: {$lesId})\n";
} else {
$lesId = (int)$dbLesson['id'];
Database::query(
"UPDATE lessons SET sequence_order = ?, markdown_content = ?, ai_video_url = COALESCE(?, ai_video_url), cheat_sheet_markdown = COALESCE(?, cheat_sheet_markdown), socratic_quiz_json = COALESCE(?, socratic_quiz_json) WHERE id = ?",
[$seqOrder, $mdContent, $aiVideoUrl, $cheatSheet, $socraticQuiz, $lesId]
"UPDATE lessons SET curriculum_key = ?, sequence_order = ?, markdown_content = ?, ai_video_url = COALESCE(?, ai_video_url), cheat_sheet_markdown = COALESCE(?, cheat_sheet_markdown), socratic_quiz_json = COALESCE(?, socratic_quiz_json) WHERE id = ?",
[$filePath, $seqOrder, $mdContent, $aiVideoUrl, $cheatSheet, $socraticQuiz, $lesId]
);
echo " 🔄 [UPDATED] Lesson: {$lessonTitle} (ID: {$lesId})\n";
}