コード例 #1
0
ファイル: ImapEmailTest.php プロジェクト: ramunasd/platform
 public function testUidGetterAndSetter()
 {
     $imapEmail = new ImapEmail();
     $this->assertNull($imapEmail->getUid());
     $imapEmail->setUid(123);
     $this->assertEquals(123, $imapEmail->getUid());
 }
コード例 #2
0
 /**
  * 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;
 }
 /**
  * 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();
 }