예제 #1
0
 /**
  * @param $jobName
  * @param $configuration
  *
  * @return $this
  */
 protected function processExport($jobName, $configuration)
 {
     $jobResult = $this->jobExecutor->executeJob(ProcessorRegistry::TYPE_EXPORT, $jobName, $configuration);
     $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);
     if (!$isSuccess) {
         $this->logger->error('Errors were occurred:');
         $exceptions = implode(PHP_EOL, $exceptions);
         $this->logger->error($exceptions, ['exceptions' => $jobResult->getFailureExceptions()]);
     } else {
         if ($context->getErrors()) {
             $this->logger->warning('Some entities were skipped due to warnings:');
             foreach ($context->getErrors() as $error) {
                 $this->logger->warning($error);
             }
         }
         $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);
     }
     return $this;
 }
예제 #2
0
 /**
  * @param array $expectedConfig
  */
 public function assertExecuteJob(array $expectedConfig = null)
 {
     $jobResult = new JobResult();
     $jobResult->setContext(new TestContext());
     $jobResult->setSuccessful(true);
     if ($expectedConfig) {
         $this->jobExecutor->expects($this->any())->method('executeJob')->with($this->equalTo(ProcessorRegistry::TYPE_IMPORT), $this->equalTo('test job'), $this->callback(function (array $config) use($expectedConfig) {
             // dictionary
             if (!array_key_exists('initialSyncInterval', $config)) {
                 return true;
             }
             $this->assertArrayHasKey(ProcessorRegistry::TYPE_IMPORT, $config);
             $diff = array_diff_key($config[ProcessorRegistry::TYPE_IMPORT], $expectedConfig);
             if (!$diff) {
                 $this->assertEquals($expectedConfig, $config[ProcessorRegistry::TYPE_IMPORT]);
                 return true;
             }
             $intersect = array_diff_key($config[ProcessorRegistry::TYPE_IMPORT], $diff);
             $this->assertEquals($expectedConfig, $intersect);
             if ($diff) {
                 $this->assertArrayHasKey('initialSyncedTo', $diff);
                 /** @var \DateTime $date */
                 $date = $diff['initialSyncedTo'];
                 $interval = $date->diff(new \DateTime('now', new \DateTimeZone('UTC')));
                 $this->assertEmpty($interval->m);
             }
             return true;
         }))->will($this->returnValue($jobResult));
     } else {
         $this->jobExecutor->expects($this->any())->method('executeJob')->with(ProcessorRegistry::TYPE_IMPORT, 'test job', $this->isType('array'))->will($this->returnValue($jobResult));
     }
 }
예제 #3
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;
 }