From a9d68c545ee08b4909987805246f23c61dc2c66e Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 28 May 2015 14:34:45 -0500
Subject: [PATCH] oops: Fix crash change ticket owner

And also fix mishap events changing the ticket status
---
 include/class.thread.php |  2 ++
 include/class.ticket.php | 18 ++++--------------
 scp/tickets.php          |  2 --
 tickets.php              |  1 -
 4 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/include/class.thread.php b/include/class.thread.php
index eb02999f4..7572ffdd5 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -1522,6 +1522,8 @@ class ThreadEvent extends VerySimpleModel {
             'overdue'   => 'time',
             'transferred' => 'share-alt',
             'edited'    => 'pencil',
+            'closed'    => 'thumbs-up-alt',
+            'reopened'  => 'rotate-right',
         );
         return @$icons[$this->state] ?: 'chevron-sign-right';
     }
diff --git a/include/class.ticket.php b/include/class.ticket.php
index a9b2b0078..ff6c549e4 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1028,8 +1028,6 @@ implements RestrictedAccess, Threadable {
         if ($this->getStatusId() == $status->getId())
             return true;
 
-        $this->status = $status;
-
         //TODO: move this up.
         $ecb = null;
         switch($status->getState()) {
@@ -1069,6 +1067,7 @@ implements RestrictedAccess, Threadable {
 
         }
 
+        $this->status = $status;
         if (!$this->save())
             return false;
 
@@ -1076,17 +1075,11 @@ implements RestrictedAccess, Threadable {
         // ticket, the ticket is opened and thereafter the status is set to
         // the requested status).
         if ($current_status = $this->getStatus()) {
-            $note = sprintf(__('Status changed from %1$s to %2$s by %3$s'),
-                    $this->getStatus(),
-                    $status,
-                    $thisstaff ?: 'SYSTEM');
-
             $alert = false;
             if ($comments) {
-                $note .= sprintf('<hr>%s', $comments);
                 // Send out alerts if comments are included
                 $alert = true;
-                $this->logNote(__('Status Changed'), $note, $thisstaff, $alert);
+                $this->logNote(__('Status Changed'), $comments, $thisstaff, $alert);
             }
         }
         // Log events via callback
@@ -1140,7 +1133,7 @@ implements RestrictedAccess, Threadable {
         if (!($status=$this->getStatus()->getReopenStatus()))
             $status = $cfg->getDefaultTicketStatusId();
 
-        return $status ? $this->setStatus($status, 'Reopened') : false;
+        return $status ? $this->setStatus($status) : false;
     }
 
     function onNewTicket($message, $autorespond=true, $alertstaff=true) {
@@ -2381,8 +2374,7 @@ implements RestrictedAccess, Threadable {
         if ($vars['note_status_id']
             && ($status=TicketStatus::lookup($vars['note_status_id']))
         ) {
-            if ($this->setStatus($status))
-                $this->reload();
+            $this->setStatus($status);
         }
 
         $activity = $vars['activity'] ?: _S('New Internal Note');
@@ -3294,8 +3286,6 @@ implements RestrictedAccess, Threadable {
             $ticket->logNote(_S('New Ticket'), $vars['note'], $thisstaff, false);
         }
 
-        $ticket->reload();
-
         if (!$cfg->notifyONNewStaffTicket()
             || !isset($vars['alertuser'])
             || !($dept=$ticket->getDept())
diff --git a/scp/tickets.php b/scp/tickets.php
index 9e244bcc6..3f1882217 100644
--- a/scp/tickets.php
+++ b/scp/tickets.php
@@ -358,8 +358,6 @@ if($_POST && !$errors):
         default:
             $errors['err']=__('Unknown action');
         endswitch;
-        if($ticket && is_object($ticket))
-            $ticket->reload();//Reload ticket info following post processing
     }elseif($_POST['a']) {
 
         switch($_POST['a']) {
diff --git a/tickets.php b/tickets.php
index 875fdfec4..070cb2567 100644
--- a/tickets.php
+++ b/tickets.php
@@ -103,7 +103,6 @@ if ($_POST && is_object($ticket) && $ticket->getId()) {
     default:
         $errors['err']=__('Unknown action');
     }
-    $ticket->reload();
 }
 elseif (is_object($ticket) && $ticket->getId()) {
     switch(strtolower($_REQUEST['a'])) {
-- 
GitLab