Пример #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 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;
 }