/** * Delete ticket update * * @param integer $id */ public function action_delete($id) { // Get the ticket update $history = \traq\models\TicketHistory::find($id); // Delete the update $history->delete(); // Is this an ajax request? if (Request::isAjax()) { // Render the view View::set('history', $history); } else { // Just redirect back to the ticket Request::redirectTo($history->ticket->href()); } }
/** * Update ticket. * * @param integer $id id matching ticket_id */ public function updateAction($id) { if (!$this->hasPermission('update_tickets') || !$this->hasPermission('comment_on_tickets')) { return $this->show403(); } // Fetch the ticket, but filter it by ticket_id and project_id $ticket = ticketQuery()->addSelect('t.*')->where('t.ticket_id = ?')->andWhere('t.project_id = ?')->setParameter(0, $id)->setParameter(1, $this->currentProject['id'])->fetch(); if ($this->hasPermission('update_tickets')) { $data = $this->ticketParamsUpdate(); $changes = $this->makeChanges($ticket, $data); } else { $data = []; $changes = []; } if ($this->hasPermission('comment_on_tickets')) { $comment = empty(Request::$post->get('comment')) ? null : Request::$post->get('comment'); } if (count($changes) || Request::$post->get('comment')) { $update = new TicketHistory(['user_id' => $this->currentUser['id'], 'ticket_id' => $ticket['id'], 'changes' => count($changes) ? $changes : null, 'comment' => isset($comment) ? $comment : null]); $ticket->set($data); if ($ticket->validate()) { $ticket->save(); $update->save(); // Which action is being performed? $status = Status::find($ticket->status_id)->name; if (!count($changes)) { $action = 'ticket_comment'; $status = null; } elseif ($ticket->isClosing) { $action = 'ticket_closed'; } elseif ($ticket->isReopening) { $action = 'ticket_reopened'; } else { $action = 'ticket_updated'; $status = null; } $timeline = Timeline::updateTicketEvent($this->currentUser, $ticket, $action, $status); $timeline->save(); return $this->redirectTo('ticket', ['pslug' => $this->currentProject['slug'], $ticket['ticket_id']]); } else { $this->set('ticketModel', $ticket); return $this->render('tickets/update.phtml', ['ticket' => $ticket]); } } else { return $this->redirectTo('ticket', ['pslug' => $this->currentProject['slug'], $ticket['ticket_id']]); } }