fix alerte
Deploy HouseHub / deploy (push) Successful in 2s

This commit is contained in:
2026-06-19 11:54:38 +02:00
parent aad528d15b
commit 5b4f4c68b2
3 changed files with 31 additions and 15 deletions
@@ -154,9 +154,12 @@ try {
$type = strtoupper(trim($_POST['leave_type'] ?? ''));
$allowance = (float)($_POST['allowance'] ?? 0);
$resetMonth = (int)($_POST['reset_month'] ?? 1);
$method = in_array($_POST['method'] ?? '', ['FIXED', 'ACCUMULATED']) ? $_POST['method'] : 'FIXED';
if ($personId <= 0 || empty($type)) throw new Exception("Données invalides.");
// Vérification des doublons
$check = $pdo->prepare("SELECT id FROM pf_person_leave_meta WHERE person_id = ? AND leave_type = ?");
$check->execute([$personId, $type]);
if ($check->rowCount() > 0) throw new Exception("Ce congé est déjà attribué à cette personne.");
@@ -164,8 +167,8 @@ try {
// On construit la date anniversaire avec le mois choisi par l'utilisateur
$anniversaryDate = "2000-" . str_pad((string)$resetMonth, 2, "0", STR_PAD_LEFT) . "-01";
$stmt = $pdo->prepare("INSERT INTO pf_person_leave_meta (person_id, leave_type, allowance, method, anniversary_date) VALUES (?, ?, ?, 'FIXED', ?)");
$stmt->execute([$personId, $type, $allowance, $anniversaryDate]);
$stmt = $pdo->prepare("INSERT INTO pf_person_leave_meta (person_id, leave_type, allowance, method, anniversary_date) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$personId, $type, $allowance, $method, $anniversaryDate]);
echo json_encode(['success' => true]);
exit;
@@ -20,9 +20,12 @@ try {
$inserted = [];
foreach ($eventsToSave as $event) {
// 🔥 LE CORRECTIF : On initialise à 0 (car NOT NULL en base)
$person_id = 0;
// 🔥 SÉCURITÉ : On ignore l'itération si les données vitales manquent (évite le crash SQL)
if (empty($event['date']) || empty($event['type'])) {
continue;
}
$person_id = 0;
if (!empty($event['person_id']) && is_numeric($event['person_id'])) {
$person_id = (int)$event['person_id'];
} elseif (!empty($event['person']) && is_numeric($event['person'])) {
@@ -55,7 +58,7 @@ try {
'inserted' => $inserted,
]);
} catch (Exception $e) {
} catch (\Throwable $e) { // 🔥 LE CORRECTIF PRINCIPAL : \Throwable attrape AUSSI les erreurs fatales PHP !
if (isset($pdo) && $pdo->inTransaction()) {
$pdo->rollBack();
}
@@ -63,7 +66,7 @@ try {
echo json_encode([
'success' => false,
'status' => 'error',
'message' => 'Erreur SQL : ' . $e->getMessage()
'message' => 'Erreur Serveur/SQL : ' . $e->getMessage()
]);
}
?>