/** * @dataProvider withTagsProvider */ public function testLogWithTags($level, $message, $expected) { $this->output->expects($this->once())->method('getVerbosity')->will($this->returnValue(OutputInterface::VERBOSITY_DEBUG)); $this->output->expects($this->exactly(1))->method('writeln')->with($expected); $logger = new OutputLogger($this->output, true, null, null, true); $logger->log($level, $message); }
/** * {@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; }
/** * {@internaldoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $logger = new OutputLogger($output); /** @var EmailFlagManager $emailFlagManager */ $emailFlagManager = $this->getContainer()->get('oro_email.email.flag.manager'); $seenStatus = $input->getOption('seen') === 'true'; $emailUserIds = $input->getOption('ids'); foreach ($emailUserIds as $emailUserId) { $emailUser = $this->getContainer()->get('doctrine')->getRepository('OroEmailBundle:EmailUser')->find($emailUserId); if ($emailUser) { try { if ($seenStatus) { $emailFlagManager->setSeen($emailUser); } else { $emailFlagManager->setUnseen($emailUser); } $msg = sprintf('Email flag synced for email user - %s', $emailUser->getId()); $output->writeln('<info>' . $msg . '</info>'); } catch (Exception $e) { $warn = sprintf('Email flag cannot be synced for email user - %s', $emailUser->getId()); $output->writeln('<info>' . $warn . '</info>'); $logger->warning($warn); } $emailUser->decrementUnsyncedFlagCount(); } else { $warn = sprintf('Not found email user - %s', $emailUser->getId()); $output->writeln('<info>' . $warn . '</info>'); $logger->warning($warn); } } $this->getEmailUserManager()->flush(); }
/** * @param Daemon $daemon * @param OutputLogger $logger */ protected function doStart(Daemon $daemon, OutputLogger $logger) { try { if ($daemon->run()) { $logger->info('Daemon was started'); } } catch (\Exception $e) { $logger->info('Daemon can`t be started'); } }
/** * {@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'); } }
/** * {@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; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $logger = new OutputLogger($output); if ($this->getContainer()->get('oro_cron.job_manager')->getRunningJobsCount(self::COMMAND_NAME) > 1) { $logger->warning('Parsing job already running. Terminating current job.'); return self::STATUS_SUCCESS; } /** @var TrackingProcessor $processor */ $processor = $this->getContainer()->get('oro_tracking.processor.tracking_processor'); $maxExecutionTime = $input->getOption('max-execution-time'); if ($maxExecutionTime && is_numeric($maxExecutionTime)) { $processor->setMaxExecutionTime($maxExecutionTime); } $processor->setLogger($logger); $processor->process(); return self::STATUS_SUCCESS; }
/** * {@internaldoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $logger = new OutputLogger($output); /** @var EmailCacheManager $emailCacheManager */ $emailCacheManager = $this->getContainer()->get('oro_email.email.cache.manager'); $emailId = $input->getOption('id'); $email = $this->getContainer()->get("doctrine")->getRepository('OroEmailBundle:Email')->find($emailId); if ($email) { try { $emailCacheManager->ensureEmailBodyCached($email); $output->writeln(sprintf('<info>Email body synced for email - %s</info>', $email->getId())); } catch (LoadEmailBodyException $e) { $warn = sprintf('Email body cannot be loaded for email - %s', $email->getId()); $output->writeln('<info>' . $warn . '</info>'); $logger->warning($warn); } } }
/** * {@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->info(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->info('Completed'); return 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; }