/**
  * Launch the quick export
  *
  * @return Response
  */
 public function indexAction()
 {
     $displayedColumnsOnly = (bool) $this->request->get('_displayedColumnsOnly');
     $jobCode = $this->request->get('_jobCode');
     $jobInstance = $this->jobInstanceRepo->findOneByIdentifier(['code' => $jobCode]);
     if (null === $jobInstance) {
         throw new \RuntimeException(sprintf('Jobinstance "%s" is not well configured', $jobCode));
     }
     $filters = $this->gridFilterAdapter->adapt($this->request);
     $rawParameters = $jobInstance->getRawParameters();
     $contextParameters = $this->getContextParameters();
     $rawParameters['filePath'] = $this->buildFilePath($rawParameters['filePath'], $contextParameters);
     $dynamicConfiguration = $contextParameters + ['filters' => $filters];
     if ($displayedColumnsOnly) {
         $gridName = null !== $this->request->get('gridName') ? $this->request->get('gridName') : 'product-grid';
         if (isset($this->request->get($gridName)['_parameters'])) {
             $columns = explode(',', $this->request->get($gridName)['_parameters']['view']['columns']);
         } else {
             $columns = array_keys($this->datagridManager->getConfigurationForGrid($gridName)['columns']);
         }
         $dynamicConfiguration = array_merge($dynamicConfiguration, ['selected_properties' => $columns]);
     }
     $configuration = array_merge($rawParameters, $dynamicConfiguration);
     $this->jobLauncher->launch($jobInstance, $this->getUser(), $configuration);
     return new Response();
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator && Operators::SINCE_LAST_JOB !== $operator && Operators::SINCE_LAST_N_DAYS !== $operator) {
         $value = $this->formatValues($field, $value);
     }
     if (Operators::SINCE_LAST_JOB === $operator) {
         if (!is_string($value)) {
             throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value));
         }
         $jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]);
         $lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED);
         if (null === $lastCompletedJobExecution) {
             return $this;
         }
         $lastJobStartTime = $lastCompletedJobExecution->getStartTime()->setTimezone(new \DateTimeZone('UTC'));
         $value = $lastJobStartTime->getTimestamp();
         $operator = Operators::GREATER_THAN;
     }
     if (Operators::SINCE_LAST_N_DAYS === $operator) {
         if (!is_numeric($value)) {
             throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value));
         }
         $fromDate = new \DateTime(sprintf('%s days ago', $value), new \DateTimeZone('UTC'));
         $value = $fromDate->getTimestamp();
         $operator = Operators::GREATER_THAN;
     }
     $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
     $this->applyFilter($field, $operator, $value);
     return $this;
 }
 /**
  * Launch the quick export
  *
  * @return Response
  */
 public function indexAction()
 {
     $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => 'csv_product_quick_export']);
     $filters = $this->gridFilterAdapter->adapt($this->request);
     $rawConfiguration = addslashes(json_encode(['filters' => $filters, 'mainContext' => $this->getContextParameters()]));
     $this->jobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration);
     return new Response();
 }
 /**
  * {@inheritdoc}
  */
 public function doExecute(Request $request)
 {
     $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => $this->getOption('job_profile')]);
     if (null === $jobInstance) {
         throw new \LogicException(sprintf('The job instance "%s" does not exist. Please contact your administrator', $this->getOption('job_profile')));
     }
     $rawConfiguration = addslashes(json_encode(['reference_data' => $this->configuration->getEntityClass(), 'ids' => $this->massActionDispatcher->dispatch($request)]));
     $this->jobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration);
     return new Response();
 }
 /**
  * {@inheritdoc}
  */
 public function purge($jobInstanceCode)
 {
     $jobInstance = $this->jobInstanceRepository->findOneByCode($jobInstanceCode);
     if (null === $jobInstance) {
         throw new EntityNotFoundException(sprintf('Job instance %s hasn\'t been found, verify your code.', $jobInstanceCode));
     }
     $jobId = $jobInstance->getId();
     foreach ($this->classesToPurge as $class) {
         $this->purgeDelta($jobId, $class);
     }
 }
 /**
  * Launch the quick export
  *
  * @return Response
  */
 public function indexAction()
 {
     $jobCode = $this->request->get('_jobCode');
     $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => $jobCode]);
     if (null === $jobInstance) {
         throw new \RuntimeException(sprintf('Jobinstance "%s" is not well configured', $jobCode));
     }
     $filters = $this->gridFilterAdapter->adapt($this->request);
     $rawConfiguration = addslashes(json_encode(['filters' => $filters, 'mainContext' => $this->getContextParameters()]));
     $this->jobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration);
     return new Response();
 }
 /**
  * Remove mapping from database.
  *
  * @param string $jobInstanceCode
  *
  * @throws EntityNotFoundException
  */
 public function purge($jobInstanceCode)
 {
     $jobInstance = $this->jobInstanceRepository->findOneByCode($jobInstanceCode);
     if (null === $jobInstance) {
         throw new EntityNotFoundException(sprintf('Job instance %s hasn\'t been found, verify your code.', $jobInstanceCode));
     }
     $rawConfiguration = $jobInstance->getRawConfiguration();
     $soapUrl = $rawConfiguration['magentoUrl'] . $rawConfiguration['wsdlUrl'];
     foreach ($this->classesToPurge as $class) {
         $this->purgeMapping($soapUrl, $class);
     }
 }
 /**
  * Launch the background process for the given $operation
  *
  * @param BatchableOperationInterface $operation
  *
  * @throws NotFoundResourceException
  */
 public function launch(BatchableOperationInterface $operation)
 {
     $jobInstanceCode = $operation->getJobInstanceCode();
     $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => $jobInstanceCode]);
     if (null === $jobInstance) {
         throw new NotFoundResourceException(sprintf('No JobInstance found with code "%s"', $jobInstanceCode));
     }
     if ($operation instanceof ConfigurableOperationInterface) {
         $operation->finalize();
     }
     $configuration = $operation->getBatchConfig();
     $this->jobLauncher->launch($jobInstance, $this->tokenStorage->getToken()->getUser(), $configuration);
 }
 /**
  * Add a filter for products updated since the last export to the query builder
  *
  * @param string $field
  * @param string $value
  */
 protected function addUpdatedSinceLastJob($field, $value)
 {
     $jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]);
     $lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED);
     if (null === $lastCompletedJobExecution) {
         return;
     }
     $lastJobStartTime = $lastCompletedJobExecution->getStartTime();
     $lastJobStartTime->setTimezone(new \DateTimeZone('UTC'));
     $updatedField = current($this->qb->getRootAliases()) . '.' . $field;
     $this->applyGreaterThanFilter($updatedField, $lastJobStartTime->format(static::DATETIME_FORMAT));
 }
 /**
  * Get a job instance
  *
  * @param int  $id
  * @param bool $checkStatus
  *
  * @throws NotFoundHttpException
  *
  * @return JobInstance|RedirectResponse
  */
 protected function getJobInstance($id, $checkStatus = true)
 {
     $jobInstance = $this->jobInstanceRepository->find($id);
     if (null === $jobInstance) {
         throw new NotFoundHttpException('Akeneo\\Component\\Batch\\Model\\JobInstance entity not found');
     }
     // Fixme: should look at the job execution to see the status of a job instance execution
     if ($checkStatus && $jobInstance->getStatus() === JobInstance::STATUS_IN_PROGRESS) {
         throw new NotFoundHttpException(sprintf('The %s "%s" is currently in progress', $jobInstance->getType(), $jobInstance->getLabel()));
     }
     $job = $this->jobRegistry->get($jobInstance->getJobName());
     if (!$job) {
         throw new NotFoundHttpException(sprintf('The following %s does not exist anymore. Please check configuration:<br />' . 'Connector: %s<br />' . 'Type: %s<br />' . 'Alias: %s', $this->getJobType(), $jobInstance->getConnector(), $jobInstance->getType(), $jobInstance->getJobName()));
     }
     return $jobInstance;
 }