/**
  * Displays completeness for a product
  *
  * @param int $id
  *
  * @return Response
  */
 public function completenessAction($id)
 {
     $product = $this->productManager->getProductRepository()->getFullProduct($id);
     $channels = $this->channelManager->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $locales, $this->userContext->getCurrentLocale()->getCode());
     return $this->templating->renderResponse('PimEnrichBundle:Completeness:_completeness.html.twig', array('product' => $product, 'channels' => $channels, 'locales' => $locales, 'completenesses' => $completenesses));
 }
 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]);
 }
 /**
  * Call when form is valid
  * @param Channel $channel
  */
 protected function onSuccess(Channel $channel)
 {
     $this->manager->persist($channel);
     $this->completenessManager->scheduleForChannel($channel);
     foreach ($channel->getLocales() as $locale) {
         $this->manager->persist($locale);
     }
     $this->manager->flush();
 }
 /**
  * Get completeness for a product
  *
  * @param int $id
  *
  * @return JSONResponse
  */
 public function getAction($id)
 {
     $product = $this->productRepository->getFullProduct($id);
     $this->completenessManager->generateMissingForProduct($product);
     $channels = $this->channelRepository->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view');
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales, $this->userContext->getCurrentLocale()->getCode());
     return new JsonResponse($this->completenessNormalizer->normalize($completenesses, 'internal_api'));
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function save($channel, array $options = [])
 {
     if (!$channel instanceof ChannelInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\ChannelInterface", "%s" provided.', get_class($channel)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($channel);
     if (true === $options['schedule']) {
         $this->completenessManager->scheduleForChannel($channel);
     }
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function save($family, array $options = [])
 {
     if (!$family instanceof FamilyInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Bundle\\CatalogBundle\\Model\\FamilyInterface", "%s" provided.', ClassUtils::getClass($family)));
     }
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($family);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (true === $options['schedule']) {
         $this->completenessManager->scheduleForFamily($family);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $this->documentManager->clear();
     if (!$this->executed) {
         $this->executed = true;
         if (!is_object($this->channel)) {
             $this->channel = $this->channelManager->getChannelByCode($this->channel);
         }
         if ($this->missingCompleteness) {
             $this->completenessManager->generateMissingForChannel($this->channel);
         }
         $this->query = $this->repository->buildByChannelAndCompleteness($this->channel)->getQuery();
         $this->products = $this->getQuery()->execute();
         // MongoDB Cursor are not positioned on first element (whereas ArrayIterator is)
         // as long as getNext() hasn't be called
         $this->products->getNext();
     }
     $result = $this->products->current();
     if ($result) {
         $this->metricConverter->convert($result, $this->channel);
         $this->stepExecution->incrementSummaryInfo('read');
         $this->products->next();
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function save($family, array $options = [])
 {
     if (!$family instanceof FamilyInterface) {
         throw new \InvalidArgumentException(sprintf('Expects a "Pim\\Component\\Catalog\\Model\\FamilyInterface", "%s" provided.', ClassUtils::getClass($family)));
     }
     $this->eventDispatcher->dispatch(StorageEvents::PRE_SAVE, new GenericEvent($family));
     $options = $this->optionsResolver->resolveSaveOptions($options);
     $this->objectManager->persist($family);
     if (true === $options['flush']) {
         $this->objectManager->flush();
     }
     if (true === $options['schedule']) {
         $this->completenessManager->scheduleForFamily($family);
     }
     $this->eventDispatcher->dispatch(StorageEvents::POST_SAVE, new GenericEvent($family));
 }
예제 #9
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);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (!$this->query) {
         $code = $this->channel;
         if (!is_object($this->channel)) {
             $this->channel = $this->channelManager->getChannelByCode($this->channel);
         }
         if (!$this->channel) {
             throw new \InvalidArgumentException(sprintf('Could not find the channel "%s"', $code));
         }
         $this->completenessManager->generateMissingForChannel($this->channel);
         $this->query = $this->repository->buildByChannelAndCompleteness($this->channel)->getQuery();
     }
     $product = parent::read();
     if ($product) {
         $this->metricConverter->convert($product, $this->channel);
     }
     return $product;
 }
 /**
  * {@inheritdoc}
  */
 public function initialize()
 {
     $this->products = null;
     $channel = $this->channelManager->getChannelByCode($this->channel);
     $pqb = $this->pqbFactory->create(['default_scope' => $channel->getCode()]);
     $this->applyCategorizationFilter($pqb, $channel);
     $this->applyUpdatedFilter($pqb);
     $this->applyEnabledFilter($pqb);
     if ('doNotApply' !== $this->completeCondition && $this->generateCompleteness) {
         $this->completenessManager->generateMissingForChannel($channel);
     }
     $this->applyCompleteFilter($pqb, $channel);
     $this->products = $pqb->execute();
 }
 /**
  * Get ids of products which are completes and in channel
  *
  * @return array
  */
 protected function getIds()
 {
     if (!is_object($this->channel)) {
         $this->channel = $this->channelManager->getChannelByCode($this->channel);
     }
     if ($this->missingCompleteness) {
         $this->completenessManager->generateMissingForChannel($this->channel);
     }
     $this->query = $this->repository->buildByChannelAndCompleteness($this->channel);
     $rootAlias = current($this->query->getRootAliases());
     $rootIdExpr = sprintf('%s.id', $rootAlias);
     $from = current($this->query->getDQLPart('from'));
     $this->query->select($rootIdExpr)->resetDQLPart('from')->from($from->getFrom(), $from->getAlias(), $rootIdExpr)->groupBy($rootIdExpr);
     $results = $this->query->getQuery()->getArrayResult();
     return array_keys($results);
 }
 /**
  * Get ids of products which are completes and in channel
  *
  * @return array
  */
 protected function getIds()
 {
     if (!is_object($this->channel)) {
         $this->channel = $this->channelManager->getChannelByCode($this->channel);
     }
     if ($this->missingCompleteness) {
         $this->completenessManager->generateMissingForChannel($this->channel);
     }
     $this->query = $this->DnDBuildByChannelAndCompleteness($this->channel, $this->getIsComplete());
     $rootAlias = current($this->query->getRootAliases());
     $rootIdExpr = sprintf('%s.id', $rootAlias);
     $from = current($this->query->getDQLPart('from'));
     $this->query->select($rootIdExpr)->resetDQLPart('from')->from($from->getFrom(), $from->getAlias(), $rootIdExpr)->andWhere($this->query->expr()->orX($this->query->expr()->gte($from->getAlias() . '.updated', ':updated')))->setParameter('updated', $this->getDateFilter())->setParameter('enabled', $this->getIsEnabled())->groupBy($rootIdExpr);
     $results = $this->query->getQuery()->getArrayResult();
     return array_keys($results);
 }
 /**
  * Call when form is valid
  *
  * @param Family $family
  */
 protected function onSuccess(Family $family)
 {
     $this->manager->persist($family);
     $this->completenessManager->scheduleForFamily($family);
     $this->manager->flush();
 }