/**
* 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.
*
* @param array $nodeData node data to save as an associative array ( $column_name => $value )
* @throws ImportException
* @return void
*/
protected function persistNodeData($nodeData)
{
if ($nodeData['workspace'] !== 'live') {
throw new ImportException('Saving NodeData with workspace != "live" using direct SQL not supported yet. Workspace is "' . $nodeData['workspace'] . '".');
}
if ($nodeData['path'] === '/') {
return;
}
// cleanup old data
/** @var Connection $connection */
$connection = $this->entityManager->getConnection();
// prepare node dimensions
$dimensionValues = $nodeData['dimensionValues'];
$dimensionsHash = Utility::sortDimensionValueArrayAndReturnDimensionsHash($dimensionValues);
$jsonPropertiesDataTypeHandler = JsonArrayType::getType(JsonArrayType::FLOW_JSON_ARRAY);
// post-process node data
$nodeData['dimensionsHash'] = $dimensionsHash;
$nodeData['dimensionValues'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($dimensionValues, $connection->getDatabasePlatform());
$nodeData['properties'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($nodeData['properties'], $connection->getDatabasePlatform());
$nodeData['accessRoles'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($nodeData['accessRoles'], $connection->getDatabasePlatform());
$connection->executeQuery('DELETE FROM neos_contentrepository_domain_model_nodedimension' . ' WHERE nodedata IN (' . ' SELECT persistence_object_identifier FROM neos_contentrepository_domain_model_nodedata' . ' WHERE identifier = :identifier' . ' AND workspace = :workspace' . ' AND dimensionshash = :dimensionsHash' . ' )', array('identifier' => $nodeData['identifier'], 'workspace' => $nodeData['workspace'], 'dimensionsHash' => $nodeData['dimensionsHash']));
/** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->delete()->from(NodeData::class, 'n')->where('n.identifier = :identifier')->andWhere('n.dimensionsHash = :dimensionsHash')->andWhere('n.workspace = :workspace')->setParameter('identifier', $nodeData['identifier'])->setParameter('workspace', $nodeData['workspace'])->setParameter('dimensionsHash', $nodeData['dimensionsHash']);
$queryBuilder->getQuery()->execute();
// insert new data
// we need to use executeUpdate to execute the INSERT -- else the data types are not taken into account.
// That's why we build a DQL INSERT statement which is then executed.
$queryParts = array();
$queryArguments = array();
$queryTypes = array();
foreach ($this->nodeDataPropertyNames as $propertyName => $propertyConfig) {
if (isset($nodeData[$propertyName])) {
$queryParts[$propertyName] = ':' . $propertyName;
$queryArguments[$propertyName] = $nodeData[$propertyName];
if (isset($propertyConfig['columnType'])) {
$queryTypes[$propertyName] = $propertyConfig['columnType'];
}
}
}
$connection->executeUpdate('INSERT INTO neos_contentrepository_domain_model_nodedata (' . implode(', ', array_keys($queryParts)) . ') VALUES (' . implode(', ', $queryParts) . ')', $queryArguments, $queryTypes);
foreach ($dimensionValues as $dimension => $values) {
foreach ($values as $value) {
$nodeDimension = array('persistence_object_identifier' => Algorithms::generateUUID(), 'nodedata' => $nodeData['Persistence_Object_Identifier'], 'name' => $dimension, 'value' => $value);
$connection->insert('neos_contentrepository_domain_model_nodedimension', $nodeDimension);
}
}
}