Fix nested array reference mutation in getTree with direct key indexing
This commit is contained in:
@@ -55,14 +55,18 @@ try {
|
||||
echo " Mapped " . count($byPath) . " paths in \$byPath lookup table.\n";
|
||||
|
||||
$matchCount = 0;
|
||||
foreach ($tree as &$grade) {
|
||||
foreach (($grade['subjects'] ?? []) as &$subject) {
|
||||
foreach (($subject['semesters'] ?? []) as &$semester) {
|
||||
foreach (($semester['units'] ?? []) as &$unit) {
|
||||
foreach (($unit['lessons'] ?? []) as &$lesson) {
|
||||
foreach ($tree as $gKey => $grade) {
|
||||
if (!isset($tree[$gKey]['subjects']) || !is_array($tree[$gKey]['subjects'])) continue;
|
||||
foreach ($tree[$gKey]['subjects'] as $sKey => $subject) {
|
||||
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'])) continue;
|
||||
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'] as $semKey => $semester) {
|
||||
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'])) continue;
|
||||
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'] as $uKey => $unit) {
|
||||
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'])) continue;
|
||||
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'] as $lKey => $lesson) {
|
||||
$path = (string)($lesson['file'] ?? '');
|
||||
if (isset($byPath[$path])) {
|
||||
$lesson = array_merge($lesson, $byPath[$path]);
|
||||
$tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'][$lKey] = array_merge($lesson, $byPath[$path]);
|
||||
$matchCount++;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +74,6 @@ try {
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($grade, $subject, $semester, $unit, $lesson);
|
||||
|
||||
echo " Enriched matches in manifest.json tree: {$matchCount}\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user