/** * {@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} */ 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 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; }
/** * {@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; }
/** * @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".'); } }
/** * {@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); } }
/** * {@inheritdoc} */ protected function initializeFromContext(ContextInterface $context) { if (!$this->contextKey) { throw new \InvalidArgumentException('Context key is missing'); } $this->entities = [$context->getOption($this->contextKey)]; }
/** * @return string */ protected function getEntityName() { if ($this->entityName) { return $this->entityName; } else { return $this->context->getOption('entityName'); } }
/** * {@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()); }
/** * {@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')); } }
/** * {@inheritdoc} */ protected function initializeFromContext(ContextInterface $context) { if (!$context->hasOption('data')) { throw new InvalidConfigurationException('Configuration reader must contain "data".'); } else { $this->data = $context->getOption('data'); } }
/** * {@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); } }
/** * @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; }
/** * {@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; }
/** * 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)); } }
/** * @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; }
/** * 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); }
/** * @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'); } }
/** * @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'); } } }
/** * {@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".'); } }
/** * {@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'); } }