function it_adds_invalid_values_to_product($groupRepository, $validator, $templateUpdater, GroupInterface $variantGroup, ProductInterface $product, StepExecution $stepExecution, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration, ProductTemplateInterface $productTemplate)
 {
     $violation = new ConstraintViolation('error2', 'spec', [], '', '', $product);
     $violations = new ConstraintViolationList([$violation, $violation]);
     $validator->validate($product)->willReturn($violations);
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
     $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => ['field' => 'variant_group', 'value' => 'variant_group_code']]));
     $groupRepository->findOneByIdentifier('variant_group_code')->willReturn($variantGroup);
     $product->getVariantGroup()->willReturn(null);
     $variantGroup->addProduct($product)->shouldBeCalled();
     $variantGroup->getProductTemplate()->willReturn($productTemplate);
     $templateUpdater->update($variantGroup->getProductTemplate(), [$product]);
     $stepExecution->addWarning(Argument::cetera())->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('skipped_products')->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->process($product);
 }
 /**
  * Fetch medias in local filesystem
  *
  * @param GroupInterface $variantGroup
  * @param string         $directory
  */
 protected function fetchMedia(GroupInterface $variantGroup, $directory)
 {
     if (null === ($productTemplate = $variantGroup->getProductTemplate())) {
         return;
     }
     $identifier = $variantGroup->getCode();
     $this->variantGroupUpdater->update($variantGroup, ['values' => $productTemplate->getValuesData()]);
     $this->mediaFetcher->fetchAll($productTemplate->getValues(), $directory, $identifier);
     foreach ($this->mediaFetcher->getErrors() as $error) {
         $this->stepExecution->addWarning($error['message'], [], new DataInvalidItem($error['media']));
     }
 }
 /**
  * @param ConstraintViolationListInterface $violations
  * @param ProductInterface                 $product
  */
 protected function addWarningMessage(ConstraintViolationListInterface $violations, ProductInterface $product)
 {
     foreach ($violations as $violation) {
         // TODO re-format the message, property path doesn't exist for class constraint
         // for instance cf VariantGroupAxis
         $invalidValue = $violation->getInvalidValue();
         if (is_object($invalidValue) && method_exists($invalidValue, '__toString')) {
             $invalidValue = (string) $invalidValue;
         } elseif (is_object($invalidValue)) {
             $invalidValue = get_class($invalidValue);
         }
         $errors = sprintf("%s: %s: %s\n", $violation->getPropertyPath(), $violation->getMessage(), $invalidValue);
         $this->stepExecution->addWarning($this->getName(), $errors, [], $product);
     }
 }
 function it_executes_with_an_invalid_item_during_processing($reader, $processor, $writer, StepExecution $execution, EventDispatcherInterface $dispatcher, JobRepositoryInterface $repository, BatchStatus $status, ExitStatus $exitStatus)
 {
     $this->setBatchSize(3);
     $this->setEventDispatcher($dispatcher);
     $this->setJobRepository($repository);
     $execution->getStatus()->willReturn($status);
     $status->getValue()->willReturn(BatchStatus::STARTING);
     $dispatcher->dispatch(EventInterface::BEFORE_STEP_EXECUTION, Argument::any())->shouldBeCalled();
     $execution->setStartTime(Argument::any())->shouldBeCalled();
     $execution->setStatus(Argument::any())->shouldBeCalled();
     // first batch
     $reader->read()->willReturn('r1', 'r2', 'r3', 'r4', null);
     $processor->process('r1')->shouldBeCalled()->willReturn('p1');
     $processor->process('r2')->shouldBeCalled()->willReturn('p2');
     $processor->process('r3')->shouldBeCalled()->willReturn('p3');
     $writer->write(['p1', 'p2', 'p3'])->shouldBeCalled();
     // second batch
     $processor->process('r4')->shouldBeCalled()->willThrow(new InvalidItemException('my msg', ['r4']));
     $execution->addWarning(Argument::any(), Argument::any(), Argument::any(), Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(Argument::any(), Argument::any())->shouldBeCalled();
     $processor->process(null)->shouldNotBeCalled();
     $writer->write(['p4'])->shouldNotBeCalled();
     $execution->getExitStatus()->willReturn($exitStatus);
     $exitStatus->getExitCode()->willReturn(ExitStatus::COMPLETED);
     $repository->updateStepExecution($execution)->shouldBeCalled();
     $execution->isTerminateOnly()->willReturn(false);
     $execution->upgradeStatus(Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(EventInterface::STEP_EXECUTION_SUCCEEDED, Argument::any())->shouldBeCalled();
     $dispatcher->dispatch(EventInterface::STEP_EXECUTION_COMPLETED, Argument::any())->shouldBeCalled();
     $execution->setEndTime(Argument::any())->shouldBeCalled();
     $execution->setExitStatus(Argument::any())->shouldBeCalled();
     $this->execute($execution);
 }
 /**
  * @param array $skippedMessages
  * @param int   $nbSkippedProducts
  */
 protected function incrementSkippedProductsCount(array $skippedMessages, $nbSkippedProducts)
 {
     $this->stepExecution->incrementSummaryInfo('skip_products', $nbSkippedProducts);
     foreach ($skippedMessages as $productIdentifier => $messages) {
         $this->stepExecution->addWarning(sprintf('Copy of values to product "%s" skipped.', $productIdentifier), [], new DataInvalidItem($messages));
     }
 }
 /**
  * @param int   $nbSkippedProducts
  * @param array $skippedMessages
  */
 protected function incrementSkippedProductsCount($nbSkippedProducts, $skippedMessages)
 {
     $this->stepExecution->incrementSummaryInfo('skip_products', $nbSkippedProducts);
     foreach ($skippedMessages as $productIdentifier => $messages) {
         $this->stepExecution->addWarning($this->getName(), sprintf('Copy of values to product "%s" skipped.', $productIdentifier), [], $messages);
     }
 }
 /**
  * Fetch medias on the local filesystem
  *
  * @param ProductInterface $product
  * @param string           $directory
  */
 protected function fetchMedia(ProductInterface $product, $directory)
 {
     $identifier = $product->getIdentifier()->getData();
     $this->mediaFetcher->fetchAll($product->getValues(), $directory, $identifier);
     foreach ($this->mediaFetcher->getErrors() as $error) {
         $this->stepExecution->addWarning($error['message'], [], new DataInvalidItem($error['media']));
     }
 }
 function it_adds_invalid_values_to_product($propertyAdder, $validator, ProductInterface $product, StepExecution $stepExecution, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration)
 {
     $violation = new ConstraintViolation('error2', 'spec', [], '', '', $product);
     $violations = new ConstraintViolationList([$violation, $violation]);
     $validator->validate($product)->willReturn($violations);
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
     $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => [['field' => 'categories', 'value' => ['office', 'bedroom']]]]));
     $propertyAdder->addData($product, 'categories', ['office', 'bedroom'])->shouldBeCalled();
     $stepExecution->addWarning(Argument::cetera())->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('skipped_products')->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->process($product);
 }
 /**
  * It checks it products is in eligible products for the variant group and
  * build the array based on variant axis and product ids.
  *
  * @param PaginatorInterface $paginator
  * @param array              $eligibleProductIds
  * @param array              $axisAttributeCodes
  *
  * @return array
  */
 protected function filterDuplicateAxisCombinations(PaginatorInterface $paginator, array $eligibleProductIds, array $axisAttributeCodes)
 {
     $productAttributeAxis = [];
     $acceptedIds = [];
     foreach ($paginator as $productsPage) {
         foreach ($productsPage as $product) {
             if (in_array($product->getId(), $eligibleProductIds)) {
                 $keyCombination = $this->generateAxisCombinationKey($product, $axisAttributeCodes);
                 $acceptedIds[] = $product->getId();
                 $productAttributeAxis = $this->fillDuplicateCombinationsArray($product, $productAttributeAxis, $keyCombination);
             } else {
                 $this->stepExecution->incrementSummaryInfo('skipped_products');
                 $this->stepExecution->addWarning('excluded', $this->translator->trans('pim_enrich.mass_edit_action.add-to-variant-group.already_in_variant_group_or_not_valid'), [], $product);
             }
         }
         $this->detachProducts($productsPage);
     }
     return [$productAttributeAxis, $acceptedIds];
 }
 /**
  * Handle step execution warning
  *
  * @param StepExecution        $stepExecution
  * @param mixed                $element
  * @param InvalidItemException $e
  */
 protected function handleStepExecutionWarning(StepExecution $stepExecution, $element, InvalidItemException $e)
 {
     if ($element instanceof AbstractConfigurableStepElement) {
         $warningName = $element->getName();
     } else {
         $warningName = get_class($element);
     }
     $stepExecution->addWarning($warningName, $e->getMessage(), $e->getMessageParameters(), $e->getItem());
     $this->dispatchInvalidItemEvent(get_class($element), $e->getMessage(), $e->getMessageParameters(), $e->getItem());
 }
