/** * Updates email references' threadId * * @param EntityManager $entityManager * @param Email $entity */ protected function updateRefs(EntityManager $entityManager, Email $entity) { if ($entity->getThread()) { /** @var Email $email */ foreach ($this->emailThreadProvider->getEmailReferences($this->em, $entity) as $email) { if (!$email->getThread()) { $email->setThread($entity->getThread()); $entityManager->persist($email); } } } }
/** * @param EntityManager $em * @param Email $email */ protected function copyContexts(EntityManager $em, Email $email) { $thread = $email->getThread(); if ($thread) { $relatedEmails = $em->getRepository(Email::ENTITY_CLASS)->findByThread($thread); $contexts = $this->emailActivityListProvider->getTargetEntities($email); // from email to thread emails if (count($contexts) > 0) { foreach ($relatedEmails as $relatedEmail) { if ($email->getId() !== $relatedEmail->getId()) { $this->changeContexts($em, $relatedEmail, $contexts); } } } else { // from thread to email $relatedEmails = $this->emailThreadProvider->getEmailReferences($em, $email); if (count($relatedEmails) > 0) { $parentEmail = $relatedEmails[0]; $contexts = $this->emailActivityListProvider->getTargetEntities($parentEmail); $this->changeContexts($em, $email, $contexts); } } } }