/** * @param POST ticket_id */ public function recordAction() { if (!empty($_POST['ticket_id'])) { $ticket = $this->loadTicket($_POST['ticket_id']); $history = new TicketHistory(); try { $history->handleUpdate($_POST); $history->save(); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } $this->redirectToTicketView($ticket); } else { header('Location: ' . BASE_URL . '/tickets'); exit; } }
/** * Does all the database work for TicketController::changeStatus * * Saves the ticket and creates history entries for the status change * * This function calls save() as needed. After using this function, * there's no need to make an additional save() call. * * @param array $post[status=>'', 'substatus_id'=>'', 'notes'=>''] */ public function handleChangeStatus($post) { $substatus_id = !empty($post['substatus_id']) ? $post['substatus_id'] : null; $this->setStatus($post['status'], $substatus_id); // add a record to ticket history $action = new Action($post['status']); $history = new TicketHistory(); $history->setTicket($this); $history->setAction($action); $history->setNotes($post['notes']); if (defined('CLOSING_COMMENT_REQUIRED_LENGTH')) { if ($action->getName() === 'closed') { if (strlen($history->getNotes()) < CLOSING_COMMENT_REQUIRED_LENGTH) { throw new \Exception('tickets/missingClosingComment'); } } } $history->save(); $this->save(); }
/** * @param REQUEST ticket_id */ public function changeStatus() { $ticket = $this->loadTicket($_REQUEST['ticket_id']); if (isset($_POST['status'])) { try { $substatus_id = !empty($_POST['substatus_id']) ? $_POST['substatus_id'] : null; $ticket->setStatus($_POST['status'], $substatus_id); // add a record to ticket history $action = new Action($_POST['status']); $history = new TicketHistory(); $history->setTicket($ticket); $history->setAction($action); $history->setNotes($_POST['notes']); if (defined('CLOSING_COMMENT_REQUIRED_LENGTH')) { if ($action->getName() == 'closed') { if (strlen($history->getNotes()) < CLOSING_COMMENT_REQUIRED_LENGTH) { throw new \Exception('tickets/missingClosingComment'); } // Display an alert, reminding them to respond to any citizens $citizens = $ticket->getReportedByPeople(); if (count($citizens)) { $_SESSION['errorMessages'][] = new \Exception('tickets/closingResponseReminder'); } } } $history->save(); $ticket->save(); $this->redirectToTicketView($ticket); } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } // Display the view $this->template->setFilename('tickets'); $this->template->blocks['ticket-panel'][] = new Block('tickets/changeStatusForm.inc', array('ticket' => $ticket)); $this->template->blocks['ticket-panel'][] = new Block('tickets/responseReminder.inc', array('ticket' => $ticket)); $this->addStandardInfoBlocks($ticket); }
/** * Does all the database work for TicketController::add * * Saves the ticket, the issue, and creates history entries * for the open and assignment actions. * * This function calls save() as needed. After using this function, * there's no need to make an additional save() call. * * @param array $post */ public function handleAdd($post) { $zend_db = Database::getConnection(); $zend_db->getDriver()->getConnection()->beginTransaction(); try { $this->handleUpdate($post); // We must add an issue to the ticket for validation to pass $issue = new Issue(); $issue->handleUpdate($post); $this->issues = array($issue); if (!$this->getEnteredByPerson_id() && $issue->getReportedByPerson_id()) { $this->setEnteredByPerson_id($issue->getReportedByPerson_id()); } $this->save(); $issue->setTicket($this); $issue->save(); $history = new TicketHistory(); $history->setTicket($this); $history->setAction(new Action('open')); if ($this->getEnteredByPerson_id()) { $history->setEnteredByPerson_id($this->getEnteredByPerson_id()); } $history->save(); $history = new TicketHistory(); $history->setTicket($this); $history->setAction(new Action('assignment')); $history->setActionPerson_id($this->getAssignedPerson_id()); if (!empty($post['notes'])) { $history->setNotes($post['notes']); } if ($this->getEnteredByPerson_id()) { $history->setEnteredByPerson_id($this->getEnteredByPerson_id()); } $history->save(); } catch (\Exception $e) { $zend_db->getDriver()->getConnection()->rollback(); $search = new Search(); $search->delete($this); $search->solrClient->commit(); throw $e; } $zend_db->getDriver()->getConnection()->commit(); $history->sendNotification($this); }