/** * @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); } }
/** * @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); } }
/** * Add a warning based on the stepExecution. * * @param string $message * @param array $messageParameters * @param mixed $item */ protected function addWarning($message, array $messageParameters = [], $item = null) { $this->stepExecution->addWarning($this->getName(), $message, $messageParameters, $item); if (!is_array($item)) { $item = array(); } $item = $this->cleanupImageContent($item); $event = new InvalidItemEvent(get_class($this), $message, $messageParameters, $item); $this->eventDispatcher->dispatch(EventInterface::INVALID_ITEM, $event); }
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); }
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); }
/** * 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]; }
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([]); }
/** * Handle step execution warning * * @param StepExecution $stepExecution * @param AbstractConfigurableStepElement $element * @param InvalidItemException $e */ protected function handleStepExecutionWarning(StepExecution $stepExecution, AbstractConfigurableStepElement $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()); }
/** * {@inheritDoc} */ public function addWarning($name, $reason, array $reasonParameters, $item) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'addWarning', array($name, $reason, $reasonParameters, $item)); return parent::addWarning($name, $reason, $reasonParameters, $item); }
public function testAddWarning() { $getWarnings = function ($warnings) { return array_map(function ($warning) { return $warning->toArray(); }, $warnings->toArray()); }; $this->stepExecution->addWarning('foo', '%something% is wrong on line 1', array('%something%' => 'Item1'), array('foo' => 'bar')); $this->stepExecution->addWarning('bar', '%something% is wrong on line 2', array('%something%' => 'Item2'), array('baz' => false)); $item = new \stdClass(); $this->stepExecution->addWarning('baz', '%something% is wrong with object 3', array('%something%' => 'Item3'), $item); $this->assertEquals(array(array('name' => 'my_step_execution.steps.foo.title', 'reason' => '%something% is wrong on line 1', 'reasonParameters' => array('%something%' => 'Item1'), 'item' => array('foo' => 'bar')), array('name' => 'my_step_execution.steps.bar.title', 'reason' => '%something% is wrong on line 2', 'reasonParameters' => array('%something%' => 'Item2'), 'item' => array('baz' => false)), array('name' => 'my_step_execution.steps.baz.title', 'reason' => '%something% is wrong with object 3', 'reasonParameters' => array('%something%' => 'Item3'), 'item' => array('id' => '[unknown]', 'class' => 'stdClass', 'string' => '[unknown]'))), $getWarnings($this->stepExecution->getWarnings())); $stepExecution = new StepExecution('my_step_execution.foobarbaz', $this->jobExecution); $stepExecution->addWarning('foo', '%something% is wrong on line 1', array('%something%' => 'Item1'), array('foo' => 'bar')); $stepExecution->addWarning('bar', '%something% is wrong on line 2', array('%something%' => 'Item2'), array('baz' => false)); $this->assertEquals(array(array('name' => 'my_step_execution.steps.foo.title', 'reason' => '%something% is wrong on line 1', 'reasonParameters' => array('%something%' => 'Item1'), 'item' => array('foo' => 'bar')), array('name' => 'my_step_execution.steps.bar.title', 'reason' => 'something is wrong on line 2', 'reason' => '%something% is wrong on line 2', 'reasonParameters' => array('%something%' => 'Item2'), 'item' => array('baz' => false))), $getWarnings($stepExecution->getWarnings())); }