/**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = array())
 {
     if ($this->context && in_array($level, [LogLevel::EMERGENCY, LogLevel::ALERT, LogLevel::CRITICAL, LogLevel::ERROR])) {
         $this->context->addError($message);
     }
     return parent::log($level, $message, $context);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function convertToImportFormat(array $importedRecord, $skipNullValues = true)
 {
     if (empty($importedRecord['entity:id'])) {
         $importedRecord['entity:id'] = (int) $this->context->getOption('entity_id');
     }
     return parent::convertToImportFormat($importedRecord, $skipNullValues);
 }
 /**
  * {@inheritdoc}
  */
 public function convertToImportFormat(array $importedRecord, $skipNullValues = true)
 {
     if ($this->context && $this->context->hasOption('channel')) {
         $importedRecord['channel:id'] = $this->context->getOption('channel');
     }
     return parent::convertToImportFormat($importedRecord, $skipNullValues);
 }
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$this->contextKey) {
         throw new \InvalidArgumentException('Context key is missing');
     }
     $this->entities = [$context->getOption($this->contextKey)];
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('entityName')) {
         throw new InvalidConfigurationException('Configuration of fixture reader must contain "entityName".');
     }
     $this->fixture = $this->templateManager->getEntityFixture($context->getOption('entityName'));
     $this->setSourceIterator($this->fixture->getData());
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('file')) {
         throw new InvalidConfigurationException('Configuration reader must contain "file".');
     } else {
         $this->file = new \SplFileObject($context->getOption('file'));
     }
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('data')) {
         throw new InvalidConfigurationException('Configuration reader must contain "data".');
     } else {
         $this->data = $context->getOption('data');
     }
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function setImportExportContext(ContextInterface $context)
 {
     if (!$context->hasOption('filePath')) {
         throw new InvalidConfigurationException('Configuration of CSV writer must contain "filePath".');
     } else {
         $this->setFilePath($context->getOption('filePath'));
     }
     parent::setImportExportContext($context);
 }
 /**
  * @param ContextInterface $importExportContext
  * @throws InvalidConfigurationException
  */
 public function setImportExportContext(ContextInterface $importExportContext)
 {
     $queryBuilder = $importExportContext->getOption('queryBuilder');
     if (isset($queryBuilder) && $this->dataConverter instanceof QueryBuilderAwareInterface) {
         if (!$queryBuilder instanceof QueryBuilder) {
             throw new InvalidConfigurationException(sprintf('Configuration of processor contains invalid "queryBuilder" option. ' . '"Doctrine\\ORM\\QueryBuilder" type is expected, but "%s" is given', is_object($queryBuilder) ? get_class($queryBuilder) : gettype($queryBuilder)));
         }
         $this->dataConverter->setQueryBuilder($queryBuilder);
     }
 }
Exemplo n.º 10
0
 public function testReadSame()
 {
     $expected = new \stdClass();
     $expected->prop = 'value';
     $this->context->expects($this->once())->method('getOption')->with($this->equalTo('entity'))->will($this->returnValue($expected));
     $this->reader->setContextKey('entity');
     $this->reader->setStepExecution($this->stepExecution);
     $this->assertEquals($expected, $this->reader->read());
     $this->assertNull($this->reader->read());
 }
 /**
  * {@inheritdoc}
  */
 public function process($item)
 {
     if ($this->converter) {
         $item = $this->converter->convertToImportFormat($item);
     }
     $object = $this->serializer->deserialize($item, $this->context->getOption('entityName'), null);
     if ($this->strategy) {
         $object = $this->strategy->process($object);
     }
     return $object ?: null;
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function process($item)
 {
     if ($this->dataConverter) {
         $item = $this->dataConverter->convertToImportFormat($item, false);
     }
     $this->context->setValue('itemData', $item);
     $object = $this->serializer->deserialize($item, $this->context->getOption('entityName'), null, $this->context->getConfiguration());
     if ($this->strategy) {
         $object = $this->strategy->process($object);
     }
     return $object ?: null;
 }
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$this->staticSegmentMemberClassName) {
         throw new InvalidConfigurationException('StaticSegmentMember class name must be provided');
     }
     if (!$this->getSourceIterator()) {
         /** @var Channel $channel */
         $channel = $this->doctrineHelper->getEntityReference($this->channelClassName, $context->getOption('channel'));
         $iterator = new StaticSegmentExportListIterator($this->getSegmentsIterator($channel, $context->getOption('segments')), $this->doctrineHelper);
         $iterator->setStaticSegmentMemberClassName($this->staticSegmentMemberClassName);
         $this->setSourceIterator($iterator);
     }
 }
