/** * Creates Comment for Ticket * * @param $content * @param $authorId * @param $messageId * @param array|null $attachments * @return Ticket|null */ public function createCommentForTicket($content, $authorId, $messageId, array $attachments = null) { if (empty($content)) { return null; } $reference = $this->messageReferenceRepository->getReferenceByMessageId($messageId); if (is_null($reference)) { $this->logger->error(sprintf('Ticket not found for message: %s', $messageId)); throw new \RuntimeException('Ticket loading failed, ticket not found.'); } $ticket = $reference->getTicket(); $command = new CommentCommand(); $command->ticket = $ticket->getId(); $command->content = $content; $command->author = User::fromString($authorId); $command->ticketStatus = $ticket->getStatus(); $command->attachmentsInput = $this->convertAttachments($attachments); $this->commentService->postNewCommentForTicket($command); return $ticket; }
/** * Creates Comment for Ticket * * @param $content * @param $authorId * @param $messageId * @param array $attachments * @return Ticket|null */ public function createCommentForTicket($content, $authorId, $messageId, array $attachments = null) { $reference = $this->messageReferenceRepository->getReferenceByMessageId($messageId); if (is_null($reference)) { $this->logger->error(sprintf('Ticket not found for message: %s', $messageId)); throw new \RuntimeException('Ticket loading failed, ticket not found.'); } $ticket = $reference->getTicket(); $author = User::fromString($authorId); if (empty($content)) { return null; } $comment = $this->commentFactory->create($content, $ticket, $author); if ($attachments) { $this->createAttachments($attachments, $comment); } $ticket->postNewComment($comment); $this->ticketRepository->store($ticket); $this->dispatchEvents($ticket); return $ticket; }