Beispiel #11
0
 /**
  * Handle step execution warning
  *
  * @param StepExecution        $stepExecution
  * @param mixed                $element
  * @param InvalidItemException $e
  */
 protected function handleStepExecutionWarning(StepExecution $stepExecution, $element, InvalidItemException $e)
 {
     $stepExecution->addWarning($e->getMessage(), $e->getMessageParameters(), $e->getItem());
     $this->dispatchInvalidItemEvent(get_class($element), $e->getMessage(), $e->getMessageParameters(), $e->getItem());
 }
 function it_skips_and_adds_warning_if_there_are_categories_with_circular_references($transformer, $validator, CategoryInterface $childCategory, CategoryInterface $parentCategory, CategoryInterface $grandParentCategory, StepExecution $stepExecution)
 {
     $item1 = ['id' => 11, 'code' => 'child_category', 'parent' => 'parent_category', 'created' => 'date', 'root' => 1];
     $item2 = ['id' => 12, 'code' => 'parent_category', 'parent' => 'grand_parent_category', 'created' => 'date2', 'root' => 1];
     $item3 = ['id' => 13, 'code' => 'grand_parent_category', 'parent' => 'child_category', 'created' => 'date2', 'root' => 1];
     $data = [$item1, $item2, $item3];
     $transformer->transform('Pim\\Bundle\\CatalogBundle\\Entity\\Category', ['id' => 11, 'code' => 'child_category', 'created' => 'date', 'root' => 1])->willReturn($childCategory);
     $transformer->transform('Pim\\Bundle\\CatalogBundle\\Entity\\Category', ['id' => 12, 'code' => 'parent_category', 'created' => 'date2', 'root' => 1])->willReturn($parentCategory);
     $transformer->transform('Pim\\Bundle\\CatalogBundle\\Entity\\Category', ['id' => 13, 'code' => 'grand_parent_category', 'created' => 'date2', 'root' => 1])->willReturn($grandParentCategory);
     $transformer->getErrors('Pim\\Bundle\\CatalogBundle\\Entity\\Category')->willReturn([]);
     $transformer->getTransformedColumnsInfo('Pim\\Bundle\\CatalogBundle\\Entity\\Category')->willReturn([]);
     $validator->validate(Argument::cetera())->willReturn([]);
     $childCategory->setParent($parentCategory)->shouldBeCalled();
     $parentCategory->setParent($grandParentCategory)->shouldBeCalled();
     $grandParentCategory->setParent($childCategory)->shouldBeCalled();
     $childCategory->getCode()->willReturn('child_category');
     $childCategory->getParent()->willReturn($parentCategory);
     $parentCategory->getCode()->willReturn('parent_category');
     $parentCategory->getParent()->willReturn($grandParentCategory);
     $grandParentCategory->getCode()->willReturn('grand_parent_category');
     $grandParentCategory->getParent()->willReturn($childCategory);
     $stepExecution->incrementSummaryInfo('skip')->shouldBeCalledTimes(3);
     $stepExecution->addWarning('category_processor', 'parent: ', [], ['id' => 11, 'code' => 'child_category', 'created' => 'date', 'root' => 1])->shouldBeCalled();
     $stepExecution->addWarning('category_processor', 'parent: ', [], ['id' => 12, 'code' => 'parent_category', 'created' => 'date2', 'root' => 1])->shouldBeCalled();
     $stepExecution->addWarning('category_processor', 'parent: ', [], ['id' => 13, 'code' => 'grand_parent_category', 'created' => 'date2', 'root' => 1])->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->process($data)->shouldReturn([]);
 }