From 7f4e62dcfebdba8f0ed37ac01a3ad939354dcfd1 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Thu, 6 Mar 2014 19:00:00 +0000
Subject: [PATCH] Decide if we need to keep the just selected SLA on ticket
 edit

---
 include/class.ticket.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index 17a0ef50b..578cbeeeb 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -1760,13 +1760,19 @@ class Ticket {
             $vars['note']=sprintf('Ticket Updated by %s', $thisstaff->getName());
 
         $this->logNote('Ticket Updated', $vars['note'], $thisstaff);
+
+        // Decide if we need to keep the just selected SLA
+        $keepSLA = ($this->getSLAId() != $vars['slaId']);
+
+        // Reload the ticket so we can do further checking
         $this->reload();
 
         // Reselect SLA if transient
-        if(!$this->getSLAId() || $this->getSLA()->isTransient())
+        if (!$keepSLA
+                && (!$this->getSLA() || $this->getSLA()->isTransient()))
             $this->selectSLAId();
 
-        //Clear overdue flag if duedate or SLA changes and the ticket is no longer overdue.
+        // Clear overdue flag if duedate or SLA changes and the ticket is no longer overdue.
         if($this->isOverdue()
                 && (!$this->getEstDueDate() //Duedate + SLA cleared
                     || Misc::db2gmtime($this->getEstDueDate()) > Misc::gmtime() //New due date in the future.
-- 
GitLab