Skip to content

Commit

Permalink
Fix TransactionRequiredException for pessimistic lock
Browse files Browse the repository at this point in the history
  • Loading branch information
michnovka committed Sep 11, 2022
1 parent e836f50 commit 3da2eef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ public function remove($entity)
*
* @throws ORMInvalidArgumentException
* @throws ORMException
* @throws TransactionRequiredException
*/
public function refresh($entity, $lockMode = null)
{
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,7 @@ private function doDetach(
* @return void
*
* @throws InvalidArgumentException If the entity is not MANAGED.
* @throws TransactionRequiredException
*/
public function refresh($entity, $lockMode = null)
{
Expand All @@ -2204,9 +2205,18 @@ public function refresh($entity, $lockMode = null)
* @psalm-param LockMode::*|null $lockMode
*
* @throws ORMInvalidArgumentException If the entity is not MANAGED.
* @throws TransactionRequiredException
*/
private function doRefresh($entity, array &$visited, $lockMode = null): void
{
switch(true) {
case $lockMode === LockMode::PESSIMISTIC_READ:
case $lockMode === LockMode::PESSIMISTIC_WRITE:
if (! $this->em->getConnection()->isTransactionActive()) {
throw TransactionRequiredException::transactionRequired();
}
}

$oid = spl_object_id($entity);

if (isset($visited[$oid])) {
Expand Down

0 comments on commit 3da2eef

Please sign in to comment.