Пример #1
0
 /**
  * @param MessageCollection $messages
  * @param FiltersCollection $filters
  *
  * @return bool
  */
 public function retrieve(MessageCollection $messages, FiltersCollection $filters = null)
 {
     $findQuery = $this->prepareQuery($filters->getFilter('data'));
     try {
         $retrieved = $this->storage->find($this->collectionName, $findQuery);
         if ($filters->hasFilter('limit')) {
             $retrieved->limit($filters->getFilter('limit'));
         }
         if ($filters->hasFilter('offset')) {
             $retrieved->skip($filters->getFilter('offset'));
         }
         $retrieved->sort(array($this->defaultSortBy => -1));
     } catch (\MongoException $e) {
         $this->lastErrorMsg = $e->getMessage();
         return false;
     }
     foreach ($retrieved as $message) {
         $uniqueId = new UniqueId($message['id']);
         $messageFactory = new MessageFactory($uniqueId);
         $messages[] = $messageFactory->fromArray($message);
     }
     return true;
 }
Пример #2
0
 /**
  * @param RetrieveMessagesEvent $event
  */
 public function onRetrieveMessages(RetrieveMessagesEvent $event)
 {
     if (false === $this->storage->retrieve($event->getMessages(), $event->getFilters())) {
         $event->setError('MongoDB Error occurred while trying to retrieve data: ' . $this->storage->getLastErrorMsg());
     }
 }