Exemplo n.º 14
0
 /**
  * @return string
  */
 protected function getEntityName()
 {
     if ($this->entityName) {
         return $this->entityName;
     } else {
         return $this->context->getOption('entityName');
     }
 }
Exemplo n.º 15
0
 /**
  * @param object $entity
  *
  * @return null|object
  */
 protected function validateAndUpdateContext($entity)
 {
     // validate entity
     $validationErrors = $this->strategyHelper->validateEntity($entity);
     if ($validationErrors) {
         $this->context->incrementErrorEntriesCount();
         $errorPrefix = ValidationUtils::guessValidationMessagePrefix($entity);
         $this->strategyHelper->addValidationErrors($validationErrors, $this->context, $errorPrefix);
         return null;
     }
     // increment context counter
     if ($entity->getId()) {
         $this->context->incrementUpdateCount();
     } else {
         $this->context->incrementAddCount();
     }
     return $entity;
 }
Exemplo n.º 16
0
 /**
  * @param ContextInterface $context
  * @throws InvalidConfigurationException
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if ($context->hasOption('entityName')) {
         $this->setSourceEntityName($context->getOption('entityName'), $context->getOption('organization'));
     } elseif ($context->hasOption('queryBuilder')) {
         $this->setSourceQueryBuilder($context->getOption('queryBuilder'));
     } elseif ($context->hasOption('query')) {
         $this->setSourceQuery($context->getOption('query'));
     } elseif (!$this->getSourceIterator()) {
         throw new InvalidConfigurationException('Configuration of entity reader must contain either "entityName", "queryBuilder" or "query".');
     }
 }
 /**
  * @param string $type
  *
  * @return TypeFormatterInterface
  */
 protected function getFormatterForType($type)
 {
     $formatType = $this->context->getOption(FormatterProvider::FORMAT_TYPE);
     if (isset($this->formatters[$formatType][$type])) {
         return $this->formatters[$formatType][$type];
     }
     $formatter = $this->formatterProvider->getFormatterFor($formatType, $type);
     $this->formatters[$formatType][$type] = $formatter;
     return $formatter;
 }
Exemplo n.º 18
0
 /**
  * @param ContextInterface $firstContext
  * @param ContextInterface $context
  */
 public static function mergeContextCounters(ContextInterface $firstContext, ContextInterface $context)
 {
     $firstContext->incrementReadCount($context->getReadCount());
     $firstContext->incrementAddCount($context->getAddCount());
     $firstContext->incrementUpdateCount($context->getUpdateCount());
     $firstContext->incrementReplaceCount($context->getReplaceCount());
     $firstContext->incrementDeleteCount($context->getDeleteCount());
     $firstContext->incrementErrorEntriesCount($context->getErrorEntriesCount());
 }
