/**
  * Update Ticket
  *
  * @param UpdateTicketCommand $command
  * @return \Diamante\DeskBundle\Model\Ticket\Ticket
  * @throws \RuntimeException if unable to load required ticket and assignee
  */
 public function updateTicket(UpdateTicketCommand $command)
 {
     \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput');
     $ticket = $this->loadTicketById($command->id);
     $this->isGranted('EDIT', $ticket);
     $reporter = $ticket->getReporter();
     if ((string) $command->reporter !== (string) $reporter) {
         $reporter = $command->reporter;
     }
     $assignee = null;
     if ($command->assignee) {
         $assignee = $ticket->getAssignee();
         $currentAssigneeId = empty($assignee) ? null : $assignee->getId();
         if ($command->assignee != $currentAssigneeId) {
             $assignee = $this->userService->getByUser(new User((int) $command->assignee, User::TYPE_ORO));
         }
     }
     $ticket->update($command->subject, $command->description, $reporter, new Priority($command->priority), new Status($command->status), new Source($command->source), $assignee);
     if (is_array($command->attachmentsInput) && false === empty($command->attachmentsInput)) {
         foreach ($command->attachmentsInput as $each) {
             $this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $ticket);
         }
     }
     $this->ticketRepository->store($ticket);
     $this->tagManager->deleteTaggingByParams($ticket->getTags(), get_class($ticket), $ticket->getId());
     $tags = $command->tags;
     $tags['owner'] = $tags['all'];
     $ticket->setTags($tags);
     $this->tagManager->saveTagging($ticket);
     $this->dispatchEvents($ticket);
     return $ticket;
 }
 /**
  * Update Ticket Comment content
  * @param Command\CommentCommand $command
  * @return void
  */
 public function updateTicketComment(Command\CommentCommand $command)
 {
     $comment = $this->loadCommentBy($command->id);
     $this->isGranted('EDIT', $comment);
     \Assert\that($command->attachmentsInput)->nullOr()->all()->isInstanceOf('Diamante\\DeskBundle\\Api\\Dto\\AttachmentInput');
     $comment->updateContent($command->content);
     $comment->setPrivate($command->private);
     if ($command->attachmentsInput) {
         foreach ($command->attachmentsInput as $each) {
             $this->attachmentManager->createNewAttachment($each->getFilename(), $each->getContent(), $comment);
         }
     }
     $this->commentRepository->store($comment);
     $ticket = $comment->getTicket();
     $newStatus = new Status($command->ticketStatus);
     if (false === $ticket->getStatus()->equals($newStatus)) {
         $ticket->updateStatus($newStatus);
         $this->ticketRepository->store($ticket);
     }
     $this->dispatchEvents($comment, $ticket);
 }
 /**
  * @param array $attachments
  * @param AttachmentHolder $attachmentHolder
  */
 private function createAttachments(array $attachments, AttachmentHolder $attachmentHolder)
 {
     foreach ($attachments as $attachment) {
         $this->attachmentManager->createNewAttachment($attachment->getName(), $attachment->getContent(), $attachmentHolder);
     }
 }