class NodeImportService (View source)

Service for importing nodes from an XML structure into the content repository

Internally, uses associative arrays instead of Domain Models for performance reasons, so "nodeData" in this class is always an associative array.

Constants

SUPPORTED_FORMAT_VERSION

Properties

protected PersistenceManagerInterface $persistenceManager
protected PropertyMapper $propertyMapper
protected EntityManagerInterface $entityManager

Doctrine's Entity Manager.

protected Context $securityContext
protected ImportExportPropertyMappingConfiguration $propertyMappingConfiguration
protected array $nodeDataStack
protected array $nodeIdentifierStack
protected array $nodeNameStack
protected array $nodeDataPropertyNames

the list of property names of NodeData. These are the keys inside the nodeData array which is built as intermediate representation while parsing the XML.

Methods

void
import(XMLReader $xmlReader, string $targetPath, string $resourceLoadPath = null)

Imports the sub-tree from the xml reader into the given target path.

null|string
determineFormatVersion(XMLReader $xmlReader)

Determines the ContentRepository format version of the given xml

void
importSubtree(XMLReader $xmlReader)

Imports the sub-tree from the xml reader into the given target path.

void
parseElement(XMLReader $xmlReader)

Parses the given XML element and adds its content to the internal content tree

array
parseDimensionsElement(XMLReader $reader)

Parses the content of the dimensions-tag and returns the dimensions as an array 'dimension name' => dimension value

array|null
parseArrayElements(XMLReader $reader, string $elementName, string $currentNodeIdentifier)

Parses the content of exported array and returns the values

array
parsePropertiesElement(XMLReader $reader, string $currentNodeIdentifier)

Parses the content of the properties-tag and returns the properties as an array 'property name' => property value

mixed
convertElementToValue(XMLReader $reader, string $currentType, string $currentEncoding, string $currentClassName, string $currentNodeIdentifier, string $currentProperty)

Convert an element to the value it represents.

void
persistEntities(mixed $propertyValue)

Checks if a propertyValue contains an entity and persists it.

void
parseEndElement(XMLReader $reader)

Parses the closing tags writes data to the database then

string
getCurrentPath()

Provides the path for a NodeData according to the current stacks

string
getParentPath(string $path)

Provides the parent of the given path

void
persistNodeData(array $nodeData)

Saves the given array as a node data entity without using the ORM.

Details

void import(XMLReader $xmlReader, string $targetPath, string $resourceLoadPath = null)

Imports the sub-tree from the xml reader into the given target path.

The root node of the imported tree becomes a child of the node specified as the target path, as the following example illustrates:

  1. Existing Nodes Before Import:

    path

    • to
      • my
        • targetNode
          • A
    • other
      • nodes
  2. Sub-tree in xml to import to 'path/to/my/targetNode':

  3. existing nodes after the import:

    path

    • to
      • my
        • targetNode
          • A
          • B
            • B1
    • another
      • sub-tree

Parameters

XMLReader $xmlReader

The XML input to import - must be either XML as a string or a prepared \XMLReader instance containing XML data

string $targetPath

path to the node which becomes parent of the root of the imported sub-tree

string $resourceLoadPath

Return Value

void

Exceptions

ImportException

protected null|string determineFormatVersion(XMLReader $xmlReader)

Determines the ContentRepository format version of the given xml

Parameters

XMLReader $xmlReader

Return Value

null|string

the version as a string or null if the version could not be determined

protected void importSubtree(XMLReader $xmlReader)

Imports the sub-tree from the xml reader into the given target path.

The root node of the imported tree becomes a child of the node specified by target path.

This parser uses the depth-first reading strategy, which means it will read the input from top til bottom.

Parameters

XMLReader $xmlReader

A prepared XML Reader with the structure to import

Return Value

void

protected void parseElement(XMLReader $xmlReader)

Parses the given XML element and adds its content to the internal content tree

Parameters

XMLReader $xmlReader

The XML Reader with the element to be parsed as its root

Return Value

void

Exceptions

ImportException

protected array parseDimensionsElement(XMLReader $reader)

Parses the content of the dimensions-tag and returns the dimensions as an array 'dimension name' => dimension value

Parameters

XMLReader $reader

reader positioned just after an opening dimensions-tag

Return Value

array

the dimension values

protected array|null parseArrayElements(XMLReader $reader, string $elementName, string $currentNodeIdentifier)

Parses the content of exported array and returns the values

Parameters

XMLReader $reader

reader positioned just after an opening array-tag

string $elementName
string $currentNodeIdentifier

Return Value

array|null

the array values

protected array parsePropertiesElement(XMLReader $reader, string $currentNodeIdentifier)

Parses the content of the properties-tag and returns the properties as an array 'property name' => property value

Parameters

XMLReader $reader

reader positioned just after an opening properties-tag

string $currentNodeIdentifier

Return Value

array

the properties

protected mixed convertElementToValue(XMLReader $reader, string $currentType, string $currentEncoding, string $currentClassName, string $currentNodeIdentifier, string $currentProperty)

Convert an element to the value it represents.

Parameters

XMLReader $reader
string $currentType

current element (userland) type

string $currentEncoding

date encoding of element

string $currentClassName

class name of element

string $currentNodeIdentifier

identifier of the node

string $currentProperty

current property name

Return Value

mixed

Exceptions

ImportException

protected void persistEntities(mixed $propertyValue)

Checks if a propertyValue contains an entity and persists it.

Parameters

mixed $propertyValue

Return Value

void

protected void parseEndElement(XMLReader $reader)

Parses the closing tags writes data to the database then

Parameters

XMLReader $reader

Return Value

void

Exceptions

ImportException

protected string getCurrentPath()

Provides the path for a NodeData according to the current stacks

Return Value

string

protected string getParentPath(string $path)

Provides the parent of the given path

Parameters

string $path

path to get parent for

Return Value

string

parent path

protected void persistNodeData(array $nodeData)

Saves the given array as a node data entity without using the ORM.

If the node data already exists (same dimensions, same identifier, same workspace) it is replaced.

Parameters

array $nodeData

node data to save as an associative array ( $column_name => $value )

Return Value

void

Exceptions

ImportException