83 lines
2.9 KiB
PHP
83 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
final class SchemaModel extends BaseModel
|
|
{
|
|
public function assertCurrent(): void
|
|
{
|
|
$requiredTables = [
|
|
'agent',
|
|
'structure',
|
|
'agent_structure',
|
|
'motif_planning',
|
|
'semaine',
|
|
'planning',
|
|
'creneau_horaire',
|
|
'quota_agent_annuel',
|
|
'modele_semaine_agent',
|
|
'modele_semaine_creneau',
|
|
'structure_couverture_horaire',
|
|
'periode_vacance',
|
|
'poste_agent',
|
|
'pta_annuel',
|
|
'agent_structure_souhait',
|
|
'agent_contrainte',
|
|
'equipe_pta',
|
|
'equipe_pta_membre',
|
|
'structure_creneau_reference',
|
|
];
|
|
|
|
$placeholders = implode(',', array_fill(0, count($requiredTables), '?'));
|
|
$stmt = $this->pdo->prepare(
|
|
"SELECT TABLE_NAME
|
|
FROM information_schema.TABLES
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME IN ($placeholders)"
|
|
);
|
|
$stmt->execute($requiredTables);
|
|
$existing = $stmt->fetchAll(\PDO::FETCH_COLUMN);
|
|
$missingTables = array_values(array_diff($requiredTables, $existing));
|
|
|
|
if ($missingTables) {
|
|
throw new \RuntimeException(
|
|
'Base PTA incomplète : table(s) manquante(s) : '
|
|
. implode(', ', $missingTables)
|
|
. '. Exécutez database/install_complet.sql ou les migrations nécessaires.'
|
|
);
|
|
}
|
|
|
|
$requiredColumns = [
|
|
'creneau_horaire' => ['id_motif'],
|
|
'planning' => ['date_validation'],
|
|
'agent' => ['email', 'telephone', 'adresse', 'est_diplome', 'diplome_libelle', 'id_structure', 'id_poste', 'type_contrat', 'date_debut_contrat', 'date_fin_contrat', 'formation_repartition_annuelle', 'commentaire_pta'],
|
|
'structure' => ['type_affectation'],
|
|
];
|
|
|
|
foreach ($requiredColumns as $table => $columns) {
|
|
$columnPlaceholders = implode(',', array_fill(0, count($columns), '?'));
|
|
$params = array_merge([$table], $columns);
|
|
$columnStmt = $this->pdo->prepare(
|
|
"SELECT COLUMN_NAME
|
|
FROM information_schema.COLUMNS
|
|
WHERE TABLE_SCHEMA = DATABASE()
|
|
AND TABLE_NAME = ?
|
|
AND COLUMN_NAME IN ($columnPlaceholders)"
|
|
);
|
|
$columnStmt->execute($params);
|
|
$existingColumns = $columnStmt->fetchAll(\PDO::FETCH_COLUMN);
|
|
$missingColumns = array_values(array_diff($columns, $existingColumns));
|
|
|
|
if ($missingColumns) {
|
|
throw new \RuntimeException(sprintf(
|
|
'Base PTA incomplète : colonne(s) manquante(s) dans %s : %s.',
|
|
$table,
|
|
implode(', ', $missingColumns)
|
|
));
|
|
}
|
|
}
|
|
}
|
|
}
|