Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $lockMode parameter to EntityManager::refresh() #10196

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrade to 3.0

## BC BREAK: Changed `EntityManagerInterface#refresh($entity)`, `EntityManagerDecorator#refresh($entity)` and `UnitOfWork#refresh($entity)` signatures

The new signatures of these methods add an optional `LockMode|int|null $lockMode`
param with default `null` value (no lock).

## BC Break: Removed AnnotationDriver

The annotation driver and anything related to annotation has been removed.
Expand Down
11 changes: 1 addition & 10 deletions lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\ObjectManagerDecorator;

use function func_get_arg;
use function func_num_args;

/**
* Base class for EntityManager decorators
*
Expand Down Expand Up @@ -133,14 +130,8 @@ public function find(string $className, mixed $id, LockMode|int|null $lockMode =
return $this->wrapped->find($className, $id, $lockMode, $lockVersion);
}

public function refresh(object $object): void
public function refresh(object $object, LockMode|int|null $lockMode = null): void
{
$lockMode = null;

if (func_num_args() > 1) {
$lockMode = func_get_arg(1);
}

$this->wrapped->refresh($object, $lockMode);
}

Expand Down
10 changes: 0 additions & 10 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,16 +496,6 @@ public function remove(object $object): void
$this->unitOfWork->remove($object);
}

/**
* Refreshes the persistent state of an entity from the database,
* overriding any local changes that have not yet been persisted.
*
* @psalm-param LockMode::*|null $lockMode
*
* @throws ORMInvalidArgumentException
* @throws ORMException
* @throws TransactionRequiredException
*/
public function refresh(object $object, LockMode|int|null $lockMode = null): void
{
$this->errorIfClosed();
Expand Down
16 changes: 15 additions & 1 deletion lib/Doctrine/ORM/EntityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\Persistence\ObjectManager;

/** @method void refresh(object $object, LockMode|int|null $lockMode = null) */
interface EntityManagerInterface extends ObjectManager
{
/**
Expand Down Expand Up @@ -133,6 +132,21 @@ public function createQueryBuilder(): QueryBuilder;
*/
public function find(string $className, mixed $id, LockMode|int|null $lockMode = null, int|null $lockVersion = null): object|null;

/**
* Refreshes the persistent state of an object from the database,
* overriding any local changes that have not yet been persisted.
*
* @param LockMode|int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants
* or NULL if no specific lock mode should be used
* during the search.
* @psalm-param LockMode::*|null $lockMode
*
* @throws ORMInvalidArgumentException
* @throws ORMException
* @throws TransactionRequiredException
*/
public function refresh(object $object, LockMode|int|null $lockMode = null): void;

/**
* Gets a reference to the entity identified by the given type and identifier
* without actually loading it, if the entity is not yet loaded.
Expand Down
12 changes: 3 additions & 9 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
use function assert;
use function count;
use function current;
use function func_get_arg;
use function func_num_args;
use function get_debug_type;
use function implode;
use function in_array;
Expand Down Expand Up @@ -1790,19 +1788,15 @@ private function doDetach(
* Refreshes the state of the given entity from the database, overwriting
* any local, unpersisted changes.
*
* @psalm-param LockMode::*|null $lockMode
*
* @throws InvalidArgumentException If the entity is not MANAGED.
* @throws TransactionRequiredException
*/
public function refresh(object $entity): void
public function refresh(object $entity, LockMode|int|null $lockMode = null): void
{
$visited = [];

$lockMode = null;

if (func_num_args() > 1) {
$lockMode = func_get_arg(1);
}

$this->doRefresh($entity, $visited, $lockMode);
}

Expand Down
3 changes: 0 additions & 3 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@
<!-- Persistence 2 compatibility -->
<referencedFunction name="Doctrine\Persistence\ObjectManager::clear"/>

<!-- Remove on 3.0.x -->
<referencedFunction name="Doctrine\Persistence\ObjectManager::refresh"/>

<!-- See https://github.com/doctrine/orm/issues/8850 -->
<referencedFunction name="Doctrine\DBAL\Connection::lastInsertId"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public function detach(object $object): void
$this->realEntityManager->detach($object);
}

public function refresh(object $object): void
public function refresh(object $object, LockMode|int|null $lockMode = null): void
{
$this->realEntityManager->refresh($object);
$this->realEntityManager->refresh($object, $lockMode);
}
michnovka marked this conversation as resolved.
Show resolved Hide resolved

public function flush(): void
Expand Down