/** * Creates Ticket and Message Reference fot it * * @param Message $message * @param $branchId * @param $reporter * @param $assigneeId * @param array|null $attachments * @return \Diamante\DeskBundle\Model\Ticket\Ticket * @throws \RuntimeException if unable to load required branch, reporter, assignee */ public function createTicket(Message $message, $branchId, $reporter, $assigneeId, array $attachments = null) { $subject = $message->getSubject(); if (empty($message->getSubject())) { $subject = self::EMPTY_SUBJECT_PLACEHOLDER; } $command = new CreateTicketCommand(); $command->subject = $subject; $command->description = $message->getContent(); $command->branch = $branchId; $command->reporter = $reporter; $command->assignee = $assigneeId; $command->source = Source::EMAIL; $command->attachmentsInput = $this->convertAttachments($attachments); $command->priority = Priority::PRIORITY_LOW; $command->status = Status::NEW_ONE; $ticket = $this->ticketService->createTicket($command); $this->createMessageReference($message->getMessageId(), $ticket, $message->getTo()); return $ticket; }
public function testProcessWhenMessageWithReference() { $message = new Message(self::DUMMY_UNIQUE_ID, self::DUMMY_MESSAGE_ID, self::DUMMY_SUBJECT, self::DUMMY_CONTENT, $this->getDummyFrom(), self::DUMMY_MESSAGE_TO, self::DUMMY_REFERENCE); $diamanteUser = $this->getReporter(1); $this->userService->expects($this->once())->method('getUserByEmail')->with($this->equalTo(self::DUMMY_MESSAGE_FROM))->will($this->returnValue($diamanteUser)); $reporter = $this->getReporter($diamanteUser->getId()); $this->messageReferenceService->expects($this->once())->method('createCommentForTicket')->with($this->equalTo($message->getContent()), $reporter, $message->getReference()); $this->ticketStrategy->process($message); }
/** * @param Message $message */ public function process(Message $message) { $email = $message->getFrom()->getEmail(); $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email); $type = User::TYPE_DIAMANTE; if (is_null($diamanteUser)) { $sender = $message->getFrom(); $diamanteUser = $this->diamanteUserFactory->create($email, $sender->getFirstName(), $sender->getLastName()); $this->diamanteUserRepository->store($diamanteUser); } $reporterId = $diamanteUser->getId(); $reporter = new User($reporterId, $type); $attachments = $message->getAttachments(); if (!$message->getReference()) { $branchId = $this->getAppropriateBranch($message->getFrom()->getEmail(), $message->getTo()); $assigneeId = $this->branchEmailConfigurationService->getBranchDefaultAssignee($branchId); $ticket = $this->messageReferenceService->createTicket($message->getMessageId(), $branchId, $message->getSubject(), $message->getContent(), $reporter, $assigneeId, $attachments); } else { $this->eventDispatcher->removeListener('commentWasAddedToTicket', array($this->ticketNotificationsSubscriber, 'processEvent')); $ticket = $this->messageReferenceService->createCommentForTicket($message->getContent(), $reporter, $message->getReference(), $attachments); } $this->processWatchers($message, $ticket); }