diff --git a/inbound.php b/inbound.php index 605747e..bbd4575 100644 --- a/inbound.php +++ b/inbound.php @@ -70,6 +70,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $id = $_POST['id'] ?? 0; if ($ref_no && $subject) { + $should_notify = false; try { db()->beginTransaction(); if ($action === 'add') { @@ -78,7 +79,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $mail_id = db()->lastInsertId(); if ($assigned_to) { - sendAssignmentNotification($assigned_to, $ref_no, $subject); + $should_notify = true; } $_SESSION['success'] = 'تمت إضافة البريد بنجاح'; @@ -93,7 +94,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt->execute([$ref_no, $date_registered, $due_date, $sender, $recipient, $subject, $description, $status_id, $assigned_to, $id]); if ($assigned_to && $assigned_to != $old_assigned_to) { - sendAssignmentNotification($assigned_to, $ref_no, $subject); + $should_notify = true; } $_SESSION['success'] = 'تم تحديث البيانات بنجاح'; @@ -117,9 +118,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } db()->commit(); + + // Notify after commit to avoid holding locks during email sending + if ($should_notify) { + sendAssignmentNotification($assigned_to, $ref_no, $subject); + } + redirect('inbound.php'); } catch (PDOException $e) { - db()->rollBack(); + if (db()->inTransaction()) db()->rollBack(); if ($e->getCode() == 23000) { $error = 'رقم القيد مستخدم مسبقاً'; } else { @@ -404,7 +411,7 @@ function getStatusBadgeInList($mail) {
- +
@@ -445,8 +452,27 @@ function getStatusBadgeInList($mail) {
+ + + + +