コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function save($product, array $options = [])
 {
     if (!$product instanceof ProductInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a Pim\\Bundle\\CatalogBundle\\Model\\ProductInterface, "%s" provided', ClassUtils::getClass($product)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($product);
     if (true === $options['schedule'] || true === $options['recalculate']) {
         $this->completenessManager->schedule($product);
     }
     if (true === $options['recalculate'] || true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (true === $options['recalculate']) {
         $this->completenessManager->generateMissingForProduct($product);
     }
 }
コード例 #2
0
 function it_does_not_flush_object_manager_when_persisting(ManagerRegistry $registry, ObjectManager $objectManager, CompletenessManager $completenessManager, ProductInterface $product)
 {
     $registry->getManagerForClass(get_class($product->getWrappedObject()))->willReturn($objectManager);
     $objectManager->persist($product)->shouldBeCalled();
     $objectManager->flush()->shouldNotBeCalled();
     $completenessManager->schedule($product)->shouldBeCalled();
     $completenessManager->generateMissingForProduct($product)->shouldNotBeCalled();
     $this->persist($product, ['recalculate' => false, 'flush' => false, 'schedule' => true]);
 }