From 925631878f7f69abe78b5a221b2c0c686623f25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 7 Oct 2023 11:46:19 +0200 Subject: [PATCH] Remove CommitOrderCalculator and related classes They are unused, and since they are internal, it should be fine to remove them without a deprecation. --- UPGRADE.md | 7 - .../ORM/Internal/CommitOrder/Edge.php | 46 ----- .../ORM/Internal/CommitOrder/Vertex.php | 49 ----- .../ORM/Internal/CommitOrder/VertexState.php | 28 --- .../ORM/Internal/CommitOrderCalculator.php | 177 ------------------ lib/Doctrine/ORM/UnitOfWork.php | 15 +- psalm-baseline.xml | 6 - psalm.xml | 4 - .../Tests/ORM/CommitOrderCalculatorTest.php | 122 ------------ 9 files changed, 2 insertions(+), 452 deletions(-) delete mode 100644 lib/Doctrine/ORM/Internal/CommitOrder/Edge.php delete mode 100644 lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php delete mode 100644 lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php delete mode 100644 lib/Doctrine/ORM/Internal/CommitOrderCalculator.php delete mode 100644 tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php diff --git a/UPGRADE.md b/UPGRADE.md index db6a80bf248..593739fa2bd 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -33,13 +33,6 @@ avoided. When using database-provided, auto-incrementing IDs, this may lead to IDs being assigned to entities in a different order than it was previously the case. -## Deprecated `\Doctrine\ORM\Internal\CommitOrderCalculator` and related classes - -With changes made to the commit order computation, the internal classes -`\Doctrine\ORM\Internal\CommitOrderCalculator`, `\Doctrine\ORM\Internal\CommitOrder\Edge`, -`\Doctrine\ORM\Internal\CommitOrder\Vertex` and `\Doctrine\ORM\Internal\CommitOrder\VertexState` -have been deprecated and will be removed in ORM 3.0. - ## Deprecated returning post insert IDs from `EntityPersister::executeInserts()` Persisters implementing `\Doctrine\ORM\Persisters\Entity\EntityPersister` should no longer diff --git a/lib/Doctrine/ORM/Internal/CommitOrder/Edge.php b/lib/Doctrine/ORM/Internal/CommitOrder/Edge.php deleted file mode 100644 index 98bb7378955..00000000000 --- a/lib/Doctrine/ORM/Internal/CommitOrder/Edge.php +++ /dev/null @@ -1,46 +0,0 @@ -from = $from; - $this->to = $to; - $this->weight = $weight; - } -} diff --git a/lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php b/lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php deleted file mode 100644 index c748bd7eab0..00000000000 --- a/lib/Doctrine/ORM/Internal/CommitOrder/Vertex.php +++ /dev/null @@ -1,49 +0,0 @@ - */ - public $dependencyList = []; - - public function __construct(string $hash, ClassMetadata $value) - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/orm', - 'https://github.com/doctrine/orm/pull/10547', - 'The %s class is deprecated and will be removed in ORM 3.0', - self::class - ); - - $this->hash = $hash; - $this->value = $value; - } -} diff --git a/lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php b/lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php deleted file mode 100644 index 24d2fb54ee1..00000000000 --- a/lib/Doctrine/ORM/Internal/CommitOrder/VertexState.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ - private $nodeList = []; - - /** - * Volatile variable holding calculated nodes during sorting process. - * - * @psalm-var list - */ - private $sortedNodeList = []; - - public function __construct() - { - Deprecation::triggerIfCalledFromOutside( - 'doctrine/orm', - 'https://github.com/doctrine/orm/pull/10547', - 'The %s class is deprecated and will be removed in ORM 3.0', - self::class - ); - } - - /** - * Checks for node (vertex) existence in graph. - * - * @param string $hash - * - * @return bool - */ - public function hasNode($hash) - { - return isset($this->nodeList[$hash]); - } - - /** - * Adds a new node (vertex) to the graph, assigning its hash and value. - * - * @param string $hash - * @param ClassMetadata $node - * - * @return void - */ - public function addNode($hash, $node) - { - $this->nodeList[$hash] = new Vertex($hash, $node); - } - - /** - * Adds a new dependency (edge) to the graph using their hashes. - * - * @param string $fromHash - * @param string $toHash - * @param int $weight - * - * @return void - */ - public function addDependency($fromHash, $toHash, $weight) - { - $this->nodeList[$fromHash]->dependencyList[$toHash] - = new Edge($fromHash, $toHash, $weight); - } - - /** - * Return a valid order list of all current nodes. - * The desired topological sorting is the reverse post order of these searches. - * - * {@internal Highly performance-sensitive method.} - * - * @psalm-return list - */ - public function sort() - { - foreach ($this->nodeList as $vertex) { - if ($vertex->state !== VertexState::NOT_VISITED) { - continue; - } - - $this->visit($vertex); - } - - $sortedList = $this->sortedNodeList; - - $this->nodeList = []; - $this->sortedNodeList = []; - - return array_reverse($sortedList); - } - - /** - * Visit a given node definition for reordering. - * - * {@internal Highly performance-sensitive method.} - */ - private function visit(Vertex $vertex): void - { - $vertex->state = VertexState::IN_PROGRESS; - - foreach ($vertex->dependencyList as $edge) { - $adjacentVertex = $this->nodeList[$edge->to]; - - switch ($adjacentVertex->state) { - case VertexState::VISITED: - // Do nothing, since node was already visited - break; - - case VertexState::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 === VertexState::NOT_VISITED) { - $this->visit($adjacentEdgeVertex); - } - } - - $adjacentVertex->state = VertexState::VISITED; - - $this->sortedNodeList[] = $adjacentVertex->value; - } - - break; - - case VertexState::NOT_VISITED: - $this->visit($adjacentVertex); - } - } - - if ($vertex->state !== VertexState::VISITED) { - $vertex->state = VertexState::VISITED; - - $this->sortedNodeList[] = $vertex->value; - } - } -} diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index dd0150a5afd..607957a48f6 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -27,7 +27,6 @@ use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\Exception\UnexpectedAssociationValue; use Doctrine\ORM\Id\AssignedGenerator; -use Doctrine\ORM\Internal\CommitOrderCalculator; use Doctrine\ORM\Internal\HydrationCompleteHandler; use Doctrine\ORM\Internal\TopologicalSort; use Doctrine\ORM\Mapping\ClassMetadata; @@ -1682,11 +1681,11 @@ public function addToIdentityMap($entity) clearing the EntityManager; - you might have been using EntityManager#getReference() to create a reference for a nonexistent ID that was subsequently (by the RDBMS) assigned to another -entity. +entity. Otherwise, it might be an ORM-internal inconsistency, please report it. -To opt-in to the new exception, call +To opt-in to the new exception, call \Doctrine\ORM\Configuration::setRejectIdCollisionInIdentityMap on the entity manager's configuration. EXCEPTION @@ -2721,16 +2720,6 @@ public function lock($entity, int $lockMode, $lockVersion = null): void } } - /** - * Gets the CommitOrderCalculator used by the UnitOfWork to order commits. - * - * @return CommitOrderCalculator - */ - public function getCommitOrderCalculator() - { - return new Internal\CommitOrderCalculator(); - } - /** * Clears the UnitOfWork. * diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 958283bf003..1e43faeba9e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -400,12 +400,6 @@ getTableHiLoUpdateNextValSql - - - state !== VertexState::VISITED]]> - state !== VertexState::VISITED]]> - - IterableResult diff --git a/psalm.xml b/psalm.xml index 1e083bafc2d..56c364634a4 100644 --- a/psalm.xml +++ b/psalm.xml @@ -45,10 +45,6 @@ - - - - diff --git a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php b/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php deleted file mode 100644 index a9d3004683a..00000000000 --- a/tests/Doctrine/Tests/ORM/CommitOrderCalculatorTest.php +++ /dev/null @@ -1,122 +0,0 @@ -_calc = new CommitOrderCalculator(); - } - - public function testCommitOrdering1(): void - { - $class1 = new ClassMetadata(NodeClass1::class); - $class2 = new ClassMetadata(NodeClass2::class); - $class3 = new ClassMetadata(NodeClass3::class); - $class4 = new ClassMetadata(NodeClass4::class); - $class5 = new ClassMetadata(NodeClass5::class); - - $this->_calc->addNode($class1->name, $class1); - $this->_calc->addNode($class2->name, $class2); - $this->_calc->addNode($class3->name, $class3); - $this->_calc->addNode($class4->name, $class4); - $this->_calc->addNode($class5->name, $class5); - - $this->_calc->addDependency($class1->name, $class2->name, 1); - $this->_calc->addDependency($class2->name, $class3->name, 1); - $this->_calc->addDependency($class3->name, $class4->name, 1); - $this->_calc->addDependency($class5->name, $class1->name, 1); - - $sorted = $this->_calc->sort(); - - // There is only 1 valid ordering for this constellation - $correctOrder = [$class5, $class1, $class2, $class3, $class4]; - - self::assertSame($correctOrder, $sorted); - } - - public function testCommitOrdering2(): void - { - $class1 = new ClassMetadata(NodeClass1::class); - $class2 = new ClassMetadata(NodeClass2::class); - - $this->_calc->addNode($class1->name, $class1); - $this->_calc->addNode($class2->name, $class2); - - $this->_calc->addDependency($class1->name, $class2->name, 0); - $this->_calc->addDependency($class2->name, $class1->name, 1); - - $sorted = $this->_calc->sort(); - - // There is only 1 valid ordering for this constellation - $correctOrder = [$class2, $class1]; - - self::assertSame($correctOrder, $sorted); - } - - public function testCommitOrdering3(): void - { - // this test corresponds to the GH7259Test::testPersistFileBeforeVersion functional test - $class1 = new ClassMetadata(NodeClass1::class); - $class2 = new ClassMetadata(NodeClass2::class); - $class3 = new ClassMetadata(NodeClass3::class); - $class4 = new ClassMetadata(NodeClass4::class); - - $this->_calc->addNode($class1->name, $class1); - $this->_calc->addNode($class2->name, $class2); - $this->_calc->addNode($class3->name, $class3); - $this->_calc->addNode($class4->name, $class4); - - $this->_calc->addDependency($class4->name, $class1->name, 1); - $this->_calc->addDependency($class1->name, $class2->name, 1); - $this->_calc->addDependency($class4->name, $class3->name, 1); - $this->_calc->addDependency($class1->name, $class4->name, 0); - - $sorted = $this->_calc->sort(); - - // There is only multiple valid ordering for this constellation, but - // the class4, class1, class2 ordering is important to break the cycle - // on the nullable link. - $correctOrders = [ - [$class4, $class1, $class2, $class3], - [$class4, $class1, $class3, $class2], - [$class4, $class3, $class1, $class2], - ]; - - // We want to perform a strict comparison of the array - self::assertContains($sorted, $correctOrders, '', false, true); - } -} - -class NodeClass1 -{ -} -class NodeClass2 -{ -} -class NodeClass3 -{ -} -class NodeClass4 -{ -} -class NodeClass5 -{ -}