abstract class AbstractImporter (View source)

Properties

protected Application $app

The Application container instance.

protected EntityManagerInterface $entityManager

The EntityManager instance.

private bool $dryRun

Is the import process just a test?

private Reader $reader

The CSV Reader instance.

private CategoryInterface $category

The attribute category.

private array|null $attributeKeysAndControllers

The memoized attribute keys and controllers for the attribute category.

private CsvSchema|null $csvSchema

The CSV Schema.

Methods

__construct(Reader $reader, CategoryInterface $category, Application $app)

Initialize the instance.

process(int $dataRowsToSkip = 0, int|null $maxDataRows = null, bool|int $collectData = false)

Process the CSV data.

bool
isDryRun()

Is the import process just a test?

$this
setDryRun(bool $value)

Is the import process just a test?

string[]|Generator
getStaticHeaders()

Get the list of fixed headers.

getObjectWithStaticValues(array $staticValues)

Get or create a ObjectInterface instance starting from its static values.

bool
processHeader(ImportResult $importResult)

Read the header row and initialize the CSV schema.

null|array
processData(ImportResult $importResult, int $dataRowsToSkip, int|null $maxDataRows, bool|int $collectData = false)

Read the data rows and process them.

$this
setReader(Reader $reader)

Set the CSV Reader instance.

Reader
getReader()

Get the CSV Reader instance.

$this
setCategory(CategoryInterface $category)

Set the attribute category to be used to export the data.

getCategory()

Get the attribute category to be used to export the data.

string[]|string[][]
getAttributesMap()

No description

array
getAttributeKeysAndControllers()

Get a list the attribute keys and controllers for the current category.

assignCsvAttributes(ObjectInterface $object, array $csvAttributes, ImportResult $importResult)

Set/update the object attributes with the data read from the CSV.

string|string[]
convertCsvDataForAttributeController(Controller $attributeController, string|array $csvData)

Convert the data read from CSV to be passed to the attribute controller.

Details

protected __construct(Reader $reader, CategoryInterface $category, Application $app)

Initialize the instance.

Parameters

Reader $reader

the CSV Reader instance

CategoryInterface $category

the attribute category

Application $app

ImportResult process(int $dataRowsToSkip = 0, int|null $maxDataRows = null, bool|int $collectData = false)

Process the CSV data.

Parameters

int $dataRowsToSkip

the number of data rows to be skipped

int|null $maxDataRows

the maximum number of data rows to be processed

bool|int $collectData

Set to false to not collect the imported data, to true to collect the all the imported data, or a number to limit the data to collect

Return Value

ImportResult

bool isDryRun()

Is the import process just a test?

Return Value

bool

$this setDryRun(bool $value)

Is the import process just a test?

Parameters

bool $value

Return Value

$this

abstract protected string[]|Generator getStaticHeaders()

Get the list of fixed headers.

Return Value

string[]|Generator

abstract protected ObjectInterface getObjectWithStaticValues(array $staticValues)

Get or create a ObjectInterface instance starting from its static values.

Parameters

array $staticValues

Return Value

ObjectInterface

Exceptions

UserMessageException

protected bool processHeader(ImportResult $importResult)

Read the header row and initialize the CSV schema.

Parameters

ImportResult $importResult

Return Value

bool

returns true in case of success, false in case of failures (see the getErrors() method of the result)

protected null|array processData(ImportResult $importResult, int $dataRowsToSkip, int|null $maxDataRows, bool|int $collectData = false)

Read the data rows and process them.

Parameters

ImportResult $importResult
int $dataRowsToSkip

the number of data rows to be skipped

int|null $maxDataRows

the maximum number of data rows to be processed

bool|int $collectData

Set to false to not collect the imported data, to true to collect the all the imported data, or a number to limit the data to collect

Return Value

null|array

If $collectData is set to true, the result will be an array with the keys:

  • attributeKeys: the list of attribute keys (\Concrete\Core\Attribute\AttributeKeyInterface[])
  • attributeControllers: the list of attribute key controllers (\Concrete\Core\Attribute\Controller[])
  • data: a list of array, whose keys are:
    • object: the object associated to the CSV data row (\Concrete\Core\Attribute\ObjectInterface)
    • attributeValues: the list of attribute values (array[\Concrete\Core\Entity\Attribute\Value\AbstractValue|null])

protected $this setReader(Reader $reader)

Set the CSV Reader instance.

Parameters

Reader $reader

Return Value

$this

protected Reader getReader()

Get the CSV Reader instance.

Return Value

Reader

protected $this setCategory(CategoryInterface $category)

Set the attribute category to be used to export the data.

Parameters

CategoryInterface $category

Return Value

$this

protected CategoryInterface getCategory()

Get the attribute category to be used to export the data.

Return Value

CategoryInterface

protected string[]|string[][] getAttributesMap()

No description

Return Value

string[]|string[][]

protected array getAttributeKeysAndControllers()

Get a list the attribute keys and controllers for the current category.

Return Value

array

private assignCsvAttributes(ObjectInterface $object, array $csvAttributes, ImportResult $importResult)

Set/update the object attributes with the data read from the CSV.

Parameters

ObjectInterface $object
array $csvAttributes
ImportResult $importResult

private string|string[] convertCsvDataForAttributeController(Controller $attributeController, string|array $csvData)

Convert the data read from CSV to be passed to the attribute controller.

Parameters

Controller $attributeController
string|array $csvData

Return Value

string|string[]