Пример #1
0
 /**
  * Process channel synchronization
  *
  * @param Integration $integration Integration object
  * @param string      $connector   Connector name
  * @param array       $parameters  Connector additional parameters
  *
  * @return $this
  */
 public function process(Integration $integration, $connector, array $parameters)
 {
     if (!$integration->getEnabled()) {
         return $this;
     }
     try {
         $this->logger->info(sprintf('Start processing "%s" connector', $connector));
         $realConnector = $this->getRealConnector($integration, $connector);
         if (!$realConnector instanceof TwoWaySyncConnectorInterface) {
             throw new LogicException('This connector doesn`t support two-way sync.');
         }
     } catch (\Exception $e) {
         return $this->logger->error($e->getMessage());
     }
     $processorAliases = $this->processorRegistry->getProcessorAliasesByEntity(ProcessorRegistry::TYPE_EXPORT, $realConnector->getImportEntityFQCN());
     $configuration = [ProcessorRegistry::TYPE_EXPORT => array_merge(['entityName' => $realConnector->getImportEntityFQCN(), 'processorAlias' => reset($processorAliases), 'channel' => $integration->getId()], $parameters)];
     $this->processExport($realConnector->getExportJobName(), $configuration);
     return $this;
 }
Пример #2
0
 /**
  * Schedules backward sync job
  *
  * @param Integration $integration
  * @param string      $connectorType
  * @param array       $params
  * @param bool        $useFlush
  *
  * @throws LogicException
  */
 public function schedule(Integration $integration, $connectorType, $params = [], $useFlush = true)
 {
     if (!$integration->getEnabled()) {
         return;
     }
     $connector = $this->typesRegistry->getConnectorType($integration->getType(), $connectorType);
     if (!$connector instanceof TwoWaySyncConnectorInterface) {
         throw new LogicException(sprintf('Unable to schedule job for "%s" connector type', $connectorType));
     }
     $args = ['--integration=' . $integration->getId(), '--connector=' . $connectorType, '--params=' . serialize($params)];
     $job = new Job(self::JOB_NAME, $args);
     if ($useFlush) {
         $this->em->persist($job);
         $this->em->flush();
     } else {
         $uow = $this->em->getUnitOfWork();
         $uow->persist($job);
         $jobMeta = $this->em->getMetadataFactory()->getMetadataFor('JMS\\JobQueueBundle\\Entity\\Job');
         $uow->computeChangeSet($jobMeta, $job);
     }
 }
Пример #3
0
 /**
  * @param Integration $integration
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  * @Route("/toggle/{id}", requirements={"id"="\d+"}, name="oro_integration_toggle")
  * @Acl(
  *      id="oro_integration_toggle",
  *      type="entity",
  *      permission="EDIT",
  *      class="OroIntegrationBundle:Channel"
  * )
  */
 public function toggleAction(Integration $integration)
 {
     if ($integration->getEnabled()) {
         $integration->setEnabled(false);
         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('oro.integration.controller.integration.message.deactivated'));
     } else {
         $integration->setEnabled(true);
         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('oro.integration.controller.integration.message.activated'));
     }
     $em = $this->get('doctrine.orm.entity_manager');
     $em->persist($integration);
     $em->flush($integration);
     return $this->redirect($this->generateUrl('oro_integration_update', ['id' => $integration->getid(), '_enableContentProviders' => 'mainMenu']));
 }
Пример #4
0
 /**
  * Process integration connector
  *
  * @param Integration $integration Integration object
  * @param string      $connector   Connector name
  * @param array       $parameters  Connector additional parameters
  * @param boolean     $saveStatus  Do we need to save new status to bd
  *
  * @return boolean
  */
 protected function processIntegrationConnector(Integration $integration, $connector, array $parameters = [], $saveStatus = true)
 {
     if (!$integration->getEnabled()) {
         return false;
     }
     try {
         $this->logger->info(sprintf('Start processing "%s" connector', $connector));
         // Clone object here because it will be modified and changes should not be shared between
         $realConnector = clone $this->registry->getConnectorType($integration->getType(), $connector);
         $jobName = $realConnector->getImportJobName();
         $processorAliases = $this->processorRegistry->getProcessorAliasesByEntity(ProcessorRegistry::TYPE_IMPORT, $realConnector->getImportEntityFQCN());
     } catch (\Exception $e) {
         // log and continue
         $this->logger->error($e->getMessage());
         $status = new Status();
         $status->setCode(Status::STATUS_FAILED)->setMessage($e->getMessage())->setConnector($connector);
         $this->doctrineRegistry->getRepository('OroIntegrationBundle:Channel')->addStatus($integration, $status);
         return false;
     }
     $configuration = [ProcessorRegistry::TYPE_IMPORT => array_merge(['processorAlias' => reset($processorAliases), 'entityName' => $realConnector->getImportEntityFQCN(), 'channel' => $integration->getId(), 'channelType' => $integration->getType()], $parameters)];
     return $this->processImport($connector, $jobName, $configuration, $integration, $saveStatus);
 }