Esempio n. 1
0
 public function getListForProcessing($limit)
 {
     $filter = new MailQueueFilter();
     $filter->setStateIds(array(MailQueueItemState::ID_QUEUED, MailQueueItemState::ID_RETRY));
     $filter->addOrderByStateId(true);
     $filter->addOrderByCreatedOn(false);
     $filter->setLimit($limit);
     $list = $this->mailQueueRepository->fetchList($filter);
     return $list;
 }
Esempio n. 2
0
 /**
  * @SuppressWarnings(PMD.CyclomaticComplexity)
  * @SuppressWarnings(PMD.NPathComplexity)
  * @SuppressWarnings(PMD.ExcessiveMethodLength)
  */
 private function createQueryBuilder(MailQueueFilter $filter)
 {
     $queryBuilder = $this->entityManager->createQueryBuilder()->select('mailQueueItem')->from(MailQueueItem::class, 'mailQueueItem');
     $joins = array();
     if ($filter->getStateIds() !== null) {
         $queryBuilder->andWhere('mailQueueItemState.id IN (:stateIds)')->setParameter('stateIds', $filter->getStateIds());
     }
     if ($filter->getOrder()) {
         foreach ($filter->getOrder() as $orderItem) {
             $orderItemNames = array_keys($orderItem);
             $orderItemName = $orderItemNames[0];
             switch ($orderItemName) {
                 case 'createdOn':
                     $orderAttributeName = 'mailQueueItem.createdOn';
                     break;
                 case 'state.id':
                     $joins[] = 'mailQueueItemState';
                     $orderAttributeName = 'mailQueueItemState.id';
                     break;
                 default:
                     throw new Exception('Unknown order item name \'' . $orderItemName . '\'');
             }
             $orderDirection = $orderItem[$orderItemName] ? 'ASC' : 'DESC';
             $queryBuilder->addOrderBy($orderAttributeName, $orderDirection);
         }
     }
     if ($filter->getLimit() !== null) {
         $queryBuilder->setMaxResults($filter->getLimit());
     }
     $joins = array_unique($joins);
     foreach ($joins as $join) {
         switch ($join) {
             case 'mailQueueItemState':
                 $queryBuilder->join('mailQueueItem.state', 'mailQueueItemState');
                 break;
             default:
                 throw new Exception('Unknown join \'' . $join . '\'');
         }
     }
     return $queryBuilder;
 }