示例#1
0
 public function testImapFolderGetterAndSetter()
 {
     $folder = new ImapEmailFolder();
     $imapEmail = new ImapEmail();
     $this->assertNull($imapEmail->getImapFolder());
     $imapEmail->setImapFolder($folder);
     $this->assertSame($folder, $imapEmail->getImapFolder());
 }
 /**
  * Creates new ImapEmail object
  *
  * @param int             $uid
  * @param EmailEntity     $email
  * @param ImapEmailFolder $imapFolder
  *
  * @return ImapEmail
  */
 protected function createImapEmail($uid, EmailEntity $email, ImapEmailFolder $imapFolder)
 {
     $imapEmail = new ImapEmail();
     $imapEmail->setUid($uid)->setEmail($email)->setImapFolder($imapFolder);
     return $imapEmail;
 }
 /**
  * @param ImapEmail|null $existingImapEmail
  * @param bool $isMultiFolder
  * @param Email $email
  *
  * @return bool
  */
 protected function isMovableToOtherFolder($existingImapEmail, $isMultiFolder, $email)
 {
     return !$isMultiFolder && $existingImapEmail && $email->getId()->getUid() === $existingImapEmail->getUid();
 }
 /**
  * Saves emails into the database
  *
  * @param Email[] $emails
  * @param EmailFolder $folder
  */
 protected function saveEmails(array $emails, EmailFolder $folder)
 {
     $this->emailEntityBuilder->removeEmails();
     $uids = array_map(function ($el) {
         /** @var Email $el */
         return $el->getId()->getUid();
     }, $emails);
     $repo = $this->em->getRepository('OroImapBundle:ImapEmail');
     $query = $repo->createQueryBuilder('e')->select('e.uid')->innerJoin('e.email', 'se')->innerJoin('se.folder', 'sf')->where('sf.id = :folderId AND e.uid IN (:uids)')->setParameter('folderId', $folder->getId())->setParameter('uids', $uids)->getQuery();
     $existingUids = array_map(function ($el) {
         return $el['uid'];
     }, $query->getResult());
     foreach ($emails as $src) {
         if (!in_array($src->getId()->getUid(), $existingUids)) {
             $this->log->notice(sprintf('Persisting "%s" email (UID: %d) ...', $src->getSubject(), $src->getId()->getUid()));
             $email = $this->emailEntityBuilder->email($src->getSubject(), $src->getFrom(), $src->getToRecipients(), $src->getSentAt(), $src->getReceivedAt(), $src->getInternalDate(), $src->getImportance(), $src->getCcRecipients(), $src->getBccRecipients());
             $email->setFolder($folder);
             $imapEmail = new ImapEmail();
             $imapEmail->setUid($src->getId()->getUid())->setEmail($email);
             $this->em->persist($imapEmail);
             $this->log->notice(sprintf('The "%s" email was persisted.', $src->getSubject()));
         } else {
             $this->log->notice(sprintf('Skip "%s" (UID: %d) email, because it is already synchronised.', $src->getSubject(), $src->getId()->getUid()));
         }
     }
     $this->emailEntityBuilder->getBatch()->persist($this->em);
     $this->em->flush();
 }