Esempio n. 1
0
 public function testWasSyncedAtLeastOnce()
 {
     $channel = new Channel();
     $status = new Status();
     $status->setChannel($channel)->setCode(Status::STATUS_COMPLETED);
     $this->assertFalse(FormUtils::wasSyncedAtLeastOnce($channel));
     $channel->addStatus($status);
     $this->assertTrue(FormUtils::wasSyncedAtLeastOnce($channel));
 }
Esempio n. 2
0
 public function testSkippedIfSyncedDuringConfiguredInterval()
 {
     $transport = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface');
     $channel = new Channel();
     $connector = $this->getConnector($this->transportMock, $this->stepExecutionMock, $channel);
     $status = new Status();
     $status->setCode($status::STATUS_COMPLETED);
     $status->setConnector($connector->getType());
     $status->setDate(new \DateTime('-10 minutes', new \DateTimeZone('UTC')));
     $this->expectLastCompletedStatusForConnector($status, $channel, $connector->getType());
     $connector->setStepExecution($this->stepExecutionMock);
     $transport->expects($this->never())->method('getRegions');
     $this->assertInstanceOf('\\EmptyIterator', $connector->getSourceIterator());
 }
Esempio n. 3
0
 public function testInitializationInForceMode()
 {
     $channel = new Channel();
     $context = new Context(['force' => true]);
     $connector = $this->getConnector($this->transportMock, $this->stepExecutionMock, $channel, $context);
     $status = new Status();
     $status->setCode($status::STATUS_COMPLETED);
     $status->setConnector($connector->getType());
     $channel->addStatus($status);
     $this->transportMock->expects($this->once())->method('init');
     $iterator = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Iterator\\UpdatedLoaderInterface');
     $iterator->expects($this->exactly((int) (!$this->supportsForceMode())))->method('setMode');
     $iterator->expects($this->exactly((int) (!$this->supportsForceMode())))->method('setStartDate');
     $this->transportMock->expects($this->at(1))->method($this->getIteratorGetterMethodName())->will($this->returnValue($iterator));
     $connector->setStepExecution($this->stepExecutionMock);
 }
Esempio n. 4
0
 public function testInitializationInUpdatedMode()
 {
     $channel = new Channel();
     $connector = $this->getConnector($this->transportMock, $this->stepExecutionMock, $channel);
     $status = new Status();
     $status->setCode($status::STATUS_COMPLETED);
     $status->setConnector($connector->getType());
     $status->setDate(new \DateTime('-10 days', new \DateTimeZone('UTC')));
     $this->expectLastCompletedStatusForConnector($status, $channel, $connector->getType());
     $expectedDateInFilter = clone $status->getDate();
     $assumptionInterval = $this->config['sync_settings']['mistiming_assumption_interval'];
     $expectedDateInFilter->sub(\DateInterval::createFromDateString($assumptionInterval));
     $iterator = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Iterator\\UpdatedLoaderInterface');
     $iterator->expects($this->once())->method('setStartDate')->with($this->equalTo($expectedDateInFilter));
     $this->transportMock->expects($this->at(0))->method($this->getIteratorGetterMethodName())->will($this->returnValue($iterator));
     $connector->setStepExecution($this->stepExecutionMock);
 }
 /**
  * @param ChannelRepository $repository
  * @param Channel $integration
  * @param string $connector
  */
 protected function addInitialStatus(ChannelRepository $repository, Channel $integration, $connector)
 {
     /** @var MagentoSoapTransport $transport */
     $transport = $integration->getTransport();
     $syncStartDate = $transport->getSyncStartDate();
     $now = new \DateTime('now', new \DateTimeZone('UTC'));
     $status = new Status();
     $status->setData([AbstractInitialProcessor::INITIAL_SYNCED_TO => $syncStartDate->format(\DateTime::ISO8601)]);
     $status->setConnector($connector);
     $status->setDate($now);
     $status->setChannel($integration);
     $status->setCode(Status::STATUS_COMPLETED);
     $status->setMessage('Automatically added initial connector status.');
     $repository->addStatus($integration, $status);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     foreach ($this->data as $data) {
         $status = new Status();
         $status->setChannel($this->getReference($data['channel']));
         $status->setCode($data['status']);
         $status->setConnector($data['connector']);
         $status->setDate(new \DateTime($data['date'], new \DateTimeZone('UTC')));
         $status->setMessage($data['message']);
         $this->setReference($data['reference'], $status);
         $manager->persist($status);
     }
     $manager->flush();
 }
Esempio n. 7
0
 /**
  * Creates status of connector of integration.
  *
  * @param ConnectorInterface $connector
  * @return Status
  */
 protected function createConnectorStatus(ConnectorInterface $connector)
 {
     $status = new Status();
     $status->setConnector($connector->getType());
     return $status;
 }
Esempio n. 8
0
 /**
  * @param Status $status
  *
  * @return \DateTime
  */
 protected function getStartDate(Status $status = null)
 {
     $jobContext = $this->stepExecution->getJobExecution()->getExecutionContext();
     $initialSyncedTo = $jobContext->get(InitialSyncProcessor::INITIAL_SYNCED_TO);
     if ($initialSyncedTo) {
         return $initialSyncedTo;
     }
     // If connector has status use it's information for start date
     if ($status) {
         $data = $status->getData();
         if (empty($data[AbstractInitialProcessor::SKIP_STATUS])) {
             if (!empty($data[self::LAST_SYNC_KEY])) {
                 return new \DateTime($data[self::LAST_SYNC_KEY], new \DateTimeZone('UTC'));
             }
             return clone $status->getDate();
         }
     }
     // If there is no status and LAST_SYNC_KEY is present in contexts use it
     $lastSyncDate = $this->stepExecution->getExecutionContext()->get(self::LAST_SYNC_KEY);
     if ($lastSyncDate) {
         return $lastSyncDate;
     } elseif ($jobContext->get(self::LAST_SYNC_KEY)) {
         return $jobContext->get(self::LAST_SYNC_KEY);
     }
     return new \DateTime('now', new \DateTimeZone('UTC'));
 }
