예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new OutputLogger($output);
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $con = $em->getConnection();
     if ($input->getOption('dry-run')) {
         $stm = $this->getConditionStatement($con, true);
         $stm->execute();
         $result = $stm->fetchColumn();
         $message = 'Will be removed %d rows';
     } else {
         $em->beginTransaction();
         $result = 0;
         try {
             $stm = $this->getConditionStatement($con);
             $stm->execute();
             $buf = [];
             while ($id = $stm->fetchColumn()) {
                 $buf[] = $id;
                 $result++;
                 $buf = $this->processBuff($em, $buf);
             }
             $this->processBuff($em, $buf, 0);
             $em->commit();
         } catch (\Exception $e) {
             $em->rollback();
             $logger->critical($e->getMessage(), ['exception' => $e]);
             return self::EXITCODE_FAILED;
         }
         $message = 'Removed %d rows';
     }
     $logger->notice(sprintf($message, $result));
     $logger->notice('Completed');
     return self::EXITCODE_SUCCESS;
 }
 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var ImapClearManager $cleaner */
     $cleaner = $this->getContainer()->get('oro_imap.manager.clear');
     $this->logger = new OutputLogger($output);
     $originId = $input->getOption('id');
     if (!$cleaner->clear($originId)) {
         $this->logger->notice('Nothing to clear');
     } else {
         $this->logger->notice('Finished');
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var ChannelRepository $repository */
     $channelId = $input->getOption('channel-id');
     $logger = new OutputLogger($output);
     if ($this->isJobRunning($channelId)) {
         $logger->warning('Job already running. Terminating....');
         return 0;
     }
     /** @var CartExpirationProcessor $processor */
     $processor = $this->getService('orocrm_magento.provider.cart_expiration_processor');
     $repository = $this->getService('doctrine.orm.entity_manager')->getRepository('OroIntegrationBundle:Channel');
     if ($channelId) {
         $channel = $repository->getOrLoadById($channelId);
         if (!$channel) {
             throw new \InvalidArgumentException('Channel with given ID not found');
         }
         $channels = [$channel];
     } else {
         $channels = $repository->getConfiguredChannelsForSync(ChannelType::TYPE);
     }
     $channels = array_filter($channels, function (Channel $channel) {
         $connectors = $channel->getConnectors() ?: [];
         return in_array('cart', $connectors);
     });
     /** @var Channel $channel */
     foreach ($channels as $channel) {
         try {
             $logger->notice(sprintf('Run sync for "%s" channel.', $channel->getName()));
             $processor->process($channel);
         } catch (\Exception $e) {
             $logger->critical($e->getMessage(), ['exception' => $e]);
             //process another channel even in case if exception thrown
             continue;
         }
     }
     $logger->notice('Completed');
     return 0;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if ($output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
         $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
     }
     /** @var ChannelRepository $repository */
     /** @var SyncProcessor $processor */
     $connector = $input->getOption('connector');
     $integrationId = $input->getOption('integration-id');
     $batchSize = $input->getOption('transport-batch-size');
     $connectorParameters = $this->getConnectorParameters($input);
     $entityManager = $this->getService('doctrine.orm.entity_manager');
     $repository = $entityManager->getRepository('OroIntegrationBundle:Channel');
     $logger = new OutputLogger($output);
     $entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
     $exitCode = self::STATUS_SUCCESS;
     if ($this->isJobRunning($integrationId)) {
         $logger->warning('Job already running. Terminating....');
         return self::STATUS_SUCCESS;
     }
     if ($integrationId) {
         $integration = $repository->getOrLoadById($integrationId);
         if (!$integration) {
             $logger->critical(sprintf('Integration with given ID "%d" not found', $integrationId));
             return self::STATUS_FAILED;
         }
         $integrations = [$integration];
     } else {
         $integrations = $repository->getConfiguredChannelsForSync(null, true);
     }
     /* @var Integration $integration */
     foreach ($integrations as $integration) {
         try {
             $logger->notice(sprintf('Run sync for "%s" integration.', $integration->getName()));
             $this->updateToken($integration);
             if ($batchSize) {
                 $integration->getTransport()->getSettingsBag()->set('page_size', $batchSize);
             }
             $processor = $this->getSyncProcessor($integration, $logger);
             $result = $processor->process($integration, $connector, $connectorParameters);
             $exitCode = $result ?: self::STATUS_FAILED;
         } catch (\Exception $e) {
             $logger->critical($e->getMessage(), ['exception' => $e]);
             $exitCode = self::STATUS_FAILED;
             continue;
         }
     }
     $logger->notice('Completed');
     return $exitCode;
 }
예제 #5
0
 /**
  * @param OutputLogger $logger
  * @param Integration $integration
  * @param int|null $batchSize
  * @param $connector
  * @param $connectorParameters
  *
  * @return int
  */
 protected function processIntegration(OutputLogger $logger, Integration $integration, $batchSize, $connector, $connectorParameters)
 {
     try {
         $logger->notice(sprintf('Run sync for "%s" integration.', $integration->getName()));
         $this->updateToken($integration);
         if ($batchSize) {
             $integration->getTransport()->getSettingsBag()->set('page_size', $batchSize);
         }
         $processor = $this->getSyncProcessor($integration, $logger);
         $result = $processor->process($integration, $connector, $connectorParameters);
         $exitCode = $result ?: self::STATUS_FAILED;
     } catch (\Exception $e) {
         $logger->critical($e->getMessage(), ['exception' => $e]);
         $exitCode = self::STATUS_FAILED;
     }
     return $exitCode;
 }