/** * @param Message $message */ public function process(Message $message) { $diamanteUser = $this->diamanteUserService->getUserByEmail($message->getFrom()->getEmail()); if (is_null($diamanteUser) || !$diamanteUser->isDiamanteUser()) { $id = $this->diamanteUserService->createDiamanteUser($this->prepareCreateUserCommand($message->getFrom())); $diamanteUser = new User($id, User::TYPE_DIAMANTE); } $attachments = $message->getAttachments(); if (!$message->getReference()) { $defaultBranch = (int) $this->configManager->get('diamante_desk.default_branch'); if (is_null($defaultBranch)) { throw new \RuntimeException("Invalid configuration, default branch should be configured"); } $branch = $this->branchService->getBranch($defaultBranch); $assigneeId = $branch->getDefaultAssigneeId() ? $branch->getDefaultAssigneeId() : null; $ticket = $this->messageReferenceService->createTicket($message, $defaultBranch, (string) $diamanteUser, $assigneeId, $attachments); } else { $ticket = $this->messageReferenceService->createCommentForTicket($message->getContent(), (string) $diamanteUser, $message->getReference(), $attachments); } $this->processWatchers($message, $ticket); }
/** * @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); }
/** * @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; }