From 568c2d308c850d36fd330dbb14cd52e799f9125b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 20 Sep 2018 12:13:25 +0200 Subject: [PATCH] Fix the computation of commit order for circular dependencies When finding a circular dependencies, we must ensure that all dependencies of a node have been visited before adding it to the sorted list. --- lib/Doctrine/ORM/Internal/CommitOrderCalculator.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php index 34703c6d2..30b9caa82 100644 --- a/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php +++ b/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php @@ -164,6 +164,17 @@ class CommitOrderCalculator case self::IN_PROGRESS: if (isset($adjacentVertex->dependencyList[$vertex->hash]) && $adjacentVertex->dependencyList[$vertex->hash]->weight < $edge->weight) { + + // If we have some non-visited dependencies in the in-progress dependency, we + // need to visit them before adding the node. + foreach ($adjacentVertex->dependencyList as $adjacentEdge) { + $adjacentEdgeVertex = $this->nodeList[$adjacentEdge->to]; + + if ($adjacentEdgeVertex->state === self::NOT_VISITED) { + $this->visit($adjacentEdgeVertex); + } + } + $adjacentVertex->state = self::VISITED; $this->sortedNodeList[] = $adjacentVertex->value;