Ejemplo 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");
 }
Ejemplo n.º 2
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()]);
     }
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 /**
  * @return EntityInterface|null
  */
 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('update.pre', $entity, $changes);
         $this->eventManager->trigger($event);
     }
     $entity->populate($changes);
     $this->repository->add($entity);
     if ($this->eventManager) {
         $event = $this->eventManager->createEvent('update.post', $entity, $changes);
         $this->eventManager->trigger($event);
     }
     return $entity;
 }