/** * 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 * @param Ticket $ticket */ private function processWatchers(Message $message, $ticket) { if (!$ticket) { return; } /** @var Message\MessageRecipient $recipient */ foreach ($message->getRecipients() as $recipient) { $email = $recipient->getEmail(); if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) { continue; } $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email); $oroUser = $this->oroUserManager->findUserByEmail($email); if ($oroUser) { $user = new User($oroUser->getId(), User::TYPE_ORO); } elseif ($diamanteUser) { $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE); } else { $diamanteUser = $this->diamanteUserFactory->create($email, $recipient->getFirstName(), $recipient->getLastName()); $this->diamanteUserRepository->store($diamanteUser); $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE); } $this->watchersService->addWatcher($ticket, $user); } }
/** * @param Message $message * @param Ticket $ticket */ private function processWatchers(Message $message, $ticket) { if (!$ticket) { return; } /** @var Message\MessageRecipient $recipient */ foreach ($message->getRecipients() as $recipient) { $email = $recipient->getEmail(); if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) { continue; } $user = $this->diamanteUserService->getUserByEmail($email); if (is_null($user)) { $id = $this->diamanteUserService->createDiamanteUser($this->prepareCreateUserCommand($recipient)); $user = new User($id, User::TYPE_DIAMANTE); } $this->watchersService->addWatcher($ticket, $user); } }
/** * @param Message $message * @return CreateDiamanteUserCommand */ protected function prepareCreateUserCommand(Message $message) { $command = new CreateDiamanteUserCommand(); $command->email = $message->getFrom()->getEmail(); $command->username = $message->getFrom()->getEmail(); $command->firstName = $message->getFrom()->getFirstName(); $command->lastName = $message->getFrom()->getLastName(); return $command; }