Exemplo n.º 1
0
 protected function getImportProcessorsChoices($entityName)
 {
     $aliases = $this->processorRegistry->getProcessorAliasesByEntity(ProcessorRegistry::TYPE_IMPORT, $entityName);
     $result = array();
     foreach ($aliases as $alias) {
         $result[$alias] = $this->generateProcessorLabel($alias);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @param array $processors
  * @param string $type
  * @param array $expected
  *
  * @dataProvider processorsByTypeDataProvider
  */
 public function testGetProcessorsByType(array $processors, $type, array $expected)
 {
     foreach ($processors as $processorType => $processorsByType) {
         foreach ($processorsByType as $processorName => $processor) {
             $this->registry->registerProcessor($processor, $processorType, '\\stdClass', $processorName);
         }
     }
     $this->assertEquals($expected, $this->registry->getProcessorsByType($type));
 }
 /**
  * @return ProcessorInterface
  * @throws InvalidConfigurationException
  * @throws LogicException
  */
 protected function getDelegateProcessor()
 {
     if (!$this->stepExecution) {
         throw new LogicException('Step execution entity must be injected to processor.');
     }
     $context = $this->contextRegistry->getByStepExecution($this->stepExecution);
     if (!$context->getOption('processorAlias')) {
         throw new InvalidConfigurationException('Configuration of processor must contain "processorAlias" options.');
     }
     $result = $this->processorRegistry->getProcessor($this->delegateType, $context->getOption('processorAlias'));
     if ($result instanceof ContextAwareInterface) {
         $result->setImportExportContext($context);
     }
     if ($result instanceof StepExecutionAwareInterface) {
         $result->setStepExecution($this->stepExecution);
     }
     return $result;
 }
Exemplo n.º 4
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;
 }
 /**
  * @dataProvider submitDataProvider
  * @param mixed $submitData
  * @param mixed $formData
  * @param array $formOptions
  */
 public function testSubmit($submitData, $formData, array $formOptions)
 {
     $this->processorRegistry->expects($this->any())->method('getProcessorAliasesByEntity')->will($this->returnCallback(function ($type, $entityName) {
         \PHPUnit_Framework_Assert::assertEquals(ProcessorRegistry::TYPE_IMPORT, $type);
         return array($type . $entityName);
     }));
     $form = $this->factory->create($this->type, null, $formOptions);
     $this->assertTrue($form->has('file'));
     $this->assertEquals('file', $form->get('file')->getConfig()->getType()->getName());
     $this->assertTrue($form->get('file')->getConfig()->getOption('required'));
     $this->assertTrue($form->has('processorAlias'));
     $this->assertEquals('choice', $form->get('processorAlias')->getConfig()->getType()->getName());
     $this->assertTrue($form->get('processorAlias')->getConfig()->getOption('required'));
     $key = ProcessorRegistry::TYPE_IMPORT . $formOptions['entityName'];
     $this->assertEquals(array($key => 'oro.importexport.import.' . $key), $form->get('processorAlias')->getConfig()->getOption('choices'));
     $this->assertEquals(array('oro.importexport.import.' . $key), $form->get('processorAlias')->getConfig()->getOption('preferred_choices'));
     $form->submit($submitData);
     $this->assertTrue($form->isSynchronized());
     $this->assertEquals($formData, $form->getData());
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
 public function assertProcessCalls()
 {
     $this->logger->expects($this->any())->method('critical')->with($this->equalTo(''));
     $this->logger->expects($this->never())->method('critical');
     $this->processorRegistry->expects($this->any())->method('getProcessorAliasesByEntity')->will($this->returnValue([]));
 }
 /**
  * @expectedException \Oro\Bundle\ImportExportBundle\Exception\UnexpectedValueException
  * @expectedExceptionMessage Processor with type "import" and alias "foo_alias" is not exist
  */
 public function testGetProcessorEntityNameFails()
 {
     $type = ProcessorRegistry::TYPE_IMPORT;
     $alias = 'foo_alias';
     $this->registry->getProcessorEntityName($type, $alias);
 }