/** * Commits new objects and changes to objects in the current persistence * session into the backend * * @param boolean $onlyWhitelistedObjects If TRUE an exception will be thrown if there are scheduled updates/deletes or insertions for objects that are not "whitelisted" (see AbstractPersistenceManager::whitelistObject()) * @return void * @api */ 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(); } }
/** * Commits new objects and changes to objects in the current persistence * session into the backend * * @return void * @api */ public function persistAll() { if ($this->entityManager->isOpen()) { $this->entityManager->flush(); $this->emitAllObjectsPersisted(); } else { $this->systemLogger->log('persistAll() skipped flushing data, the Doctrine EntityManager is closed. Check the logs for error message.', LOG_ERR); } }
/** * Return a Doctrine ObjectManager * * @return ObjectManager */ public function getObjectManager() { // Check if Object Manager is open // If it's closed, usually this means there has been an error if ($this->objectManager === null || method_exists($this->objectManager, 'isOpen') && !$this->objectManager->isOpen()) { // We want to recover and create a new instance of the Document manager $this->setObjectManager($this->getObjectManagerFromFactory()); // But we should also create an error in the log // @TODO Log Object Manager was closed error } return $this->objectManager; }
/** * Commits new objects and changes to objects in the current persistence * session into the backend * * @param boolean $onlyWhitelistedObjects * @return void * @api */ public function persistAll($onlyWhitelistedObjects = FALSE) { if ($onlyWhitelistedObjects) { $unitOfWork = $this->entityManager->getUnitOfWork(); /** @var \Doctrine\ORM\UnitOfWork $unitOfWork */ $objectsToBePersisted = $unitOfWork->getScheduledEntityUpdates() + $unitOfWork->getScheduledEntityDeletions() + $unitOfWork->getScheduledEntityInsertions(); foreach ($objectsToBePersisted as $object) { $this->throwExceptionIfObjectIsNotWhitelisted($object); } } if ($this->entityManager->isOpen()) { $this->entityManager->flush(); $this->emitAllObjectsPersisted(); } else { $this->systemLogger->log('persistAll() skipped flushing data, the Doctrine EntityManager is closed. Check the logs for error message.', LOG_ERR); } }