Example #1
0
 public function write(array $items)
 {
     foreach ($items as $product) {
         $this->productManager->save($product);
         $this->stepExecution->incrementSummaryInfo('save');
     }
 }
 public function process($item)
 {
     $sku = (string) $item['sku'];
     $attribute = $this->productManager->getIdentifierAttribute();
     $product = $this->productManager->findByIdentifier($sku);
     // if (!$product) {
     //     $product = $this->productManager->createProduct();
     //     $value   = $this->productManager->createProductValue();
     //     $value->setAttribute($attribute);
     //     $value->setData($sku);
     //     $product->addValue($value);
     //     $this->stepExecution->incrementSummaryInfo('create');
     //     return $product;
     // } else {
     if (!$product) {
         $data = current((array) $item);
         $this->stepExecution->incrementSummaryInfo('skip');
         throw new InvalidItemException(sprintf('Skip the existing %s product', $sku), $data);
     } else {
         $product_tab = array();
         $product_tab[] = $product;
         $this->productUpdater->setValue($product_tab, 'price', [['data' => (string) $item['price'], 'currency' => (string) $item['currency']]]);
         return $product;
     }
     // }
 }
Example #3
0
 /**
  * @param object $item
  */
 protected function incrementCount($item)
 {
     if ($item->getId()) {
         $this->stepExecution->incrementSummaryInfo('update');
     } 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('update')->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('create')->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $this->write([$product1, $product2]);
 }
Example #5
0
 public function write(array $items)
 {
     if (null === $this->file) {
         $this->file = new \SplFileObject($this->filePath, "w");
     }
     foreach ($items as $product) {
         $this->file->fputcsv($product);
         $this->stepExecution->incrementSummaryInfo('write');
     }
 }
 /**
  * @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 (!$this->cursor) {
         $this->cursor = $this->getQuery()->iterate();
     }
     if ($data = $this->cursor->next()) {
         $this->stepExecution->incrementSummaryInfo('read');
         return $data;
     }
 }
 /**
  * {@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;
 }
 /**
  * {@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;
 }
 public function read()
 {
     if (!isset($this->iterator)) {
         $this->initializeIterator();
     }
     if (!$this->iterator->valid()) {
         return null;
     }
     $current = $this->iterator->current();
     if ($this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('read');
     }
     $this->iterator->next();
     return $current;
 }
 public function read()
 {
     if (!isset($this->iterator)) {
         $this->initializeIterator();
     }
     if (!$this->iterator->valid()) {
         return null;
     }
     $current = $this->iterator->current();
     if ($this->stepExecution) {
         $this->stepExecution->incrementSummaryInfo('read');
     }
     $this->iterator->next();
     return $this->convertNumericIdentifierToString($current);
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if (null === $this->csv) {
         if (mime_content_type($this->filePath) === 'application/zip') {
             $this->extractZipArchive();
         }
         $this->csv = new \SplFileObject($this->filePath);
         $this->csv->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY | \SplFileObject::DROP_NEW_LINE);
         $this->csv->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
         $this->fieldNames = $this->csv->fgetcsv();
     }
     $data = $this->csv->fgetcsv();
     if (false !== $data) {
         if ($data === array(null) || $data === null) {
             return null;
         }
         if ($this->stepExecution) {
             $this->stepExecution->incrementSummaryInfo('read');
         }
         if (count($this->fieldNames) !== count($data)) {
             throw new InvalidItemException('pim_base_connector.steps.csv_reader.invalid_item_columns_count', $data, array('%totalColumnsCount%' => count($this->fieldNames), '%itemColumnsCount%' => count($data), '%csvPath%' => $this->csv->getRealPath(), '%lineno%' => $this->csv->key()));
         }
         $data = array_combine($this->fieldNames, $data);
     } else {
         throw new \RuntimeException('An error occured while reading the csv.');
     }
     return $data;
 }
 /**
  * {@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;
 }
 /**
  * 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 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);
     }
 }
 /**
  * {@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;
 }
 /**
  * Test the increment by bulk
  */
 public function testIncrementSummaryInfoByBulk()
 {
     $this->stepExecution->incrementSummaryInfo('create');
     $this->stepExecution->incrementSummaryInfo('create');
     $this->assertEquals($this->stepExecution->getSummaryInfo('create'), 2);
     $this->stepExecution->incrementSummaryInfo('create', 5);
     $this->assertEquals($this->stepExecution->getSummaryInfo('create'), 7);
 }
 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']]);
 }
 /**
  * {@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');
         }
     }
 }
 /**
  * @param ProductInterface $product
  */
 protected function incrementCount(ProductInterface $product)
 {
     if ($product->getId()) {
         $this->stepExecution->incrementSummaryInfo('process');
     } else {
         $this->stepExecution->incrementSummaryInfo('create');
     }
 }
 /**
  * {@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;
 }
Example #22
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;
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     $config = $this->getJobConfiguration();
     $resolver = new OptionsResolver();
     $this->configureOptions($resolver);
     $config = $resolver->resolve($config);
     if (null === $this->referenceDatas) {
         if ($config['reference_data']) {
             $this->referenceDatas = $this->getReferenceDatas($config['reference_data'], $config['ids']);
         }
     }
     $result = $this->referenceDatas->current();
     if (!empty($result)) {
         $this->stepExecution->incrementSummaryInfo('read');
         $this->referenceDatas->next();
     } else {
         $result = null;
     }
     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);
 }
 /**
  * {@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');
         }
         return $data;
     }
     return null;
 }
 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_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);
 }
 /**
  * @{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->channelManager->getChannelByCode($this->channel);
         $this->metricConverter->convert($product, $channel);
     }
     return $product;
 }
Example #29
0
    public function process($item)
    {
        $sku       = $item['sku'];
        $attribute = $this->productManager->getIdentifierAttribute();
        $product   = $this->productManager->findByIdentifier($sku);

        if (!$product) {
            $product = $this->productManager->createProduct();
            $value   = $this->productManager->createProductValue();
            $value->setAttribute($attribute);
            $value->setData($sku);
            $product->addValue($value);
            $this->stepExecution->incrementSummaryInfo('create');

            return $product;

        } else {

            $data = current(((array) $item));
            $this->stepExecution->incrementSummaryInfo('skip');

            throw new InvalidItemException(sprintf('Skip the existing %s product', $sku), $data);
        }
    }
 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);
 }