I need to transform data from an old codebase to a new one. One Step is to split one NodeType into to others. I create the new node by calling
$newNode = $parent->createNode($nodeName, $this->nodeTypeManager->getNodeType(<NodeTypeName>));
After the migration states to have been run successfully i get the error
A new entity was found through the relationship ‘Neos\ContentRepository\Domain\Model\NodeData#workspace’ that was not configured to cascade persist operations for entity: Neos\Flow\Persistence\Doctrine\Proxies_CG_\Neos\ContentRepository\Domain\Model\Workspace@4816.
Explicitly calling EntityManager#persist() on the created nodes throws the exception
No class schema found for “Neos\ContentRepository\Domain\Model\Node”.
- What’s the proper way to create and persist child nodes?
- Could “broken” workspaces from the old DB make the Transformation fail? If so, is there a way to delete personal workspaces?
Kind regards!
Hello Runa,
Today I stumbled over the same behavior. I wanted to migrate a node with plenty of properties to a new structure of nodes. The migrations seem to run fine except for one issue for me (if I ignore the error
).
In other dimensions I can see the default and target dimension node for the new created nodes. Although I don’t see an issue in the database. The dimension values and so on seem to be fine. Wanted to post something here and then found your thread.
Did you find a solution back then?
For the translation issue, I could also reproduce similar behavior from the backend. Will try to reproduce that with the Neos.Demo, for instance, so that others hopefully can reproduce the issue.
Hello,
I spoke with @christianm, and I apologize for my mistake. I attempted to persist changes before completing the task. When we use the persistence manager for this purpose, all references cannot be reused afterward. Therefore, we need to retrieve the context again.
I’m not certain about the complete code for you, @RunaSchloer, but it might be helpful to others as well. For instance, when you use persistsAll, you should use $this->_contextFactory->reset() to get the context for the node once more.
For instance, with a function like that:
/**
* To have the correct references in the ORM we need to reset the context and get the node again.
* This is important after a persistsAll() call.
*
* @param NodeData $node
* @return NodeInterface
*/
protected function getNodeFromContext(NodeData $node): NodeInterface
{
$this->_contextFactory->reset();
$contentContext = $this->createContentContext($node->getWorkspace()->getName(), $node->getDimensionValues());
return $contentContext->getNodeByIdentifier($node->getIdentifier());
}