Skip to content
Snippets Groups Projects
Commit 646fc2c8 authored by Jared Hancock's avatar Jared Hancock
Browse files

Correct set status on new ticket

This affects new ticket by staff as well as honoring the influence of ticket
filters on new ticket, where the status may be set to something other than
the system default. Even the system default may be influenced if it were set
to a closed state derivative.

So the concept is simple: the new status should be set using the standard
logic so that the closed_by staff member, date, events, and other
information is set as normally is when a ticket is closed.
parent 1e686f7d
Branches
Tags
No related merge requests found
...@@ -822,7 +822,7 @@ class Ticket { ...@@ -822,7 +822,7 @@ class Ticket {
} }
//Status helper. //Status helper.
function setStatus($status, $comments='') { function setStatus($status, $comments='', $set_closing_agent=true) {
global $thisstaff; global $thisstaff;
if ($status && is_numeric($status)) if ($status && is_numeric($status))
...@@ -845,7 +845,7 @@ class Ticket { ...@@ -845,7 +845,7 @@ class Ticket {
switch($status->getState()) { switch($status->getState()) {
case 'closed': case 'closed':
$sql.=', closed=NOW(), duedate=NULL '; $sql.=', closed=NOW(), duedate=NULL ';
if ($thisstaff) if ($thisstaff && $set_closing_agent)
$sql.=', staff_id='.db_input($thisstaff->getId()); $sql.=', staff_id='.db_input($thisstaff->getId());
$ecb = function($t) { $ecb = function($t) {
...@@ -877,21 +877,24 @@ class Ticket { ...@@ -877,21 +877,24 @@ class Ticket {
if (!db_query($sql) || !db_affected_rows()) if (!db_query($sql) || !db_affected_rows())
return false; return false;
// Log status change b4 reload // Log status change b4 reload — if currently has a status. (On new
$note = sprintf(__('Status changed from %s to %s by %s'), // ticket, the ticket is opened and thereafter the status is set to
$this->getStatus(), // the requested status).
$status, if ($current_status = $this->getStatus()) {
$thisstaff ?: 'SYSTEM'); $note = sprintf(__('Status changed from %s to %s by %s'),
$this->getStatus(),
$status,
$thisstaff ?: 'SYSTEM');
$alert = false;
if ($comments) {
$note .= sprintf('<hr>%s', $comments);
// Send out alerts if comments are included
$alert = true;
}
$alert = false; $this->logNote(__('Status Changed'), $note, $thisstaff, $alert);
if ($comments) {
$note .= sprintf('<hr>%s', $comments);
// Send out alerts if comments are included
$alert = true;
} }
$this->logNote(__('Status Changed'), $note, $thisstaff, $alert);
// Log events via callback // Log events via callback
if ($ecb) $ecb($this); if ($ecb) $ecb($this);
...@@ -2635,7 +2638,6 @@ class Ticket { ...@@ -2635,7 +2638,6 @@ class Ticket {
.' ,`number`='.db_input($number) .' ,`number`='.db_input($number)
.' ,dept_id='.db_input($deptId) .' ,dept_id='.db_input($deptId)
.' ,topic_id='.db_input($topicId) .' ,topic_id='.db_input($topicId)
.' ,status_id='.db_input($statusId)
.' ,ip_address='.db_input($ipaddress) .' ,ip_address='.db_input($ipaddress)
.' ,source='.db_input($source); .' ,source='.db_input($source);
...@@ -2709,6 +2711,12 @@ class Ticket { ...@@ -2709,6 +2711,12 @@ class Ticket {
$ticket->assignToTeam($vars['teamId'], _S('Auto Assignment')); $ticket->assignToTeam($vars['teamId'], _S('Auto Assignment'));
} }
// Apply requested status — this should be done AFTER assignment,
// because if it is requested to be closed, it should not cause the
// ticket to be reopened for assignment.
if ($statusId)
$ticket->setStatus($statusId, false, false);
/********** double check auto-response ************/ /********** double check auto-response ************/
//Override auto responder if the FROM email is one of the internal emails...loop control. //Override auto responder if the FROM email is one of the internal emails...loop control.
if($autorespond && (Email::getIdByEmail($ticket->getEmail()))) if($autorespond && (Email::getIdByEmail($ticket->getEmail())))
...@@ -2797,11 +2805,7 @@ class Ticket { ...@@ -2797,11 +2805,7 @@ class Ticket {
$vars['response'] = $ticket->replaceVars($vars['response']); $vars['response'] = $ticket->replaceVars($vars['response']);
// $vars['cannedatachments'] contains the attachments placed on // $vars['cannedatachments'] contains the attachments placed on
// the response form. // the response form.
if(($response=$ticket->postReply($vars, $errors, false))) { $response = $ticket->postReply($vars, $errors, false);
//Only state supported is closed on response
if(isset($vars['ticket_state']) && $thisstaff->canCloseTickets())
$ticket->setState($vars['ticket_state']);
}
} }
// Not assigned...save optional note if any // Not assigned...save optional note if any
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment