Пример #1
0
 /**
  * @param Integration $integration
  *
  * @return ChannelObjectBuilder
  */
 public function createBuilderForIntegration(Integration $integration)
 {
     $channel = new Channel();
     $settingsProvider = $this->settingsProvider;
     $type = $this->getChannelTypeForIntegration($this->settingsProvider, $integration->getType());
     $connectors = $integration->getConnectors();
     $entities = array_filter($settingsProvider->getEntitiesByChannelType($type), function ($entityName) use($settingsProvider, &$connectors) {
         $connector = $settingsProvider->getIntegrationConnectorName($entityName);
         $key = array_search($connector, $connectors);
         $enabled = $key !== false;
         if ($enabled) {
             unset($connectors[$key]);
         }
         return $enabled;
     });
     // disable connectors without correspondent entity
     $connectors = array_diff($integration->getConnectors(), $connectors);
     $identity = $settingsProvider->getCustomerIdentityFromConfig($type);
     if (!in_array($identity, $entities, true)) {
         array_unshift($entities, $identity);
         $connector = $settingsProvider->getIntegrationConnectorName($identity);
         if (false !== $connector) {
             array_unshift($connectors, $connector);
         }
     }
     $integration->setEditMode(Integration::EDIT_MODE_DISALLOW);
     $integration->setConnectors($connectors);
     $builder = new ChannelObjectBuilder($this->registry->getManager(), $this->settingsProvider, $channel);
     $builder->setChannelType($type)->setEntities($entities);
     return $builder;
 }
Пример #2
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);
 }
Пример #3
0
 /**
  * Delete integration
  *
  * @param integration $integration
  *
  * @return bool
  */
 public function delete(Integration $integration)
 {
     try {
         $this->em->getConnection()->beginTransaction();
         $type = $integration->getType();
         foreach ($this->deleteProviders as $deleteProvider) {
             if ($deleteProvider->supports($type)) {
                 $deleteProvider->deleteRelatedData($integration);
             }
         }
         $this->em->remove($integration);
         $this->em->flush();
         $this->em->getConnection()->commit();
     } catch (\Exception $e) {
         $this->em->getConnection()->rollback();
         return false;
     }
     return true;
 }
Пример #4
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);
     }
 }
Пример #5
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);
         }
     }
 }
Пример #6
0
 /**
  * Reset connector statuses and transport initial sync start date.
  *
  * @param Integration $integration
  */
 protected function forceSync(Integration $integration)
 {
     $connectors = $integration->getConnectors();
     foreach ($connectors as $connectorName) {
         $connector = $this->registry->getConnectorType($integration->getType(), $connectorName);
         if ($connector instanceof ForceConnectorInterface && $connector->supportsForceSync()) {
             $this->markConnectorSyncStatusesSkipped($integration, $connectorName);
         }
     }
     /** @var MagentoSoapTransport $transport */
     $transport = $integration->getTransport();
     $transport->setInitialSyncStartDate(null);
     $this->saveEntity($transport);
 }
Пример #7
0
 /**
  * Checks if there is at least one connector that supports force sync.
  *
  * @param Integration $integration
  *
  * @return boolean
  */
 public function supportsForceSync(Integration $integration)
 {
     $connectors = $this->getRegisteredConnectorsTypes($integration->getType());
     foreach ($connectors as $connector) {
         if ($connector instanceof ForceConnectorInterface) {
             if ($connector->supportsForceSync()) {
                 return true;
             }
         }
     }
     return false;
 }
Пример #8
0
 /**
  * Clone object here because it will be modified and changes should not be shared between
  *
  * @param Integration $integration
  * @param string      $connector
  *
  * @return TwoWaySyncConnectorInterface
  */
 protected function getRealConnector(Integration $integration, $connector)
 {
     return clone $this->registry->getConnectorType($integration->getType(), $connector);
 }
Пример #9
0
 /**
  * @param Channel $integration
  * @return bool
  */
 public function hasProcessorForIntegration(Channel $integration)
 {
     return array_key_exists($integration->getType(), $this->processors);
 }
Пример #10
0
 /**
  * @param Integration $integration
  * @param BlockingJob $blockingJobManager
  *
  * @return bool
  */
 protected function isBlockingJobRunning(Integration $integration, BlockingJob $blockingJobManager)
 {
     if ($blockingJobManager->hasBlockingJobs($integration->getType())) {
         $commandNames = $blockingJobManager->getBlockingJobs($integration->getType());
         $commandNames = $commandNames->getCommandName();
         $managerRegistry = $this->getService('doctrine');
         /** @var ManagerRegistry $managerRegistry */
         $running = $managerRegistry->getRepository('OroIntegrationBundle:Channel')->getRunningSyncJobsCountByCommands($commandNames);
         if ($running > 0) {
             return true;
         }
     }
     return false;
 }
Пример #11
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);
 }
 /**
  * @param Channel $data
  * @return bool
  */
 public function isApplicable(Channel $data = null)
 {
     return $data && $data->getType() === ChannelType::TYPE;
 }