Exemplo n.º 19
0
 /**
  * Ensure that filtering applied and query builder wrapped in buffered iterator
  * if data source is query builder or just an entity name
  *
  * @param ContextInterface $context
  */
 protected function ensureInitialized(ContextInterface $context)
 {
     if (null !== $this->qb) {
         if ($context->hasOption(self::ID_FILTER)) {
             $optionValue = $context->getOption(self::ID_FILTER);
             $em = $this->qb->getEntityManager();
             $entityNames = $this->qb->getRootEntities();
             $classMetadata = $em->getClassMetadata(reset($entityNames));
             $identifier = $classMetadata->getSingleIdentifierFieldName();
             if (is_array($optionValue)) {
                 $this->qb->andWhere($this->qb->expr()->in('o.' . $identifier, ':id'));
                 $this->qb->setParameter('id', $optionValue);
             } else {
                 $this->qb->andWhere('o.' . $identifier . ' = :id');
             }
             $this->qb->setParameter('id', $optionValue);
         }
         $this->setSourceIterator(new BufferedQueryResultIterator($this->qb));
     }
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function convertToExportFormat(array $exportedRecord, $skipNullValues = true)
 {
     if ($this->context->getValue('columns')) {
         $columns = $this->context->getValue('columns');
     } elseif ($this->context->hasOption('gridName')) {
         $gridName = $this->context->getOption('gridName');
         $gridConfig = $this->gridManagerLink->getService()->getConfigurationForGrid($gridName);
         $columns = $gridConfig->offsetGet('columns');
     } else {
         throw new InvalidConfigurationException('Configuration of datagrid export processor must contain "gridName" or "columns" options.');
     }
     $result = array();
     foreach ($columns as $columnName => $column) {
         if (isset($column['renderable']) && false === $column['renderable']) {
             continue;
         }
         $val = isset($exportedRecord[$columnName]) ? $exportedRecord[$columnName] : null;
         $val = $this->applyFrontendFormatting($val, $column);
         $result[$this->translator->trans($column['label'])] = $val;
     }
     return $result;
 }
Exemplo n.º 21
0
 /**
  * @param array $importedRecord
  * @param ContextInterface|null $context
  * @return array
  */
 public static function addUnknownAttributes(array $importedRecord, ContextInterface $context = null)
 {
     $channelId = null;
     if ($context && $context->hasOption(self::CHANNEL_KEY)) {
         $channelId = $context->getOption(self::CHANNEL_KEY);
     }
     if (!empty($importedRecord[self::ATTRIBUTES_KEY])) {
         foreach ($importedRecord[self::ATTRIBUTES_KEY] as $attribute) {
             $name = $attribute[self::KEY];
             $value = $attribute[self::VALUE];
             $isIdentifier = substr($name, -strlen(self::ID_MARK)) === self::ID_MARK;
             if ($isIdentifier && $channelId) {
                 $name = Inflector::camelize($name);
                 $importedRecord = self::addAttribute($importedRecord, $name, $value);
                 $name = substr($name, 0, strlen($name) - strlen(self::ID_MARK) + 1);
                 $value = ['originId' => $value, self::CHANNEL_KEY => ['id' => $channelId]];
             }
             $name = Inflector::camelize($name);
             $importedRecord = self::addAttribute($importedRecord, $name, $value);
         }
         unset($importedRecord[self::ATTRIBUTES_KEY]);
     }
     return $importedRecord;
 }
Exemplo n.º 22
0
 /**
  * Fetch job execution result statistic from context
  *
  * @param ContextInterface $context
  *
  * @return array
  */
 private function fetchStatistic(ContextInterface $context = null)
 {
     $counts = array_fill_keys(['read', 'processed', 'updated', 'deleted', 'added', 'invalid'], 0);
     if ($context) {
         $counts['read'] = (int) $context->getReadCount();
         $counts['processed'] += $counts['added'] = (int) $context->getAddCount();
         $counts['processed'] += $counts['updated'] = (int) $context->getUpdateCount();
         $counts['processed'] += $counts['deleted'] = (int) $context->getDeleteCount();
         $counts['invalid'] = (int) $context->getErrorEntriesCount();
     }
     return $counts;
 }
Exemplo n.º 23
0
 /**
  * @param ContextInterface $context
  * @throws InvalidConfigurationException
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     if (!$context->hasOption('filePath')) {
         throw new InvalidConfigurationException('Configuration of CSV reader must contain "filePath".');
     } else {
         $this->setFilePath($context->getOption('filePath'));
     }
     if ($context->hasOption('delimiter')) {
         $this->delimiter = $context->getOption('delimiter');
     }
     if ($context->hasOption('enclosure')) {
         $this->enclosure = $context->getOption('enclosure');
     }
     if ($context->hasOption('escape')) {
         $this->escape = $context->getOption('escape');
     }
     if ($context->hasOption('firstLineIsHeader')) {
         $this->firstLineIsHeader = (bool) $context->getOption('firstLineIsHeader');
     }
     if ($context->hasOption('header')) {
         $this->header = $context->getOption('header');
     }
 }
Exemplo n.º 24
0
 /**
  * Get channel instance
  *
  * @param ContextInterface $context
  *
  * @return Integration
  */
 public function getChannel(ContextInterface $context)
 {
     $channel = $this->getEm()->getRepository('OroIntegrationBundle:Channel')->getOrLoadById($context->getOption('channel'));
     return $channel;
 }
 /**
  * {@inheritdoc}
  */
 protected function initializeFromContext(ContextInterface $context)
 {
     $this->priceListId = (int) $context->getOption('price_list_id');
     parent::initializeFromContext($context);
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public function setImportExportContext(ContextInterface $context)
 {
     if ($context->hasOption('delimiter')) {
         $this->delimiter = $context->getOption('delimiter');
     }
     if ($context->hasOption('enclosure')) {
         $this->enclosure = $context->getOption('enclosure');
     }
     if ($context->hasOption('firstLineIsHeader')) {
         $this->firstLineIsHeader = (bool) $context->getOption('firstLineIsHeader');
     }
     if ($context->hasOption('header')) {
         $this->header = $context->getOption('header');
     }
 }
Exemplo n.º 27
0
 /**
  * @param ContextInterface $context
  * @param \Iterator $iterator
  */
 protected function setPredefinedFilters(ContextInterface $context, \Iterator $iterator)
 {
     $filters = null;
     if ($context->hasOption('filters')) {
         $filters = $context->getOption('filters');
         $context->removeOption('filters');
     }
     $complexFilters = null;
     if ($context->hasOption('complex_filters')) {
         $complexFilters = $context->getOption('complex_filters');
         $context->removeOption('complex_filters');
     }
     if ($filters || $complexFilters) {
         if ($iterator instanceof PredefinedFiltersAwareInterface) {
             $predefinedFilters = new BatchFilterBag((array) $filters, (array) $complexFilters);
             $iterator->setPredefinedFiltersBag($predefinedFilters);
         } else {
             throw new \LogicException('Iterator does not support predefined filters');
         }
     }
 }
Exemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function setImportExportContext(ContextInterface $context)
 {
     $this->context = $context;
     if ($context->hasOption('gridName')) {
         $this->grid = $this->gridManagerLink->getService()->getDatagrid($context->getOption('gridName'), $context->getOption('gridParameters'));
         $context->setValue('columns', $this->grid->getConfig()->offsetGet('columns'));
     } else {
         throw new InvalidConfigurationException('Configuration of datagrid export reader must contain "gridName".');
     }
 }
 /**
  * @param array $validationErrors
  * @param ContextInterface $context
  * @param string|null $errorPrefix
  */
 public function addValidationErrors(array $validationErrors, ContextInterface $context, $errorPrefix = null)
 {
     if (null === $errorPrefix) {
         $errorPrefix = $this->translator->trans('oro.importexport.import_error %number%', array('%number%' => $context->getReadOffset()));
     }
     foreach ($validationErrors as $validationError) {
         $context->addError($errorPrefix . ' ' . $validationError);
     }
 }