/** * @return EmailFolder[] */ public function getFolders() { // retrieve folders from imap $folders = $this->connector->findFolders(); // transform folders into tree of models $emailFolderModels = $this->processFolders($folders); if ($this->origin->getId()) { // renew existing folders if origin already exists $existingFolders = $this->getExistingFolders(); // merge synced and existing folders $emailFolderModels = $this->mergeFolders($emailFolderModels, $existingFolders); // mark old folders as outdated $this->removeOutdated($existingFolders); // flush changes $this->em->flush(); } return $this->extractEmailFolders($emailFolderModels); }
/** * Updates a state of the given email origin * * @param EmailOrigin $origin * @param int $syncCode Can be one of self::SYNC_CODE_* constants * @param \DateTime|null $synchronizedAt * @return bool true if the synchronization code was updated; false if no any changes are needed */ protected function changeOriginSyncState(EmailOrigin $origin, $syncCode, $synchronizedAt = null) { $repo = $this->getEntityManager()->getRepository($this->getEmailOriginClass()); $qb = $repo->createQueryBuilder('o')->update()->set('o.syncCode', ':code')->set('o.syncCodeUpdatedAt', ':updated')->where('o.id = :id')->setParameter('code', $syncCode)->setParameter('updated', $this->getCurrentUtcDateTime())->setParameter('id', $origin->getId()); if ($synchronizedAt !== null) { $qb->set('o.synchronizedAt', ':synchronized')->setParameter('synchronized', $synchronizedAt); } if ($syncCode === self::SYNC_CODE_IN_PROCESS) { $qb->andWhere('(o.syncCode IS NULL OR o.syncCode <> :code)'); } if ($syncCode === self::SYNC_CODE_SUCCESS) { $qb->set('o.syncCount', 'o.syncCount + 1'); } $affectedRows = $qb->getQuery()->execute(); return $affectedRows > 0; }
/** * Register EmailOrigin object * * @param EmailOrigin $origin * @throws \LogicException */ public function addOrigin(EmailOrigin $origin) { $key = $origin->getId(); if (isset($this->origins[$key])) { throw new \LogicException(sprintf('The origin %s already exists in the batch.', $origin)); } $this->origins[$key] = $origin; }
/** * @param EmailOrigin $origin * * @return mixed * @throws \Doctrine\ORM\NonUniqueResultException */ public function getOriginOwner(EmailOrigin $origin) { $qb = $this->createQueryBuilder('u')->select('u')->innerJoin('u.emailOrigins', 'o')->where('o.id = :originId')->setParameter('originId', $origin->getId())->setMaxResults(1); return $qb->getQuery()->getOneOrNullResult(); }
/** * Register EmailOrigin object * * @param EmailOrigin $origin * @throws \LogicException */ public function addOrigin(EmailOrigin $origin) { $key = $origin->getId(); $this->origins[$key] = $origin; }
/** * Return test for error message * * @param EmailOrigin $origin - entity EmailOrigin * * @return string */ protected function getErrorMessage(EmailOrigin $origin) { $message = 'Cannot find an email flag manager loader. Origin id: %d.'; return sprintf($message, $origin->getId()); }
/** * @param EmailOrigin $origin * * @return EmailBodyLoaderInterface */ protected function getBodyLoader(EmailOrigin $origin) { $originId = $origin->getId(); if (!isset($this->emailBodyLoaders[$originId])) { $this->emailBodyLoaders[$originId] = $this->selector->select($origin); } return $this->emailBodyLoaders[$originId]; }