From ec62d3ff0ab62bf724f6d03ea4c793325efaa9f4 Mon Sep 17 00:00:00 2001 From: Makar Sichevoy Date: Tue, 12 Jul 2016 14:16:23 +0300 Subject: [PATCH] BAP-11039: Integrity constraint violation during IMAP synchronization --- .../ImapBundle/Sync/ImapEmailSynchronizationProcessor.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Oro/Bundle/ImapBundle/Sync/ImapEmailSynchronizationProcessor.php b/src/Oro/Bundle/ImapBundle/Sync/ImapEmailSynchronizationProcessor.php index ec5a15636e6..dc04088797a 100644 --- a/src/Oro/Bundle/ImapBundle/Sync/ImapEmailSynchronizationProcessor.php +++ b/src/Oro/Bundle/ImapBundle/Sync/ImapEmailSynchronizationProcessor.php @@ -563,7 +563,10 @@ protected function removeImapEmailReference(ImapEmail $imapEmail) $emailUser = $imapEmail->getEmail()->getEmailUserByFolder($imapEmail->getImapFolder()->getFolder()); if ($emailUser != null) { - $imapEmail->getEmail()->getEmailUsers()->removeElement($emailUser); + $emailUser->removeFolder($imapEmail->getImapFolder()->getFolder()); + if (!$emailUser->getFolders()->count()) { + $imapEmail->getEmail()->getEmailUsers()->removeElement($emailUser); + } } $this->em->remove($imapEmail); }