Skip to content

Commit

Permalink
Fix for #7068: EntityManager::find() with pessimistic lock should che…
Browse files Browse the repository at this point in the history
…ck for transaction
  • Loading branch information
Michael Kühn authored and guilhermeblanco committed Jun 11, 2019
1 parent 4f507d2 commit b0a39ec
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,4 +911,26 @@ private function checkLockRequirements(int $lockMode, ClassMetadata $class) : vo
}
}
}

/**
* @param int $lockMode
* @param ClassMetadata $class
* @throws OptimisticLockException
* @throws TransactionRequiredException
*/
private function checkLockRequirements(int $lockMode, ClassMetadata $class): void
{
switch ($lockMode) {
case LockMode::OPTIMISTIC:
if (!$class->isVersioned) {
throw OptimisticLockException::notVersioned($class->name);
}
// Intentional fallthrough
case LockMode::PESSIMISTIC_READ:
case LockMode::PESSIMISTIC_WRITE:
if (!$this->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired();
}
}
}
}

0 comments on commit b0a39ec

Please sign in to comment.