/**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $pages = $this->pageManager->findBy(array('site' => $event->getMessage()->getValue('siteId')));
     $backend = $event->getMessage()->getValue('mode') == 'async' ? $this->asyncBackend : $this->runtimeBackend;
     foreach ($pages as $page) {
         $backend->createAndPublish('sonata.page.create_snapshot', array('pageId' => $page->getId()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $message = $event->getMessage();
     if (!in_array($message->getValue('level'), $this->types)) {
         throw new InvalidParameterException();
     }
     call_user_func(array($this->logger, $message->getValue('level')), $message->getValue('message'));
 }
 /**
  * @param ConsumerEvent $event
  *
  * @return ThumbnailInterface
  */
 protected function getThumbnail(ConsumerEvent $event)
 {
     $thumbnail = $this->container->get($event->getMessage()->getValue('thumbnailId'));
     if (!$thumbnail instanceof ThumbnailInterface) {
         throw new HandlingException(sprintf('Invalid thumbnail instance requested - id: %s', $event->getMessage()->getValue('thumbnailId')));
     }
     return $thumbnail;
 }
 public function process(ConsumerEvent $event)
 {
     $message = $event->getMessage();
     $url = $message->getValue('url');
     $headers = $message->getValue('headers');
     $this->fosCacheManager->invalidatePath($url, $headers);
     $this->cloudFlare->api('zone_file_purge', array('z' => 'mkaciuba.pl', 'url' => 'https://mkaciuba.pl' . $url));
     $this->cloudFlare->api('zone_file_purge', array('z' => 'mkaciuba.pl', 'url' => 'http://mkaciuba.pl' . $url));
 }
 public function it_dump_composer_json_content_to_file(ConsumerEvent $event, Message $message, \Pusher $pusher, Filesystem $filesystem)
 {
     $event->getMessage()->shouldBeCalled()->willReturn($message);
     $message->getValue('channelName')->shouldBeCalled()->willReturn('new_channel');
     $message->getValue('body')->shouldBeCalled()->willReturn('composer.json content');
     $pusher->trigger('new_channel', 'consumer:new-step', array('message' => 'Starting async job'))->shouldBeCalled();
     $filesystem->mkdir(sys_get_temp_dir() . '/' . 'composer_dir')->shouldBeCalled();
     $filesystem->dumpFile(sys_get_temp_dir() . '/composer_dir/composer.json', 'composer.json content')->shouldBeCalled();
     $this->execute($event, 'composer_dir')->shouldReturn(0);
 }
 function it_push_error_message_and_alerts_when_vulnerability_found(SecurityChecker $securityChecker, ConsumerEvent $event, Message $message, \Pusher $pusher)
 {
     $event->getMessage()->shouldBeCalled()->willReturn($message);
     $message->getValue('channelName')->shouldBeCalled()->willReturn('new_channel');
     $pusher->trigger('new_channel', 'consumer:new-step', array('message' => 'Checking vulnerability'))->shouldBeCalled();
     $securityChecker->check(sys_get_temp_dir() . '/composer_dir/composer.lock', 'text')->shouldBeCalled()->willReturn($this->getVulnerabilityMessage());
     $securityChecker->getLastVulnerabilityCount()->shouldBeCalled()->willReturn(1);
     $pusher->trigger('new_channel', 'consumer:step-error', array('message' => 'Vulnerability found : 1'))->shouldBeCalled();
     $pusher->trigger('new_channel', 'consumer:vulnerabilities', array('message' => $this->getVulnerabilityMessage()))->shouldBeCalled();
     $this->execute($event, 'composer_dir')->shouldReturn(0);
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $page = $this->pageManager->findOneBy(array('id' => $event->getMessage()->getValue('pageId')));
     if (!$page) {
         return;
     }
     // start a transaction
     $this->snapshotManager->getConnection()->beginTransaction();
     // cleanup snapshots
     $this->snapshotManager->cleanup($page, $event->getMessage()->getValue('keepSnapshots'));
     // commit the changes
     $this->snapshotManager->getConnection()->commit();
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     if (!$this->mailer->getTransport()->isStarted()) {
         $this->mailer->getTransport()->start();
     }
     $exception = false;
     try {
         $this->sendEmail($event->getMessage());
     } catch (\Exception $e) {
         $exception = $e;
     }
     $this->mailer->getTransport()->stop();
     if ($exception) {
         throw new $exception();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $pageId = $event->getMessage()->getValue('pageId');
     $page = $this->pageManager->findOneBy(array('id' => $pageId));
     if (!$page) {
         return;
     }
     // start a transaction
     $this->snapshotManager->getConnection()->beginTransaction();
     // creating snapshot
     $snapshot = $this->transformer->create($page);
     // update the page status
     $page->setEdited(false);
     $this->pageManager->save($page);
     // save the snapshot
     $this->snapshotManager->save($snapshot);
     $this->snapshotManager->enableSnapshots(array($snapshot));
     // commit the changes
     $this->snapshotManager->getConnection()->commit();
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $message = $event->getMessage();
     $userId = $message->getValue('user_id');
     $cocktailId = $message->getValue('cocktail_id');
     $timestamp = $message->getValue('date');
     $user = $this->userRepository->findOneById($userId);
     if (!$user instanceof User) {
         throw new InvalidParameterException('invalid user id');
     }
     $cocktail = $this->cocktailRepository->findOneById($cocktailId);
     if (!$cocktail instanceof Cocktail) {
         throw new InvalidParameterException('invalid cocktail id');
     }
     if ($user->isConnectedWithFacebook()) {
         $accessToken = $user->getFacebookAccessToken();
         $cocktailUrl = $this->appUrl . $cocktail->getRelativeUrl();
         $this->client->setAccessToken($accessToken);
         $response = $this->client->hadCocktail($cocktailUrl, $timestamp);
         // TODO analyze response and log errors
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $model = $event->getMessage();
     /** @var \Sententiaregum\User\Domain\User $user */
     $user = $model->getValue('user');
     if (null === $user) {
         throw new InvalidParameterException('The "user" parameter is required for the email to send!');
     }
     $emailContent = $model->getValue('content');
     $emailConfig = $model->getValue('config_path');
     $templateParams = $model->getValue('parameters', []);
     $useDefaultEmail = null === $emailConfig;
     if (null === $emailContent && $useDefaultEmail) {
         throw new InvalidParameterException('In order to send an email properly, the parameters "content" or "config_path" are required!');
     }
     $templateParams['user'] = $user;
     $config = $useDefaultEmail ? 'SententiaregumApp:notification' : $emailConfig;
     if ($useDefaultEmail) {
         $templateParams['content'] = $emailContent;
     }
     $locale = $model->getValue('override_locale', false) ? $user->getSimpleProfile()->getLocale() : null;
     $this->mailer->send($config, $templateParams, $locale);
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $orderStatus = $event->getMessage()->getValue('order_status');
     $transactionStatus = $event->getMessage()->getValue('transaction_status');
     $productId = $event->getMessage()->getValue('product_id');
     $productType = $event->getMessage()->getValue('product_type');
     $quantity = $event->getMessage()->getValue('quantity');
     $productManager = $this->getProductManager($productType);
     $productProvider = $this->getProductProvider($productType);
     $diff = $this->generateDiffValue($transactionStatus, $orderStatus, $quantity);
     if ($diff) {
         $productProvider->updateStock($productId, $productManager, $diff);
     }
 }
 /**
  * Extracts a channel name from a ConsumerEvent.
  *
  * @param ConsumerEvent $event
  *
  * @return array
  */
 protected function getChannels(ConsumerEvent $event)
 {
     $message = $event->getMessage();
     return [$message->getValue('channelName')];
 }
 /**
  * Get the related Transaction.
  *
  * @param ConsumerEvent $event
  *
  * @throws \RuntimeException
  *
  * @return TransactionInterface
  */
 protected function getTransaction(ConsumerEvent $event)
 {
     $transactionId = $event->getMessage()->getValue('transaction_id');
     $transaction = $this->transactionManager->findOneBy(array('id' => $transactionId));
     if (!$transaction) {
         throw new \RuntimeException(sprintf('Unable to retrieve Transaction %d', $transactionId));
     }
     return $transaction;
 }
 /**
  * @param ConsumerEvent $event
  * @throws \InvalidArgumentException If the message body does not contain the expected data
  */
 public function process(ConsumerEvent $event)
 {
     $this->logger->debug('Process event {event} from sonata backend', ['event' => $event]);
     $ticket = $event->getMessage()->getValue('ticket', null);
     if (!is_string($ticket) || strlen((string) $ticket) == 0) {
         throw new \InvalidArgumentException('The message body must be an array containing the key "ticket"');
     }
     $this->manager->onMessage(new Message($event->getMessage()->getType(), $ticket));
 }
 public function process(ConsumerEvent $event)
 {
     $message = $event->getMessage();
     $this->logger->info("BatchPhotoConsumer: processing ");
     if ($message->getValue('type') == 'photos') {
         $this->addPhotosToCategory($message);
     } else {
         $this->addCategory($message);
     }
 }