Skip to content

Commit

Permalink
Ensure the node is persisted before inserting closure
Browse files Browse the repository at this point in the history
  • Loading branch information
JDruery committed Aug 14, 2023
1 parent 4891f06 commit 5b79ec1
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Tree/Strategy/ORM/Closure.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,24 +271,21 @@ public function processPostPersist($em, $entity, AdapterInterface $ea)
{
$uow = $em->getUnitOfWork();
$emHash = spl_object_id($em);
$entityClass = get_class($entity);

foreach ($this->pendingChildNodeInserts[$emHash] as $node) {
$nodeClass = get_class($node);
if ($entityClass !== $nodeClass) {
// Do not update if this node is a different type of entity from what has been persisted
// otherwise it's not guaranteed that the node has actually been persisted
$meta = $em->getClassMetadata(get_class($node));
$identifier = $meta->getSingleIdentifierFieldName();
$nodeId = $meta->getReflectionProperty($identifier)->getValue($node);

if (is_null($nodeId)) {
// Do not update if the node has not been persisted yet
continue;
}

// The closure for this node will now be inserted. Remove the node from the list of pending inserts to indicate this.
unset($this->pendingChildNodeInserts[$emHash][spl_object_id($node)]);

$meta = $em->getClassMetadata(get_class($node));
$config = $this->listener->getConfiguration($em, $meta->getName());

$identifier = $meta->getSingleIdentifierFieldName();
$nodeId = $meta->getReflectionProperty($identifier)->getValue($node);
$parent = $meta->getReflectionProperty($config['parent'])->getValue($node);

$closureClass = $config['closure'];
Expand Down

0 comments on commit 5b79ec1

Please sign in to comment.