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);
 }
예제 #2
0
 /**
  * @param ProductInterface $product
  */
 protected function incrementCount(ProductInterface $product)
 {
     if ($product->getId()) {
         $this->stepExecution->incrementSummaryInfo('process');
     } else {
         $this->stepExecution->incrementSummaryInfo('create');
     }
 }
예제 #3
0
 /**
  * @param object $item
  */
 protected function incrementCount($item)
 {
     if ($item->getId()) {
         $this->stepExecution->incrementSummaryInfo('process');
     } else {
         $this->stepExecution->incrementSummaryInfo('create');
     }
 }
 function it_increments_summary_info(StepExecution $stepExecution, ProductInterface $product1, ProductInterface $product2)
 {
     $product1->getId()->willReturn('45');
     $product2->getId()->willReturn(null);
     $stepExecution->incrementSummaryInfo('process')->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('create')->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->write([$product1, $product2]);
 }
예제 #5
0
 /**
  * @param array $objects
  */
 protected function incrementCount(array $objects)
 {
     foreach ($objects as $object) {
         if ($object->getId()) {
             $this->stepExecution->incrementSummaryInfo('process');
         } else {
             $this->stepExecution->incrementSummaryInfo('create');
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->results) {
         $items = $this->readItems();
         $this->results = new \ArrayIterator($items);
     }
     if (null !== ($result = $this->results->current())) {
         $this->results->next();
         $this->stepExecution->incrementSummaryInfo('read');
     }
     return $result;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (!$this->isExecuted) {
         $this->isExecuted = true;
         $this->results = $this->getResults();
     }
     if (null !== ($result = $this->results->current())) {
         $this->results->next();
         $this->stepExecution->incrementSummaryInfo('read');
     }
     return $result;
 }
 /**
  * @param array $products
  */
 protected function incrementCount(array $products)
 {
     foreach ($products as $product) {
         foreach ($product->getAssociations() as $association) {
             $count = count($association->getProducts()) + count($association->getGroups());
             $action = $association->getId() ? 'process' : 'create';
             for ($i = 0; $i < $count; $i++) {
                 $this->stepExecution->incrementSummaryInfo($action);
             }
         }
     }
 }
 /**
  * Sets an item as skipped and throws an invalid item exception.
  *
  * @param array                            $item
  * @param ConstraintViolationListInterface $violations
  * @param \Exception                       $previousException
  *
  * @throws InvalidItemException
  */
 protected function skipItemWithConstraintViolations(array $item, ConstraintViolationListInterface $violations, \Exception $previousException = null)
 {
     if ($this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('skip');
     }
     throw new InvalidItemFromViolationsException($violations, new FileInvalidItem($item, $this->stepExecution->getSummaryInfo('read_lines') + 1), [], 0, $previousException);
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $product = null;
     if ($this->products->valid()) {
         $product = $this->products->current();
         $this->stepExecution->incrementSummaryInfo('read');
         $this->products->next();
     }
     if (null !== $product) {
         $channel = $this->getConfiguredChannel();
         if (null !== $channel) {
             $this->metricConverter->convert($product, $channel);
         }
     }
     return $product;
 }
 /**
  * Sets errors on items
  *
  * @param array $item
  * @param array $errors
  *
  * @throws InvalidItemException
  */
 protected function setItemErrors(array $item, array $errors)
 {
     if ($this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('skip');
     }
     throw new InvalidItemException(implode("\n", $this->getErrorMessages($errors)), $item);
 }
 /**
  * @param FlatItemBuffer $buffer
  * @param array          $writerOptions
  * @param int            $maxLinesPerFile
  * @param string         $basePathname
  *
  * @return array
  */
 protected function writeIntoSeveralFiles(FlatItemBuffer $buffer, array $writerOptions, $maxLinesPerFile, $basePathname)
 {
     $writtenFiles = [];
     $basePathPattern = $this->getNumberedPathname($basePathname);
     $writtenLinesCount = 0;
     $fileCount = 1;
     $headers = $this->sortHeaders($buffer->getHeaders());
     $hollowItem = array_fill_keys($headers, '');
     foreach ($buffer as $count => $incompleteItem) {
         if (0 === $writtenLinesCount % $maxLinesPerFile) {
             $filePath = $this->resolveFilePath($buffer, $maxLinesPerFile, $basePathPattern, $fileCount);
             $writtenLinesCount = 0;
             $writer = $this->getWriter($filePath, $writerOptions);
             $writer->addRow($headers);
         }
         $item = array_replace($hollowItem, $incompleteItem);
         $writer->addRow($item);
         $writtenLinesCount++;
         if (null !== $this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('write');
         }
         if (0 === $writtenLinesCount % $maxLinesPerFile || $buffer->count() === $count + 1) {
             $writer->close();
             $writtenFiles[] = $filePath;
             $fileCount++;
         }
     }
     return $writtenFiles;
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $configuration = $this->getJobConfiguration();
     if (!$this->isExecuted) {
         $this->isExecuted = true;
         $this->families = $this->getFamilies($configuration['filters']);
     }
     $result = $this->families->current();
     if (!empty($result)) {
         $this->stepExecution->incrementSummaryInfo('read');
         $this->families->next();
     } else {
         $result = null;
     }
     return $result;
 }
 /**
  * {@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;
 }
 /**
  * @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);
     }
 }
 function it_reads_several_entities_from_a_yml_file_incrementing_summary_info(StepExecution $stepExecution)
 {
     $this->beConstructedWith(true, false);
     $stepExecution->incrementSummaryInfo('read_lines')->shouldBeCalled();
     $this->setFilePath(realpath(__DIR__ . '/../../../../../../features/Context/fixtures/fake_products_with_code.yml'));
     $this->setStepExecution($stepExecution);
     $this->read()->shouldReturn(['mug_akeneo' => ['sku' => 'mug_akeneo'], 't_shirt_akeneo_purple' => ['sku' => 't_shirt_akeneo_purple', 'color' => 'purple'], 'mouse_akeneo' => ['sku' => 'mouse_akeneo']]);
 }
예제 #17
0
 /**
  * @param array                        $item
  * @param DataArrayConversionException $exception
  *
  * @throws InvalidItemException
  * @throws InvalidItemFromViolationsException
  */
 protected function skipItemFromConversionException(array $item, DataArrayConversionException $exception)
 {
     if (null !== $this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('skip');
     }
     if (null !== $exception->getViolations()) {
         throw new InvalidItemFromViolationsException($exception->getViolations(), new FileInvalidItem($item, $this->stepExecution->getSummaryInfo('read_lines') + 1), [], 0, $exception);
     }
     throw new InvalidItemException($exception->getMessage(), new FileInvalidItem($item, $this->stepExecution->getSummaryInfo('read_lines') + 1), [], 0, $exception);
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $configuration = $this->getJobConfiguration();
     if (null === $configuration) {
         return null;
     }
     if (!$this->isExecuted) {
         $this->isExecuted = true;
         $this->products = $this->getProductsCursor($configuration['filters']);
     }
     $result = $this->products->current();
     if (!empty($result)) {
         $this->stepExecution->incrementSummaryInfo('read');
         $this->products->next();
     } else {
         $result = null;
     }
     return $result;
 }
예제 #19
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (!$this->executed) {
         $this->executed = true;
         $this->results = $this->getQuery()->execute();
         if (!$this->results instanceof \Iterator) {
             $this->results = new \ArrayIterator($this->results);
         }
         if (is_a($this->results, 'Doctrine\\MongoDB\\Cursor', true)) {
             // MongoDB Cursor are not positionned on first element (whereas ArrayIterator is)
             // as long as getNext() hasn't be called
             $this->results->getNext();
         }
     }
     if ($result = $this->results->current()) {
         $this->results->next();
         $this->stepExecution->incrementSummaryInfo('read');
     }
     return $result;
 }
 function it_throws_an_exception_if_an_error_occurs_during_processing($transformer, $validator, $managerRegistry, ProductInterface $product, ColumnInfo $columnInfo, ObjectManager $objectManager, StepExecution $stepExecution)
 {
     $item = ['sku' => 'AKNTS', 'family' => 'tshirts', 'groups' => 'akeneo_tshirt', 'categories' => 'tshirts,goodies', 'SUBSTITUTION-groups' => '', 'SUBSTITUTION-products' => 'AKNTS_WPS,AKNTS_PBS,AKNTS_PWS', 'description-en_US-mobile' => '<p>Akeneo T-Shirt</p>', 'not_empty_attribute' => ''];
     $transformer->transform('Pim\\Component\\Catalog\\Model\\Product', $item, ['enabled' => true])->willReturn($product);
     $transformer->getErrors('Pim\\Component\\Catalog\\Model\\Product')->willReturn([]);
     $transformer->getTransformedColumnsInfo('Pim\\Component\\Catalog\\Model\\Product')->willReturn([$columnInfo]);
     $validator->validate($product, [$columnInfo], $item, [])->willReturn(['AKNTS' => [["The value \"\" for not empty attribute \"not_empty_attribute\" is empty"]]]);
     $managerRegistry->getManagerForClass(Argument::type('string'))->willReturn($objectManager);
     $stepExecution->incrementSummaryInfo('skip')->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->shouldThrow(new InvalidItemException('AKNTS: ', $item))->duringProcess($item);
 }
 function it_reads_families($jobConfigurationRepo, $familyRepository, StepExecution $stepExecution, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration, FamilyInterface $pantFamily, FamilyInterface $sockFamily)
 {
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
     $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [['field' => 'id', 'operator' => 'IN', 'value' => [12, 13, 14]]]]));
     $families = [$pantFamily, $sockFamily];
     $familyRepository->findByIds([12, 13, 14])->willReturn($families);
     $stepExecution->incrementSummaryInfo('read')->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->read()->shouldReturn($pantFamily);
     $this->read()->shouldReturn($sockFamily);
     $this->read()->shouldReturn(null);
     $stepExecution->incrementSummaryInfo('read')->shouldHaveBeenCalledTimes(2);
 }
 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);
 }
