EntityManagerReopener
in package
Reopens a closed Doctrine EntityManager.
Doctrine ORM 3 has no reopen(): after a failed flush (UnitOfWork::commit() ends in
close()) the EntityManager stays closed and every later persist()/flush() in the same
process throws "The EntityManager is closed." (the next cron or import item, an order save
after a customer race). Reopening is safe only when the transaction is rolled back and the
UnitOfWork is empty, so TransactionManager calls
it after the outermost rollback, as do places that handle a flush failure themselves.
close() calls clear() but does not reset UnitOfWork::$persisters: the persister of an
entity whose INSERT failed keeps it in $queuedInserts, and the next flush would replay it
with an empty changeset (an INSERT of all nulls). The persisters are therefore dropped on
reopen and the UnitOfWork rebuilds them lazily.
NOTE: the reflection on closed, persisters and collectionPersisters depends on ORM
internals. TransactionSequencesTest covers it; on an ORM rename update this helper.
Table of Contents
Methods
- reopenIfClosed() : bool
Methods
reopenIfClosed()
public
static reopenIfClosed(EntityManagerInterface $em, string $logChannel) : bool
Parameters
- $em : EntityManagerInterface
- $logChannel : string
Return values
bool —true when the EntityManager is open (again)