/**
  * @return ExecutionContext
  */
 protected function getJobContext()
 {
     if (!$this->stepExecution) {
         throw new \InvalidArgumentException('Missing StepExecution');
     }
     return $this->stepExecution->getJobExecution()->getExecutionContext();
 }
 public function testProcessWithoutCustomer()
 {
     /** @var NewsletterSubscriber $newsletterSubscriber */
     $newsletterSubscriber = $this->getReference('newsletter_subscriber2');
     $newsletterSubscriber->setCustomer(null);
     $em = $this->getContainer()->get('doctrine')->getManager();
     $em->persist($newsletterSubscriber);
     $em->flush($newsletterSubscriber);
     $this->strategy->setEntityName(get_class($newsletterSubscriber));
     $this->assertEquals($newsletterSubscriber, $this->strategy->process($newsletterSubscriber));
     $this->assertEmpty($this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessSubscribers'));
     $this->assertEmpty($this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessCustomerIds'));
 }
 function it_throws_an_exception_if_no_job_configuration_is_found($jobConfigurationRepo, StepExecution $stepExecution, JobExecution $jobExecution)
 {
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn(null);
     $this->setStepExecution($stepExecution);
     $this->shouldThrow('Doctrine\\ORM\\EntityNotFoundException')->during('read');
 }
Example #4
0
 /**
  * @return ExecutionContext
  */
 protected function getExecutionContext()
 {
     if (!$this->stepExecution) {
         throw new \InvalidArgumentException('Execution context is not configured');
     }
     return $this->stepExecution->getJobExecution()->getExecutionContext();
 }
 /**
  * Save the job configuration
  *
  * @param string $configuration
  */
 protected function setJobConfiguration($configuration)
 {
     $jobExecution = $this->stepExecution->getJobExecution();
     $massEditJobConf = $this->jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution]);
     $massEditJobConf->setConfiguration($configuration);
     $this->jobConfigurationSaver->save($massEditJobConf);
 }
 /**
  * {@inheritdoc}
  */
 public function removeOption($name)
 {
     if ($this->hasOption($name)) {
         $configuration = $this->getConfiguration();
         unset($configuration[$name]);
         $this->stepExecution->getJobExecution()->getJobInstance()->setRawConfiguration($configuration);
     }
 }
 /**
  * Save the job configuration
  *
  * @param string $configuration
  */
 protected function setJobConfiguration($configuration)
 {
     $jobExecution = $this->stepExecution->getJobExecution();
     $massEditJobConf = $this->jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution]);
     $massEditJobConf->setConfiguration($configuration);
     $this->objectManager->persist($massEditJobConf);
     $this->objectManager->flush($massEditJobConf);
 }
 /**
  * {@inheritdoc}
  */
 public function updateStepExecution(StepExecution $stepExecution)
 {
     $jobExecution = $stepExecution->getJobExecution();
     if ($jobExecution) {
         $this->updateJobExecution($jobExecution);
     }
     parent::updateStepExecution($stepExecution);
 }
 /**
  * Return the job configuration
  *
  * @throws EntityNotFoundException
  *
  * @return array
  */
 protected function getJobConfiguration()
 {
     $jobExecution = $this->stepExecution->getJobExecution();
     $massEditJobConf = $this->jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution]);
     if (null === $massEditJobConf) {
         throw new EntityNotFoundException(sprintf('No JobConfiguration found for jobExecution with id %s', $jobExecution->getId()));
     }
     return json_decode(stripcslashes($massEditJobConf->getConfiguration()), true);
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     /** @var EntityManager $em */
     $em = $this->registry->getManager();
     try {
         $em->beginTransaction();
         foreach ($items as $item) {
             $em->persist($item);
         }
         $em->flush();
         $em->commit();
         $configuration = $this->contextRegistry->getByStepExecution($this->stepExecution)->getConfiguration();
         $contextSkipClear = $this->stepExecution->getJobExecution()->getExecutionContext()->get(EntityWriter::SKIP_CLEAR);
         if (empty($configuration[EntityWriter::SKIP_CLEAR]) && !$contextSkipClear) {
             $em->clear();
         }
     } catch (\Exception $exception) {
         $em->rollback();
         if (!$em->isOpen()) {
             $this->registry->resetManager();
         }
         $jobName = $this->stepExecution->getJobExecution()->getJobInstance()->getAlias();
         $event = new WriterErrorEvent($items, $jobName, $exception);
         $this->eventDispatcher->dispatch(WriterErrorEvent::NAME, $event);
         if ($event->getCouldBeSkipped()) {
             $importContext = $this->contextRegistry->getByStepExecution($this->stepExecution);
             $importContext->setValue('error_entries_count', (int) $importContext->getValue('error_entries_count') + count($items));
             $this->logger->warning($event->getWarning());
             if ($event->getException() === $exception) {
                 // exception are already handled and job can move forward
                 throw new InvalidItemException($event->getWarning(), []);
             } else {
                 // exception are already created and ready to be rethrown
                 throw $event->getException();
             }
         } else {
             throw $exception;
         }
     }
     $this->eventDispatcher->dispatch(WriterAfterFlushEvent::NAME, new WriterAfterFlushEvent($em));
 }
 /**
  * Get the last successful execution date for the current job instance
  *
  * @return \DateTime||null
  */
 protected function getLastExecutionDate()
 {
     $query = $this->entityManager->createQuery(sprintf("SELECT MAX(e.endTime) FROM %s e WHERE e.jobInstance = :jobInstance AND e.exitCode = :completed", $this->jobExecutionClass));
     $query->setParameter('jobInstance', $this->stepExecution->getJobExecution()->getJobInstance());
     $query->setParameter('completed', ExitStatus::COMPLETED);
     $utcDateTime = $query->getOneOrNullResult();
     if (is_array($utcDateTime)) {
         $utcTimeZone = new \DateTimeZone('Etc/UTC');
         $utcDateTime = new \DateTime(reset($utcDateTime), $utcTimeZone);
     }
     $dateTime = new \DateTime();
     $dateTime->setTimestamp($utcDateTime->getTimestamp());
     return $dateTime;
 }
 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_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);
 }
 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);
 }
 function it_sets_invalid_values_to_attributes($validator, $propertySetter, FamilyInterface $family, AttributeInterface $attribute, AttributeRepository $attributeRepository, ProductInterface $product, ConstraintViolationListInterface $violations, StepExecution $stepExecution, JobConfigurationRepositoryInterface $jobConfigurationRepo, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration)
 {
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
     $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => [['field' => 'categories', 'value' => ['office', 'bedroom'], 'options' => []]]]));
     $validator->validate($product)->willReturn($violations);
     $violation = new ConstraintViolation('error2', 'spec', [], '', '', $product);
     $violations = new ConstraintViolationList([$violation, $violation]);
     $validator->validate($product)->willReturn($violations);
     $attributeRepository->findOneBy(['code' => 'categories'])->willReturn($attribute);
     $family->hasAttribute($attribute)->willReturn(true);
     $product->getFamily()->willReturn($family);
     $propertySetter->setData($product, 'categories', ['office', 'bedroom'], [])->shouldBeCalled();
     $this->setStepExecution($stepExecution);
     $stepExecution->addWarning(Argument::cetera())->shouldBeCalled();
     $stepExecution->incrementSummaryInfo('skipped_products')->shouldBeCalled();
     $this->process($product);
 }
 function it_processes_a_family($jobConfigurationRepo, $attributeRepository, $channelRepository, $factory, StepExecution $stepExecution, ValidatorInterface $validator, FamilyInterface $family, JobExecution $jobExecution, JobConfigurationInterface $jobConfiguration, AttributeInterface $attributeColor, ChannelInterface $channelMobile, ChannelInterface $channelEcommerce, AttributeRequirementInterface $attrReqColorMobile, AttributeRequirementInterface $attrReqColorEcom)
 {
     $actions = [['attribute_code' => 'color', 'channel_code' => 'mobile', 'is_required' => true], ['attribute_code' => 'color', 'channel_code' => 'ecommerce', 'is_required' => false]];
     $violations = new ConstraintViolationList([]);
     $validator->validate($family)->willReturn($violations);
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $attributeRepository->findOneByIdentifier('color')->willReturn($attributeColor);
     $channelRepository->findOneByIdentifier('mobile')->willReturn($channelMobile);
     $channelRepository->findOneByIdentifier('ecommerce')->willReturn($channelEcommerce);
     $jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution])->willReturn($jobConfiguration);
     $jobConfiguration->getConfiguration()->willReturn(json_encode(['filters' => [], 'actions' => $actions]));
     $factory->createAttributeRequirement($attributeColor, $channelMobile, true)->willReturn($attrReqColorMobile);
     $factory->createAttributeRequirement($attributeColor, $channelEcommerce, false)->willReturn($attrReqColorEcom);
     $this->setStepExecution($stepExecution);
     $family->addAttribute($attributeColor)->shouldBeCalledTimes(2);
     $family->addAttributeRequirement($attrReqColorMobile)->shouldBeCalled();
     $family->addAttributeRequirement($attrReqColorEcom)->shouldBeCalled();
     $this->process($family);
 }
 /**
  * {@inheritdoc}
  */
 public function getConfiguration()
 {
     $stepName = $this->stepExecution->getStepName();
     $rawConfiguration = $this->stepExecution->getJobExecution()->getJobInstance()->getRawConfiguration();
     return !empty($rawConfiguration[$stepName]) ? $rawConfiguration[$stepName] : $rawConfiguration;
 }
 /**
  * Return the job configuration
  *
  * @return array
  */
 protected function getJobConfiguration()
 {
     $jobExecution = $this->stepExecution->getJobExecution();
     $massEditJobConf = $this->jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution]);
     return json_decode(stripcslashes($massEditJobConf->getConfiguration()), true);
 }
 /**
  * @return ExecutionContext
  */
 protected function getJobContext()
 {
     /** @var JobExecution $jobExecution */
     $jobExecution = $this->stepExecution->getJobExecution();
     return $jobExecution->getExecutionContext();
 }
 public function testGetJobExecution()
 {
     $this->assertSame($this->jobExecution, $this->stepExecution->getJobExecution());
 }
 /**
  * {@inheritDoc}
  */
 public function getJobExecution()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getJobExecution', array());
     return parent::getJobExecution();
 }
 function it_sets_step_execution(StepExecution $stepExecution, JobExecution $jobExecution)
 {
     $stepExecution->getJobExecution()->willReturn($jobExecution);
     $jobExecution->getJobInstance()->shouldBeCalled();
     $this->setStepExecution($stepExecution);
 }