예제 #23
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->yaml) {
         $this->yaml = new \ArrayIterator($this->getFileData());
     }
     if ($data = $this->yaml->current()) {
         $this->yaml->next();
         if (null !== $this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('read_lines');
         }
         return $data;
     }
     return null;
 }
 function it_reads_products($entityManager, $jobRepository, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobInstance $jobInstance, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration, ProductQueryBuilderFactory $pqbFactory, ProductQueryBuilder $pqb, StepExecution $stepExecution, Cursor $cursor, ProductInterface $product, EntityRepository $customEntityRepository)
 {
     $jobRepository->getJobManager()->willReturn($entityManager);
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $customEntityRepository->findOneBy(['code' => 'update_product_value'])->willReturn($jobInstance);
     $jobInstance->getJobExecutions()->willReturn(new ArrayCollection([$jobExecution]));
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
     $pqbFactory->create()->willReturn($pqb);
     $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => []]));
     $pqb->execute()->willReturn($cursor);
     $cursor->next()->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('read')->shouldBeCalledTimes(1);
     $this->setStepExecution($stepExecution);
     $cursor->current()->willReturn($product);
     $this->read()->shouldReturn($product);
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $product = null;
     if (!$this->products->valid()) {
         $this->products = $this->getNextProducts();
     }
     if (null !== $this->products) {
         $product = $this->products->current();
         $this->products->next();
         $this->stepExecution->incrementSummaryInfo('read');
     }
     if (null !== $product) {
         $this->metricConverter->convert($product, $this->channel);
     }
     return $product;
 }
