eltrino / diamantedesk-application

DiamanteDesk
http://diamantedesk.com/
Other
119 stars 42 forks source link

diamante.ERROR: Error processing message: An account with this email address already exists / recipient vs from mismatch #14

Closed quazardous closed 8 years ago

quazardous commented 8 years ago

HI,

I've got errors when launching:

php app/console oro:cron:diamante:emailprocessing:general -vvv

imap is OK, first message was ok.

there is something wrong with the logic:

...
// src/Diamante/DeskBundle/Infrastructure/Ticket/EmailProcessing/TicketStrategy.php
// line 148

    private function processWatchers(Message $message, $ticket)
    {
        if (!$ticket) {
            return;
        }

        /** @var Message\MessageRecipient $recipient */
        foreach ($message->getRecipients() as $recipient) {

// you're getting the recipient email...
            $email = $recipient->getEmail();

            if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) {
                continue;
            }

// your getting the user associated withe the recipient...
            $user = $this->diamanteUserService->getUserByEmail($email);

            if (is_null($user)) {
// your trying to create a user if not exists
                $user = $this->diamanteUserService->createDiamanteUser($this->prepareCreateUserCommand($message));
            }

            $this->watchersService->addWatcher($ticket, $user);
        }
    }
...

// line 215
    protected function prepareCreateUserCommand(Message $message)
    {
        $command = new CreateDiamanteUserCommand();

// but your trying to create a user from the FROM attribute !!!
// but you were testing the RECIPIENT earlier ???
// it's wrong, no !?

        $command->email     = $message->getFrom()->getEmail();
        $command->username  = $message->getFrom()->getEmail();
        $command->firstName = $message->getFrom()->getFirstName();
        $command->lastName  = $message->getFrom()->getLastName();

        return $command;
    }
...

Of course I'm a total newby with diamente...

a quick backtrace

I'm on the master branch with a composer update

Diamante\UserBundle\Api\Internal\UserServiceImpl->createDiamanteUser() called at [/home/david/www/desk-application/src/Diamante/DeskBundle/Infrastructure/Ticket/EmailProcessing/TicketStrategy.php:167]
#1  Diamante\DeskBundle\Infrastructure\Ticket\EmailProcessing\TicketStrategy->processWatchers() called at [/home/david/www/desk-application/src/Diamante/DeskBundle/Infrastructure/Ticket/EmailProcessing/TicketStrategy.php:118]
#2  Diamante\DeskBundle\Infrastructure\Ticket\EmailProcessing\TicketStrategy->process() called at [/home/david/www/desk-application/src/Diamante/EmailProcessingBundle/Model/Processing/Context.php:31]
#3  Diamante\EmailProcessingBundle\Model\Processing\Context->execute() called at [/home/david/www/desk-application/src/Diamante/EmailProcessingBundle/Model/Service/MessageProcessingManager.php:57]
#4  Diamante\EmailProcessingBundle\Model\Service\MessageProcessingManager->handle() called at [/home/david/www/desk-application/src/Diamante/EmailProcessingBundle/Api/Impl/EmailProcessingServiceImpl.php:67]
#5  Diamante\EmailProcessingBundle\Api\Impl\EmailProcessingServiceImpl->process() called at [/home/david/www/desk-application/src/Diamante/EmailProcessingBundle/Command/GeneralEmailProcessingCommand.php:35]
#6  Diamante\EmailProcessingBundle\Command\GeneralEmailProcessingCommand->execute() called at [/home/david/www/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256]
#7  Symfony\Component\Console\Command\Command->run() called at [/home/david/www/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:846]
#8  Symfony\Component\Console\Application->doRunCommand() called at [/home/david/www/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:189]
#9  Symfony\Component\Console\Application->doRun() called at [/home/david/www/desk-application/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96]
#10 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() called at [/home/david/www/desk-application/vendor/jms/job-queue-bundle/JMS/JobQueueBundle/Console/Application.php:45]
#11 JMS\JobQueueBundle\Console\Application->doRun() called at [/home/david/www/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:120]
#12 Symfony\Component\Console\Application->run() called at [/home/david/www/desk-application/app/console:23]
quazardous commented 8 years ago

quick fix


...

            if (is_null($user)) {
                $user = $this->diamanteUserService->createDiamanteUser($this->prepareCreateUserCommandRecipient($recipient));
            }

...
    protected function prepareCreateUserCommandRecipient(MessageRecipient $recipient)
    {
        $command = new CreateDiamanteUserCommand();
        $command->email     = $recipient->getEmail();
        $command->username  = $recipient->getEmail();
        $command->firstName = $recipient->getFirstName();
        $command->lastName  = $recipient->getLastName();

        return $command;
    }
...
kstupak commented 8 years ago

Hi @quazardous Thank you, the behavior is indeed invalid.

We'll fix this issue in next release.

kstupak commented 8 years ago

Fixed