/** * Handles issue editing * * Choosing a person involves going through a whole person finding process * at a different url. Once the user has chosen a new person, they will * return here, passing in the person_id they have chosen * * @param REQUEST issue_id Existing issues are edited by passing in an Issue * @param REQUEST ticket_id New issues are created by passing in a Ticket * @param REQUEST person_id The new reportedByPerson */ public function update() { //------------------------------------------------------------------- // Load all the data that's passed in //------------------------------------------------------------------- try { // To edit existing issues, pass in the issue_id if (!empty($_REQUEST['issue_id'])) { $issue = new Issue($_REQUEST['issue_id']); } else { if (!empty($_REQUEST['ticket_id'])) { $issue = new Issue(); $issue->setTicket_id($_REQUEST['ticket_id']); } else { throw new \Exception('tickets/unknownTicket'); } } } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; header('Location: ' . BASE_URL . '/tickets'); exit; } if (isset($_REQUEST['person_id'])) { $issue->setReportedByPerson_id($_REQUEST['person_id']); } //------------------------------------------------------------------- // Handle any stuff the user posts //------------------------------------------------------------------- if (isset($_POST['issueType_id'])) { $issue->handleUpdate($_POST); try { $issue->save(); $action = new Action('update'); $history = new IssueHistory(); $history->setIssue($issue); $history->setAction($action); $history->save(); // Update the search index // Make sure the ticket uses the latest issue information $ticket = new Ticket($issue->getTicket_id()); $ticket->updateSearchIndex(); header('Location: ' . $ticket->getURL()); exit; } catch (\Exception $e) { $_SESSION['errorMessages'][] = $e; } } //------------------------------------------------------------------- // Display the view //------------------------------------------------------------------- $ticket = $issue->getTicket(); $this->template->setFilename('tickets'); $this->template->blocks['ticket-panel'][] = new Block('tickets/ticketInfo.inc', array('ticket' => $ticket, 'disableButtons' => true)); $this->template->blocks['history-panel'][] = new Block('tickets/history.inc', array('history' => $ticket->getHistory())); $this->template->blocks['issue-panel'][] = new Block('tickets/updateIssueForm.inc', array('issue' => $issue, 'ticket' => $ticket)); $this->addLocationInfoBlocks($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(); // Create the entry in the history log $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(); $this->getCategory()->onTicketAdd($this); } 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); }