예제 #26
0
 /**
  * {@inheritdoc}
  */
 public function write(array $data)
 {
     if (!$this->handler) {
         $path = $this->getPath();
         if (!is_dir(dirname($path))) {
             mkdir(dirname($path), 0777, true);
         }
         $this->handler = fopen($path, 'w');
     }
     foreach ($data as $entry) {
         if (false === fwrite($this->handler, $entry)) {
             throw new RuntimeErrorException('Failed to write to file %path%', ['%path%' => $this->getPath()]);
         } else {
             $this->stepExecution->incrementSummaryInfo('write');
         }
     }
 }
 /**
  * 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];
 }
 /**
  * Sets an item as skipped and throws an invalid item exception.
  *
  * @param array                            $item
  * @param ConstraintViolationListInterface $violations
  * @param \Exception                       $previousException
  *
  * @throws InvalidItemException
  */
 protected function skipItemWithConstraintViolations(array $item, ConstraintViolationListInterface $violations, \Exception $previousException = null)
 {
     if ($this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('skip');
     }
     $errors = [];
     /** @var ConstraintViolationInterface $violation */
     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);
     }
     throw new InvalidItemException(implode("\n", $errors), $item, [], 0, $previousException);
 }
 function it_flushes_a_buffer_into_multiple_files_with_extension($columnSorter, FlatItemBuffer $buffer, StepExecution $stepExecution, JobParameters $parameters)
 {
     $columnSorter->sort(Argument::any(), [])->willReturn(['colA', 'colB']);
     $stepExecution->getJobParameters()->willReturn($parameters);
     $stepExecution->incrementSummaryInfo('write')->shouldBeCalled();
     $parameters->all()->willReturn([]);
     $buffer->rewind()->willReturn();
     $buffer->count()->willReturn(3);
     $buffer->valid()->willReturn(true, true, true, false);
     $buffer->next()->willReturn();
     $buffer->current()->willReturn(['colA' => 'fooA', 'colB' => 'fooB']);
     $buffer->key()->willReturn(0);
     $buffer->getHeaders()->willReturn(['colA', 'colB']);
     $this->flush($buffer, ['type' => 'csv'], $this->directory . 'output.txt', 2);
     if (!file_exists($this->directory . 'output_1.txt')) {
         throw new FailedPredictionException(sprintf('File "%s" should have been flushed', $this->directory . 'output_1.txt'));
     }
     if (!file_exists($this->directory . 'output_2.txt')) {
         throw new FailedPredictionException(sprintf('File "%s" should have been flushed', $this->directory . 'output_2.txt'));
     }
 }
예제 #30
0
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->csv) {
         $this->initializeRead();
     }
     $data = $this->csv->fgetcsv();
     if (false !== $data) {
         if ([null] === $data || null === $data) {
             return null;
         }
         if ($this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('read_lines');
         }
         if (count($this->fieldNames) !== count($data)) {
             throw new InvalidItemException('pim_connector.steps.csv_reader.invalid_item_columns_count', $data, ['%totalColumnsCount%' => count($this->fieldNames), '%itemColumnsCount%' => count($data), '%csvPath%' => $this->csv->getRealPath(), '%lineno%' => $this->csv->key()]);
         }
         $data = array_combine($this->fieldNames, $data);
     } elseif ($this->csv->eof()) {
         $data = null;
     } else {
         throw new \RuntimeException('An error occurred while reading the csv.');
     }
     return $data;
 }