/** * 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); }