public function persistAll($onlyWhitelistedObjects = false)
{
if ($onlyWhitelistedObjects) {
$unitOfWork = $this->entityManager->getUnitOfWork();
/** @var \Doctrine\ORM\UnitOfWork $unitOfWork */
$unitOfWork->computeChangeSets();
$objectsToBePersisted = $unitOfWork->getScheduledEntityUpdates() + $unitOfWork->getScheduledEntityDeletions() + $unitOfWork->getScheduledEntityInsertions();
foreach ($objectsToBePersisted as $object) {
$this->throwExceptionIfObjectIsNotWhitelisted($object);
}
}
if (!$this->entityManager->isOpen()) {
$this->systemLogger->log('persistAll() skipped flushing data, the Doctrine EntityManager is closed. Check the logs for error message.', LOG_ERR);
return;
}
try {
$this->entityManager->flush();
} catch (Exception $exception) {
$this->systemLogger->logException($exception);
/** @var Connection $connection */
$connection = $this->entityManager->getConnection();
$connection->close();
$connection->connect();
$this->systemLogger->log('Reconnected the Doctrine EntityManager to the persistence backend.', LOG_INFO);
$this->entityManager->flush();
} finally {
$this->emitAllObjectsPersisted();
}
}