From e3b333ed043e0ab9a3cd7572c283f3cc0c1d2b92 Mon Sep 17 00:00:00 2001
From: JediKev <kevin@enhancesoft.com>
Date: Thu, 19 Jul 2018 12:15:04 -0500
Subject: [PATCH] thread: getId On Non-Object

This addresses issue 4347 where opening a ticket without an initial message
for the User and replying to it as an agent, fatally errors. This is because
osTicket does not check if there is a last message before getting the ID
from it. So it tries to lookup the ID of a non-object therefore fatally
erroring out.
---
 include/class.thread.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index b1a0f1bf7..0b2df9263 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -2863,7 +2863,8 @@ implements TemplateVariable {
     function addResponse($vars, &$errors) {
         $vars['threadId'] = $this->getId();
         $vars['userId'] = 0;
-        $vars['pid'] = $this->getLastMessage()->getId();
+        if ($message = $this->getLastMessage())
+            $vars['pid'] = $message->getId();
 
         $vars['flags'] = 0;
         switch ($vars['reply-to']) {
-- 
GitLab