update policy and fix other issues
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Successful in 1m19s

This commit is contained in:
root
2026-08-23 18:19:08 -04:00
parent 103f970110
commit a6e0ce1432
13 changed files with 433 additions and 317 deletions
+59
View File
@@ -72,6 +72,34 @@ class StudentYearStatusService
]);
}
/**
* Mark students who existed in a source school year as returning in the target year.
*
* This is intentionally idempotent so school-year activation/closing and repair
* migrations can call it safely.
*/
public function markReturningStudentsForTargetYear(string $sourceSchoolYear, string $targetSchoolYear): int
{
$sourceSchoolYear = trim($sourceSchoolYear);
$targetSchoolYear = trim($targetSchoolYear);
if (
! preg_match('/^\d{4}-\d{4}$/', $sourceSchoolYear)
|| ! preg_match('/^\d{4}-\d{4}$/', $targetSchoolYear)
|| $sourceSchoolYear === $targetSchoolYear
|| ! $this->db->tableExists('student_year_status')
) {
return 0;
}
$studentIds = $this->returningStudentIds($sourceSchoolYear);
foreach ($studentIds as $studentId) {
$this->upsert($studentId, $targetSchoolYear, false);
}
return count($studentIds);
}
/**
* @param list<array<string, mixed>> $students
*/
@@ -144,6 +172,37 @@ class StudentYearStatusService
return $flags;
}
/**
* @return list<int>
*/
private function returningStudentIds(string $sourceSchoolYear): array
{
$ids = [];
foreach (['student_year_status', 'student_class', 'enrollments'] as $table) {
if (! $this->db->tableExists($table) || ! $this->db->fieldExists('school_year', $table)) {
continue;
}
$rows = $this->db->table($table)
->select('student_id')
->where('school_year', $sourceSchoolYear)
->where('student_id IS NOT NULL', null, false)
->groupBy('student_id')
->get()
->getResultArray();
foreach ($rows as $row) {
$studentId = (int) ($row['student_id'] ?? 0);
if ($studentId > 0) {
$ids[$studentId] = true;
}
}
}
return array_keys($ids);
}
public function activeSchoolYear(): ?string
{
if ($this->db->tableExists('school_years')) {