Files
saqel/backend/scripts/link_legacy_math_videos.php
T

75 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* Read-only audit for historic Grade 10 Math video records.
*
* This replaces the retired linker, which hard-coded a Bunny hostname and
* marked legacy records published without version-bound video review evidence.
* New media must go through TeacherSubmissionService and the full review flow.
*
* Usage: php backend/scripts/link_legacy_math_videos.php
*/
require_once dirname(__DIR__) . '/app/bootstrap.php';
use App\Core\Database;
if (in_array('--apply', $argv, true)) {
fwrite(STDERR, "This legacy linker is retired and read-only. Use the teacher upload and review workflow.\n");
exit(2);
}
echo "=== Grade 10 Math legacy video audit (read-only) ===\n";
$lessons = Database::select(
"SELECT id, uuid, lesson_key, unit_key, title, source_manifest_path, curriculum_version
FROM curriculum_lessons
WHERE grade_key='grade_10' AND subject_key='math_10' AND unit_key='unit_01'
ORDER BY lesson_key, id"
);
foreach ($lessons as $curriculumLesson) {
$path = (string)$curriculumLesson['source_manifest_path'];
$pathWithoutExtension = preg_replace('/\.md$/i', '', $path);
$records = Database::select(
"SELECT l.id, l.title, l.curriculum_key, l.storage_type, l.duration_seconds,
l.encoding_status, l.hls_url, l.r2_url,
vv.uuid AS version_uuid, vv.status AS version_status,
ts.status AS submission_status, j.status AS review_status
FROM lessons l
LEFT JOIN video_versions vv ON vv.source_lesson_id=l.id
LEFT JOIN teacher_submissions ts ON ts.id=vv.teacher_submission_id
LEFT JOIN video_review_jobs j ON j.video_version_id=vv.id
WHERE l.curriculum_key IN (?, ?)
ORDER BY l.id, vv.id",
[$path, $pathWithoutExtension]
);
echo "\n{$path} [{$curriculumLesson['curriculum_version']}]\n";
if ($records === []) {
echo " no matching video records\n";
continue;
}
foreach ($records as $record) {
$url = (string)($record['hls_url'] ?: $record['r2_url'] ?: '');
$host = $url !== '' ? (string)(parse_url($url, PHP_URL_HOST) ?: 'relative') : 'none';
$storage = str_ends_with($host, '.r2.dev') ? 'cloudflare_r2' : $record['storage_type'];
echo sprintf(
" lesson=%d storage=%s duration=%ss encoding=%s submission=%s version=%s review=%s host=%s\n",
(int)$record['id'],
$storage,
(int)$record['duration_seconds'],
(string)$record['encoding_status'],
(string)($record['submission_status'] ?? 'none'),
(string)($record['version_status'] ?? 'none'),
(string)($record['review_status'] ?? 'missing'),
$host
);
}
}
echo "\nNo records were changed.\n";