fix tables to have school year, and remove school year from other tables.
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 5m48s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 1m33s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 5m48s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 1m33s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
+6
-43
@@ -61,7 +61,7 @@ class Staff extends BaseModel
|
||||
|
||||
public function scopeForSchoolYear(Builder $q, string $schoolYear): Builder
|
||||
{
|
||||
return $q->where('school_year', $schoolYear);
|
||||
return $q;
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
@@ -88,8 +88,7 @@ class Staff extends BaseModel
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert or update a staff row keyed by (user_id, school_year).
|
||||
* - If school_year missing: reuse latest existing school_year for that user if available.
|
||||
* Insert or update a staff row keyed by user_id.
|
||||
* - created_at is preserved on update (unless explicitly provided).
|
||||
* - updated_at can be provided by caller; otherwise we set it.
|
||||
*
|
||||
@@ -103,45 +102,10 @@ class Staff extends BaseModel
|
||||
|
||||
$userId = (int) $data['user_id'];
|
||||
|
||||
// Resolve school_year fallback like your legacy logic
|
||||
$schoolYear = $data['school_year'] ?? null;
|
||||
if ($schoolYear === null) {
|
||||
$existingAny = static::query()
|
||||
->where('user_id', $userId)
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
if ($existingAny && $existingAny->school_year) {
|
||||
$schoolYear = (string) $existingAny->school_year;
|
||||
$data['school_year'] = $schoolYear;
|
||||
}
|
||||
}
|
||||
|
||||
// Find existing by key
|
||||
$existing = null;
|
||||
if ($schoolYear !== null) {
|
||||
$existing = static::query()
|
||||
->where('user_id', $userId)
|
||||
->where('school_year', (string) $schoolYear)
|
||||
->first();
|
||||
} else {
|
||||
// If no school_year, treat (user_id) as key
|
||||
$existing = static::query()
|
||||
->where('user_id', $userId)
|
||||
->first();
|
||||
}
|
||||
|
||||
// The table enforces unique email addresses, so a user cannot safely
|
||||
// have multiple staff rows across different school years with the same
|
||||
// generated email. If an exact school-year row is missing but the user
|
||||
// already has any staff row, update that existing row instead of trying
|
||||
// to insert a duplicate-email record.
|
||||
if (! $existing) {
|
||||
$existing = static::query()
|
||||
->where('user_id', $userId)
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
}
|
||||
$existing = static::query()
|
||||
->where('user_id', $userId)
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
$now = now(); // use UTC if app.timezone=UTC (recommended)
|
||||
|
||||
@@ -201,7 +165,6 @@ class Staff extends BaseModel
|
||||
'role_name' => ['nullable', 'string', 'max:80'],
|
||||
'active_role' => ['nullable', 'string', 'max:80'], // includes 'inactive'
|
||||
'status' => ['nullable', 'string', 'max:40'],
|
||||
'school_year' => ['nullable', 'string', 'max:20'],
|
||||
'created_at' => ['nullable', 'date'],
|
||||
'updated_at' => ['nullable', 'date'],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user