Example #1
0
 /**
  * Process integration synchronization
  * By default, if $connector is empty, will process all connectors of given integration
  *
  * @param Integration $integration Integration object
  * @param string      $connector   Connector name
  * @param array       $parameters  Connector additional parameters
  *
  * @return boolean
  */
 public function process(Integration $integration, $connector = null, array $parameters = [])
 {
     if (!$integration->isEnabled()) {
         $this->logger->error(sprintf('Integration "%s" with type "%s" is not enabled. Cannot process synchronization.', $integration->getName(), $integration->getType()));
         return false;
     }
     $callback = null;
     if ($connector) {
         $callback = function ($integrationConnector) use($connector) {
             return $integrationConnector === $connector;
         };
     }
     return $this->processConnectors($integration, $parameters, $callback);
 }
 /**
  * Process channel synchronization
  *
  * @param Integration $integration Integration object
  * @param string      $connector   Connector name
  * @param array       $parameters  Connector additional parameters
  */
 public function process(Integration $integration, $connector, array $parameters)
 {
     if (!$integration->isEnabled()) {
         return;
     }
     try {
         $this->logger->info(sprintf('Start processing "%s" connector', $connector));
         $realConnector = $this->getRealConnector($integration, $connector);
         if (!$realConnector instanceof TwoWaySyncConnectorInterface) {
             throw new LogicException('This connector does not support reverse sync.');
         }
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage());
         return;
     }
     $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);
 }
Example #3
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->isEnabled()) {
         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)];
     if (!$this->isScheduled($args)) {
         $job = new Job(self::JOB_NAME, $args);
         /** @var EntityManager $em */
         $em = $this->registry->getManagerForClass('JMSJobQueueBundle:Job');
         $em->persist($job);
         if (true === $useFlush) {
             $em->flush();
         } else {
             $jobMeta = $em->getClassMetadata('JMSJobQueueBundle:Job');
             $em->getUnitOfWork()->computeChangeSet($jobMeta, $job);
         }
     }
 }
 /**
  * @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->isEnabled()) {
         $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']));
 }
Example #5
0
 /**
  * Process integration connector
  *
  * @param Integration $integration Integration object
  * @param string      $connector   Connector name
  * @param array       $parameters  Connector additional parameters
  *
  * @return boolean
  */
 protected function processIntegrationConnector(Integration $integration, $connector, array $parameters = [])
 {
     if (!$integration->isEnabled()) {
         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);
 }