Skip to content

Commit

Permalink
Add deprecation message for EM#clear($entityName)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcobucci committed Nov 19, 2019
1 parent 8332fa1 commit 9ccb883
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ restful operations, you should look at alternatives such as [JMSSerializer](http
Final keyword will be added to the `EntityManager::class` in Doctrine 3.0 in order to ensure that EntityManager
is not used as valid extension point. Valid extension point should be EntityManagerInterface.

## Deprecated `EntityManager#clear($entityName)`

If your code relies on clearing a single entity type via `EntityManager#clear($entityName)`,
the signature has been changed to `EntityManager#clear()`.

The main reason is that partial clears caused multiple issues with data integrity
in the managed entity graph, which was constantly spawning more edge-case bugs/scenarios.

## Deprecated `EntityManager#flush($entity)` and `EntityManager#flush($entities)`

If your code relies on single entity flushing optimisations via
Expand Down
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Doctrine\ORM\Query\FilterCollection;
use Doctrine\Common\Util\ClassUtils;
use Throwable;
use const E_USER_DEPRECATED;
use function trigger_error;

/**
Expand Down Expand Up @@ -555,6 +556,13 @@ public function clear($entityName = null)
throw ORMInvalidArgumentException::invalidEntityName($entityName);
}

if ($entityName !== null) {
@trigger_error(
'Calling ' . __METHOD__ . '() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine 3.0.',
E_USER_DEPRECATED
);
}

$this->unitOfWork->clear(
null === $entityName
? null
Expand Down
9 changes: 9 additions & 0 deletions tests/Doctrine/Tests/ORM/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ public function testClearManagerWithNullValue()
$this->assertFalse($this->_em->contains($entity));
}

public function testDeprecatedClearWithArguments() : void
{
$entity = new Country(456, 'United Kingdom');
$this->_em->persist($entity);

$this->expectDeprecationMessage('Calling Doctrine\ORM\EntityManager::clear() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine 3.0.');
$this->_em->clear(Country::class);
}

public function testDeprecatedFlushWithArguments() : void
{
$entity = new Country(456, 'United Kingdom');
Expand Down

0 comments on commit 9ccb883

Please sign in to comment.