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(); }
/** * Creates a loader * * @param ObjectManager $objectManager * @param ReferenceRepository $referenceRepository * @param string $name * @param string $extension * * @return LoaderInterface */ public function create(ObjectManager $objectManager, ReferenceRepository $referenceRepository, $name, $extension) { $this->doctrineCache->setReferenceRepository($referenceRepository); $reader = $this->configRegistry->getReader($name, $extension); $processor = $this->configRegistry->getProcessor($name, $extension); $class = $this->configRegistry->getClass($name); $multiple = $this->configRegistry->isMultiple($name); return $this->createLoader($objectManager, $reader, $processor, $class, $multiple); }
/** * Sets the options of the attribute * * @param string $class * @param AttributeInterface $attribute * @param array $optionsData */ protected function setOptions($class, AttributeInterface $attribute, array $optionsData) { $this->doctrineCache->setReference($attribute); $optionClass = $this->optionManager->getAttributeOptionClass(); foreach ($optionsData as $code => $optionData) { $optionData['attribute'] = $attribute->getCode(); if (!isset($optionData['code'])) { $optionData['code'] = $code; } $option = $this->transformNestedEntity($class, 'options', $optionClass, $optionData); $attribute->addOption($option); $this->doctrineCache->setReference($option); } }
/** * Sets the parents and recursively removes categories with bad parents * * @param array &$categories * @param array $parents * @param array $items */ protected function setParents(array &$categories, array $parents, array $items) { $invalidCodes = []; foreach ($categories as $code => $category) { $parentCode = $parents[$code]; if (!$parentCode) { continue; } if (isset($categories[$parentCode])) { $parent = $categories[$parentCode]; } else { $parent = $this->doctrineCache->find($this->class, $parentCode); } if ($parent) { $category->setParent($parent); } else { $invalidCodes[] = $code; } } if (count($invalidCodes)) { foreach ($invalidCodes as $code) { $this->setItemErrors($items[$code], ['parent' => [['No category with code %code%', ['%code%' => $parents[$code]]]]]); unset($categories[$code]); } $this->setParents($categories, $parents, $items); } }
/** * Persists an object * * @param object $object */ protected function persistObject($object) { if ($object instanceof \Pim\Bundle\CatalogBundle\Model\ProductInterface) { $this->mediaManager->handleProductMedias($object); } $this->objectManager->persist($object); $this->doctrineCache->setReference($object); }
/** * 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); }
/** * Persists an object * * @param object $object */ protected function persistObject($object) { //TODO: make this work without the media manager if ($object instanceof \Pim\Component\Catalog\Model\ProductInterface) { $this->mediaManager->handleProductMedias($object); } $this->objectManager->persist($object); $this->doctrineCache->setReference($object); }
/** * Finds the object in the cache * * @param string $class * @param string $value * * @return object */ protected function findObject($class, $value) { return $this->doctrineCache->find($class, $value); }