From d21691a548870b3ebd0c865a869dd7e022cc1bc0 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 11 Apr 2026 14:09:34 -0400 Subject: [PATCH] Fix deleteTicket crash when ticket_custom_fields table doesn't exist PHP 8.2 raises mysqli_sql_exception on prepare() for non-existent tables rather than returning false. Wrap each child-table delete in try/catch and silently skip tables that don't exist in all deployments, re-throwing for unexpected errors. Co-Authored-By: Claude Sonnet 4.6 --- models/TicketModel.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/models/TicketModel.php b/models/TicketModel.php index d2a418a..00f9b75 100644 --- a/models/TicketModel.php +++ b/models/TicketModel.php @@ -747,16 +747,23 @@ class TicketModel { ]; foreach ($children as $sql) { - $stmt = $this->conn->prepare($sql); - if (!$stmt) continue; - // ticket_dependencies uses two placeholders - if (strpos($sql, 'depends_on_id') !== false) { - $stmt->bind_param('ss', $ticketId, $ticketId); - } else { - $stmt->bind_param('s', $ticketId); + try { + $stmt = $this->conn->prepare($sql); + if (!$stmt) continue; + // ticket_dependencies uses two placeholders + if (strpos($sql, 'depends_on_id') !== false) { + $stmt->bind_param('ss', $ticketId, $ticketId); + } else { + $stmt->bind_param('s', $ticketId); + } + $stmt->execute(); + $stmt->close(); + } catch (mysqli_sql_exception $e) { + // Skip optional tables that may not exist in all deployments + if (strpos($e->getMessage(), "doesn't exist") === false) { + throw $e; + } } - $stmt->execute(); - $stmt->close(); } $stmt = $this->conn->prepare("DELETE FROM tickets WHERE ticket_id = ?");