Esempio n. 9
0
 /**
  * @param Status $status
  *
  * @return bool
  */
 protected function isIntegrationConnectorProcessSuccess(Status $status)
 {
     return $status->getCode() == Status::STATUS_COMPLETED;
 }
Esempio n. 10
0
 /**
  * @param string      $connector
  * @param string      $jobName
  * @param array       $configuration
  * @param Integration $integration
  * @param boolean     $saveStatus
  *
  * @return boolean
  */
 protected function processImport($connector, $jobName, $configuration, Integration $integration, $saveStatus)
 {
     $jobResult = $this->jobExecutor->executeJob(ProcessorRegistry::TYPE_IMPORT, $jobName, $configuration);
     /** @var ContextInterface $contexts */
     $context = $jobResult->getContext();
     $counts = [];
     if ($context) {
         $counts['process'] = $counts['warnings'] = 0;
         $counts['read'] = $context->getReadCount();
         $counts['process'] += $counts['add'] = $context->getAddCount();
         $counts['process'] += $counts['update'] = $context->getUpdateCount();
         $counts['process'] += $counts['delete'] = $context->getDeleteCount();
     }
     $exceptions = $jobResult->getFailureExceptions();
     $isSuccess = $jobResult->isSuccessful() && empty($exceptions);
     $connectorData = $context->getValue(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY);
     $status = new Status();
     $status->setConnector($connector);
     if (is_array($connectorData)) {
         $status->setData($connectorData);
     }
     if (!$isSuccess) {
         $this->logger->error('Errors were occurred:');
         $exceptions = implode(PHP_EOL, $exceptions);
         $this->logger->error($exceptions, ['exceptions' => $jobResult->getFailureExceptions()]);
         $status->setCode(Status::STATUS_FAILED)->setMessage($exceptions);
     } else {
         $message = '';
         if ($context->getErrors()) {
             $message = 'Some entities were skipped due to warnings:';
             foreach ($context->getErrors() as $error) {
                 $message .= $error . PHP_EOL;
             }
             $this->logger->warning($message);
         }
         $message .= sprintf("Stats: read [%d], process [%d], updated [%d], added [%d], delete [%d], invalid entities: [%d]", $counts['read'], $counts['process'], $counts['update'], $counts['add'], $counts['delete'], $context->getErrorEntriesCount());
         $this->logger->info($message);
         $status->setCode(Status::STATUS_COMPLETED)->setMessage($message);
     }
     if ($saveStatus) {
         $this->doctrineRegistry->getRepository('OroIntegrationBundle:Channel')->addStatus($integration, $status);
         if ($integration->getEditMode() < Integration::EDIT_MODE_RESTRICTED) {
             $integration->setEditMode(Integration::EDIT_MODE_RESTRICTED);
         }
     }
     return $isSuccess;
 }
Esempio n. 11
0
 /**
  * @param string      $connector
  * @param string      $jobName
  * @param array       $configuration
  * @param Integration $integration
  *
  * @return boolean
  */
 protected function processImport($connector, $jobName, $configuration, Integration $integration)
 {
     $event = new SyncEvent($jobName, $configuration);
     $this->eventDispatcher->dispatch(SyncEvent::SYNC_BEFORE, $event);
     $configuration = $event->getConfiguration();
     $jobResult = $this->jobExecutor->executeJob(ProcessorRegistry::TYPE_IMPORT, $jobName, $configuration);
     $this->eventDispatcher->dispatch(SyncEvent::SYNC_AFTER, new SyncEvent($jobName, $configuration, $jobResult));
     /** @var ContextInterface $contexts */
     $context = $jobResult->getContext();
     $connectorData = $errors = [];
     if ($context) {
         $connectorData = $context->getValue(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY);
         $errors = $context->getErrors();
     }
     $exceptions = $jobResult->getFailureExceptions();
     $isSuccess = $jobResult->isSuccessful() && empty($exceptions);
     $status = new Status();
     $status->setConnector($connector);
     $status->setData(is_array($connectorData) ? $connectorData : []);
     $message = $this->formatResultMessage($context);
     $this->logger->info($message);
     if ($isSuccess) {
         if ($errors) {
             $warningsText = 'Some entities were skipped due to warnings:' . PHP_EOL;
             $warningsText .= implode($errors, PHP_EOL);
             $this->logger->warning($warningsText);
             $message .= PHP_EOL . $warningsText;
         }
         $status->setCode(Status::STATUS_COMPLETED)->setMessage($message);
     } else {
         $this->logger->error('Errors were occurred:');
         $exceptions = implode(PHP_EOL, $exceptions);
         $this->logger->error($exceptions);
         $status->setCode(Status::STATUS_FAILED)->setMessage($exceptions);
     }
     $this->doctrineRegistry->getRepository('OroIntegrationBundle:Channel')->addStatus($integration, $status);
     if ($integration->getEditMode() < Integration::EDIT_MODE_RESTRICTED) {
         $integration->setEditMode(Integration::EDIT_MODE_RESTRICTED);
     }
     return $isSuccess;
 }