parent
a21f3f2bb4
commit
e7176b6371
17 changed files with 189 additions and 25 deletions
|
|
@ -65,14 +65,27 @@ final class Migrations
|
|||
}
|
||||
}
|
||||
|
||||
$relaxesForeignKeys = $name === '093_room_rules_and_care_periods.sql';
|
||||
if ($relaxesForeignKeys) {
|
||||
$db->exec('PRAGMA foreign_keys = OFF');
|
||||
}
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$db->exec($sql);
|
||||
$ins = $db->prepare("INSERT INTO _migrations(name, applied_at) VALUES(:n, datetime('now'))");
|
||||
$ins->execute([':n' => $name]);
|
||||
if ($relaxesForeignKeys && $db->query('PRAGMA foreign_key_check')->fetchColumn() !== false) {
|
||||
throw new RuntimeException('Foreign key check failed after room migration');
|
||||
}
|
||||
$db->commit();
|
||||
if ($relaxesForeignKeys) {
|
||||
$db->exec('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$db->rollBack();
|
||||
if ($relaxesForeignKeys) {
|
||||
$db->exec('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
throw new RuntimeException('Migration ' . $name . ' : ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
final class ShelterRoomService
|
||||
{
|
||||
public const PERIODS = ['morning', 'noon', 'afternoon', 'evening'];
|
||||
|
||||
public static function all(bool $activeOnly = false): array
|
||||
{
|
||||
$sql =
|
||||
|
|
@ -56,4 +58,28 @@ final class ShelterRoomService
|
|||
$value = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value) ?: $value;
|
||||
return trim(preg_replace('/[^a-z0-9]+/', '-', $value) ?? '', '-');
|
||||
}
|
||||
|
||||
public static function periods(array $room): array
|
||||
{
|
||||
$periods = array_values(array_intersect(
|
||||
self::PERIODS,
|
||||
explode(',', (string) ($room['care_periods'] ?? 'morning,evening')),
|
||||
));
|
||||
return $periods ?: ['morning', 'evening'];
|
||||
}
|
||||
|
||||
public static function accepts(array $room, array $animal): bool
|
||||
{
|
||||
$species = trim((string) ($room['allowed_species'] ?? ''));
|
||||
$sex = trim((string) ($room['allowed_sex'] ?? ''));
|
||||
$fiv = (string) ($room['required_fiv'] ?? 'any');
|
||||
if ($species !== '' && SpeciesService::normalize((string) ($animal['species'] ?? '')) !== $species) {
|
||||
return false;
|
||||
}
|
||||
if ($sex !== '' && (string) ($animal['sex'] ?? '') !== $sex) {
|
||||
return false;
|
||||
}
|
||||
$positive = (int) ($animal['fiv'] ?? 0) === 1 || (string) ($animal['fiv_status'] ?? '') === 'positive';
|
||||
return $fiv === 'any' || ($fiv === 'positive' ? $positive : !$positive);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue