51 lines
2.2 KiB
PHP
51 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Saqel Platform — Self-Healing Socratic Checkpoints Migration & Cleanup Script
|
|
* Scans all lessons in the database and cleans up any legacy Tawjihi Calculus
|
|
* checkpoints attached to Grade 10 lessons (e.g. Systems of Equations).
|
|
*/
|
|
|
|
require_once __DIR__ . '/../app/bootstrap.php';
|
|
|
|
use App\Core\Database;
|
|
use App\Services\AiVideoAnalyzerService;
|
|
|
|
echo "======================================================================\n";
|
|
echo "🧹 SAQEL CURRICULUM CHECKPOINT AUDIT & REPAIR ENGINE\n";
|
|
echo "======================================================================\n\n";
|
|
|
|
try {
|
|
// Find all lessons with mismatched calculus questions in non-calculus lessons
|
|
$mismatchedLessons = Database::select(
|
|
"SELECT DISTINCT l.id, l.title
|
|
FROM lessons l
|
|
JOIN exams e ON e.lesson_id = l.id
|
|
JOIN questions q ON q.exam_id = e.id
|
|
WHERE (q.question_text LIKE '%مشتق%' OR q.question_text LIKE '%f\'(x)%' OR q.question_text LIKE '%sin(3x)%')
|
|
AND l.title NOT LIKE '%اشتقاق%' AND l.title NOT LIKE '%تفاضل%'"
|
|
);
|
|
|
|
if (empty($mismatchedLessons)) {
|
|
echo "✅ No mismatched calculus checkpoints found. All lessons are curriculum-grounded!\n";
|
|
} else {
|
|
echo "⚠️ Found " . count($mismatchedLessons) . " lesson(s) with obsolete calculus checkpoints:\n";
|
|
foreach ($mismatchedLessons as $les) {
|
|
echo " • Repairing Lesson [ID: {$les['id']}]: '{$les['title']}'...\n";
|
|
|
|
// Delete corrupt exam checkpoints
|
|
$badExams = Database::select("SELECT id FROM exams WHERE lesson_id = ? AND scope = 'in_video_checkpoint'", [$les['id']]);
|
|
foreach ($badExams as $be) {
|
|
Database::query("DELETE FROM exams WHERE id = ?", [$be['id']]);
|
|
}
|
|
|
|
// Re-generate fresh, pristine, Grade 10 curriculum checkpoints
|
|
AiVideoAnalyzerService::processLessonAutonomously((int)$les['id']);
|
|
echo " ✓ Successfully regenerated authentic Grade 10 curriculum questions!\n";
|
|
}
|
|
}
|
|
|
|
echo "\n🎉 Curriculum audit & cleanup completed successfully!\n";
|
|
} catch (\Throwable $e) {
|
|
echo "❌ Error during cleanup: " . $e->getMessage() . "\n";
|
|
}
|