From ee796dce9179b9d6f80cccc651672007c46da098 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 24 Jan 2026 17:04:13 -0500 Subject: [PATCH] fix: Handle missing updated_at column in comment updates Check if updated_at column exists before using it in UPDATE query. This allows comment editing to work before migration script is run. Co-Authored-By: Claude Opus 4.5 --- models/CommentModel.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/models/CommentModel.php b/models/CommentModel.php index 03eabd1..4dcc4a0 100644 --- a/models/CommentModel.php +++ b/models/CommentModel.php @@ -147,7 +147,19 @@ class CommentModel { return ['success' => false, 'error' => 'You do not have permission to edit this comment']; } - $sql = "UPDATE ticket_comments SET comment_text = ?, markdown_enabled = ?, updated_at = NOW() WHERE comment_id = ?"; + // Check if updated_at column exists + $hasUpdatedAt = false; + $colCheck = $this->conn->query("SHOW COLUMNS FROM ticket_comments LIKE 'updated_at'"); + if ($colCheck && $colCheck->num_rows > 0) { + $hasUpdatedAt = true; + } + + if ($hasUpdatedAt) { + $sql = "UPDATE ticket_comments SET comment_text = ?, markdown_enabled = ?, updated_at = NOW() WHERE comment_id = ?"; + } else { + $sql = "UPDATE ticket_comments SET comment_text = ?, markdown_enabled = ? WHERE comment_id = ?"; + } + $stmt = $this->conn->prepare($sql); $markdownInt = $markdownEnabled ? 1 : 0; $stmt->bind_param("sii", $commentText, $markdownInt, $commentId); @@ -158,7 +170,7 @@ class CommentModel { 'comment_id' => $commentId, 'comment_text' => $commentText, 'markdown_enabled' => $markdownInt, - 'updated_at' => date('M d, Y H:i') + 'updated_at' => $hasUpdatedAt ? date('M d, Y H:i') : null ]; } else { return ['success' => false, 'error' => $this->conn->error];