function it_clears_the_import_cache(DoctrineCache $doctrineCache, EntityManager $entityManager, UnitOfWork $uow) { $this->setNonClearableEntities(['NonClearable']); $uow->getIdentityMap()->willReturn(['NonClearable' => [], 'Clearable' => []]); $entityManager->clear('Clearable')->shouldBeCalled(); $doctrineCache->clear(['NonClearable'])->shouldBeCalled(); $this->clear(); }
/** * Clear the Unit of Work of the manager(s) from the clearable entities * between batch writes * * @param bool $full True to clear all entities */ public function clear($full = false) { $nonClearableEntities = $full ? [] : $this->nonClearableEntities; foreach ($this->managerRegistry->getManagers() as $objectManager) { $identityMap = $objectManager->getUnitOfWork()->getIdentityMap(); $managedClasses = array_keys($identityMap); $nonClearableClasses = array_intersect($managedClasses, $nonClearableEntities); if (empty($nonClearableClasses)) { $objectManager->clear(); } else { $clearableClasses = array_diff($managedClasses, $nonClearableEntities); foreach ($clearableClasses as $clearableClass) { $objectManager->clear($clearableClass); } } } $this->doctrineCache->clear($nonClearableEntities); }
/** * {@inheritdoc} */ public function load($file) { $this->eventDispatcher->dispatch(static::EVENT_STARTED, new FixtureLoaderEvent($file)); $this->reader->setFilePath($file); if ($this->multiple) { $items = $this->reader->read(); foreach ($this->processor->process($items) as $object) { $this->persistObjects($object); } } else { while ($item = $this->reader->read()) { $this->persistObjects($this->processor->process($item)); } } $this->objectManager->flush(); $this->objectManager->clear(); $this->doctrineCache->clear(); $this->eventDispatcher->dispatch(static::EVENT_COMPLETED, new FixtureLoaderEvent($file)); }