Пример #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
 public function testOnChannelSucceedSave()
 {
     $this->entity->setEntities(['OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1', 'OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2']);
     $this->event->expects($this->once())->method('getChannel')->will($this->returnValue($this->entity));
     $this->settingProvider->expects($this->at(0))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1')->will($this->returnValue('TestConnector1'));
     $this->settingProvider->expects($this->at(1))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2')->will($this->returnValue('TestConnector2'));
     $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em));
     $this->em->expects($this->once())->method('persist')->with($this->integration);
     $this->em->expects($this->once())->method('flush');
     $channelSaveSucceedListener = new ChannelSaveSucceedListener($this->settingProvider, $this->registry);
     $channelSaveSucceedListener->onChannelSucceedSave($this->event);
     $this->assertEquals($this->integration->getConnectors(), ['TestConnector1', 'TestConnector2']);
 }
Пример #3
0
 /**
  * @param Integration $integration
  * @param callable $callback
  * @return array
  */
 protected function getConnectorsToSync(Integration $integration, callable $callback = null)
 {
     $connectors = $integration->getConnectors();
     if ($callback) {
         $connectors = array_filter($connectors, $callback);
     }
     return (array) $connectors;
 }
Пример #4
0
 /**
  * Process integration synchronization
  * By default, if $connector is empty, will process all connectors of given integration
  *
  * @param Integration $integration Integration object
  * @param array       $parameters  Connector additional parameters
  * @param callable    $callback    Callback to filter connectors
  *
  * @return boolean
  */
 protected function processConnectors(Integration $integration, array $parameters = [], callable $callback = null)
 {
     $isSuccess = true;
     $connectors = $integration->getConnectors();
     if ($callback) {
         $connectors = array_filter($connectors, $callback);
     }
     foreach ((array) $connectors as $connector) {
         try {
             $result = $this->processIntegrationConnector($integration, $connector, $parameters);
             $isSuccess = $isSuccess && $result;
         } catch (\Exception $e) {
             $isSuccess = false;
             $this->logger->critical($e->getMessage());
         }
     }
     return $isSuccess;
 }
Пример #5
0
 /**
  * @param Integration $integration
  * @param callable $callback
  *
  * @return string[]
  */
 protected function getTypesOfConnectorsToProcess(Integration $integration, callable $callback = null)
 {
     $connectors = $integration->getConnectors();
     if ($callback) {
         $connectors = array_filter($connectors, $callback);
     }
     return $connectors;
 }
Пример #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);
 }
 public function assertConnectors()
 {
     $this->assertEquals($this->integration->getConnectors(), ['TestConnector1', 'TestConnector2']);
 }