Esempio n. 1
0
 public function onDispatch(MvcEvent $e)
 {
     /** @var ConsoleRequest $request */
     $request = $this->getRequest();
     $queueName = $request->getParam('queueName');
     $messageId = $request->getParam('messageId');
     if (!isset($this->config[$queueName])) {
         echo "Bad queue name: " . $queueName;
         return;
     }
     $this->queueConfig = $this->config[$queueName];
     $this->debug("Queue name: " . $queueName);
     $this->debug("Message Id: " . $messageId);
     /** @var QueueMessage $message */
     $message = $this->messageRepository->findById($messageId);
     /** @var WorkerInterface $handler */
     $handler = $this->getServiceLocator()->get($this->queueConfig['handler']);
     $message->setProcessed();
     $this->messageRepository->add($message);
     try {
         $handler->handle($message->getMessage());
     } catch (\Exception $e) {
         $message->setFailed($e->getMessage());
         $this->messageRepository->add($message);
     }
     $message->setCompleted();
     $this->messageRepository->add($message);
     $this->debug("done");
 }
Esempio n. 2
0
 public function isValid($value)
 {
     $entity = $this->repository->findById($value);
     $this->setValue($value);
     if (!$entity) {
         $this->error(self::ENTITY_NOT_EXIST);
         return false;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * Execute the request
  *
  * @param  MvcEvent $e
  * @return ReadViewModelInterface
  */
 public function onDispatch(MvcEvent $e)
 {
     $entity = $this->repository->find($this->criteria);
     if (!$entity) {
         return $this->notFoundAction();
     }
     $this->viewModel->setEntity($entity);
     $e->setResult($this->viewModel);
     return $this->viewModel;
 }
Esempio n. 4
0
 /**
  * Produces a new message.
  *
  * @param string $queueName The queue name
  * @param array $message The message
  *
  * @return void
  *
  * @codeCoverageIgnore
  */
 public function produce($queueName, array $message)
 {
     if (!isset($this->config['queues'][$queueName])) {
         throw new Exception\QueueDoesNotExistsException("Queue {$queueName} does not exists.");
     }
     $queueMessage = new QueueMessage(['queueName' => $queueName, 'message' => Json::encode($message), 'status' => QueueMessage::STATUS_NEW, 'options' => Json::encode($this->config['queues'][$queueName])]);
     $this->messageRepository->add($queueMessage);
     if ($this->config['realtime-server']['enabled']) {
         $this->sendMessage(['queueName' => $queueName, 'messageId' => $queueMessage->getId()]);
     }
 }
Esempio n. 5
0
 /**
  * @return void
  */
 public function initialize()
 {
     $this->criteria = $this->getVariable('validCriteria', []);
     $this->currentPage = isset($this->criteria['page']) ? $this->criteria['page'] : 1;
     $this->itemsCountPerPage = isset($this->criteria['limit']) ? $this->criteria['limit'] : 20;
     $criteria = $this->repository->createCriteria($this->criteria);
     $this->count = $this->repository->count($criteria);
     $this->zendPaginator = new ZendPaginator(new NullFill($this->count));
     $this->zendPaginator->setCurrentPageNumber($this->currentPage);
     $this->zendPaginator->setDefaultItemCountPerPage($this->itemsCountPerPage);
     $this->zendPaginator->setPageRange(5);
 }
Esempio n. 6
0
 public function handle($criteria, $data)
 {
     $entity = $this->entityFactory->create($data);
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('create.pre', $entity, $data);
         $this->eventManager->trigger($event);
     }
     $this->repository->add($entity);
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('create.post', $entity, $data);
         $this->eventManager->trigger($event);
     }
     return $entity;
 }
Esempio n. 7
0
 public function handle($criteria, $changes)
 {
     if (empty($criteria['limit'])) {
         $criteria['limit'] = 20;
     }
     if (!isset($criteria['offset']) && empty($criteria['page'])) {
         $criteria['page'] = 1;
     }
     if (empty($criteria['order'])) {
         $criteria['order'] = 'id DESC';
     }
     $criteria = $this->repository->createCriteria($criteria);
     return $this->repository->findMany($criteria);
 }
Esempio n. 8
0
 /**
  * @param EventInterface $event
  */
 public function __invoke(EventInterface $event)
 {
     /** @var Message $message */
     $message = $event->getParam('message');
     /** @var Template $template */
     $template = $event->getParam('template');
     /** @var \Zend\Mail\AddressList $toAddress */
     $toAddress = $message->getTo();
     $toAddress->rewind();
     $fromAddress = $message->getFrom();
     $fromAddress->rewind();
     /** @var \Zend\Mime\Message $body */
     $body = $message->getBody();
     $entry = new MailLogEntry(['mailFrom' => $fromAddress->current()->getEmail(), 'mailTo' => $toAddress->current()->getEmail(), 'subject' => $message->getSubject(), 'layoutId' => $template->getLayoutId(), 'templateId' => $template->getId(), 'body' => $body->getPartContent(0), 'calculatedVars' => json_encode($event->getParam('data'))]);
     $this->logRepository->add($entry);
 }
Esempio n. 9
0
 /**
  * @return EntityInterface
  */
 public function handle($filter, $changes)
 {
     /** @var CriteriaInterface $criteria */
     $criteria = $this->repository->createCriteria($filter);
     $entity = $this->repository->find($criteria);
     if (!$entity) {
         throw new EntityNotFoundException("Entity does not found.");
     }
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('delete.pre', $entity);
         $this->eventManager->trigger($event);
     }
     $this->repository->remove($entity);
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('delete.post', $entity);
         $this->eventManager->trigger($event);
     }
     return $entity;
 }
Esempio n. 10
0
 /**
  * Execute the request
  *
  * @param  MvcEvent $e
  * @return ListViewModelInterface
  */
 public function onDispatch(MvcEvent $e)
 {
     if ($this->inputFilter) {
         $this->inputFilter->setData($this->query);
         if ($this->inputFilter->isValid()) {
             $validData = $this->inputFilter->getValues();
             $criteria = $this->repository->createCriteria($validData);
             $collection = $this->repository->findMany($criteria);
             $this->viewModel->setCollection($collection);
             $this->viewModel->setInputData($validData);
         } else {
             $this->viewModel->setErrors($this->inputFilter->getMessages());
             $this->viewModel->setInputData($this->query);
         }
     } else {
         $criteria = $this->repository->createCriteria($this->query);
         $collection = $this->repository->findMany($criteria);
         $this->viewModel->setCollection($collection);
         $this->viewModel->setInputData($this->query);
     }
     $e->setResult($this->viewModel);
     return $this->viewModel;
 }
 /**
  * @param array $filter
  * @return CriteriaInterface
  */
 public function createCriteria(array $filter = [])
 {
     return $this->entityRepository->createCriteria($filter);
 }
Esempio n. 12
0
 public function handle($criteria, $changes)
 {
     $criteria = $this->repository->createCriteria($criteria);
     return $this->repository->find($criteria);
 }