/**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * @param string $operationAlias
  *
  * @AclAncestor("pim_enrich_mass_edit")
  *
  * @throws NotFoundResourceException
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function performAction($operationAlias)
 {
     $gridName = $this->request->get('gridName');
     $operation = $this->operationRegistry->get($operationAlias);
     $itemsName = $operation->getItemsName();
     $productCount = $this->request->get('objectsCount');
     $form = $this->massEditFormResolver->getConfigurationForm($operationAlias);
     $form->remove('operationAlias');
     $form->submit($this->request);
     if ($form->isValid()) {
         $operation = $form->getData();
         $pimFilters = $this->gridFilterAdapter->adapt($this->request);
         $operation->setFilters($pimFilters);
         $jobCode = $operation->getBatchJobCode();
         $jobInstance = $this->getRepository('Akeneo\\Component\\Batch\\Model\\JobInstance')->findOneBy(['code' => $jobCode]);
         if (null === $jobInstance) {
             throw new NotFoundResourceException(sprintf('No job found with job code "%s"', $jobCode));
         }
         $operation->finalize();
         $rawConfiguration = $operation->getBatchConfig();
         $this->simpleJobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration);
     }
     if ($form->isValid()) {
         $this->addFlash('success', sprintf('pim_enrich.mass_edit_action.%s.launched_flash', $operationAlias));
         $route = $this->getRouteFromMapping($gridName);
         return $this->redirectToRoute($route);
     }
     return $this->render(sprintf('PimEnrichBundle:MassEditAction:configure/%s.html.twig', $operationAlias), ['form' => $form->createView(), 'operationAlias' => $operationAlias, 'itemsName' => $itemsName, 'productCount' => $productCount, 'queryParams' => $this->getQueryParams()]);
 }
 /**
  * Allow to validate and run the job
  *
  * @param bool        $isUpload
  * @param JobInstance $jobInstance
  *
  * @return JobInstance
  */
 protected function launchJob($isUpload, JobInstance $jobInstance)
 {
     $this->eventDispatcher->dispatch(JobProfileEvents::PRE_EXECUTE, new GenericEvent($jobInstance));
     $rawConfig = $isUpload ? addslashes(json_encode($jobInstance->getJob()->getConfiguration())) : '';
     $jobExecution = $this->simpleJobLauncher->setConfig(['email' => true])->launch($jobInstance, $this->getUser(), $rawConfig);
     $this->eventDispatcher->dispatch(JobProfileEvents::POST_EXECUTE, new GenericEvent($jobInstance));
     $this->addFlash('success', sprintf('The %s is running.', $this->getJobType()));
     return $jobExecution;
 }
 /**
  * Allow to validate and run the job
  *
  * @param bool        $isUpload
  * @param JobInstance $jobInstance
  *
  * @return JobInstance
  */
 protected function launchJob($isUpload, JobInstance $jobInstance)
 {
     $this->eventDispatcher->dispatch(JobProfileEvents::PRE_EXECUTE, new GenericEvent($jobInstance));
     $rawConfig = $isUpload ? addslashes(json_encode($jobInstance->getJob()->getConfiguration())) : '';
     $jobExecution = $this->simpleJobLauncher->setConfig(['email' => true])->launch($jobInstance, $this->tokenStorage->getToken()->getUser(), $rawConfig);
     $this->eventDispatcher->dispatch(JobProfileEvents::POST_EXECUTE, new GenericEvent($jobInstance));
     $this->request->getSession()->getFlashBag()->add('success', new Message(sprintf('flash.%s.running', $this->getJobType())));
     return $jobExecution;
 }
 /**
  * Allow to validate and run the job
  *
  * @param JobInstance $jobInstance
  *
  * @return JobInstance
  */
 protected function launchJob(JobInstance $jobInstance)
 {
     $this->eventDispatcher->dispatch(JobProfileEvents::PRE_EXECUTE, new GenericEvent($jobInstance));
     $configuration = $jobInstance->getRawParameters();
     $configuration['send_email'] = true;
     $jobExecution = $this->simpleJobLauncher->launch($jobInstance, $this->tokenStorage->getToken()->getUser(), $configuration);
     $this->eventDispatcher->dispatch(JobProfileEvents::POST_EXECUTE, new GenericEvent($jobInstance));
     $this->request->getSession()->getFlashBag()->add('success', new Message(sprintf('flash.%s.running', $this->getJobType())));
     return $jobExecution;
 }