public function testMarkAsFailed()
 {
     $jobExecution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution');
     $jobExecution->expects($this->once())->method('setStatus');
     $jobExecution->expects($this->once())->method('setExitStatus');
     $jobExecution->expects($this->once())->method('setEndTime');
     $jobExecution->expects($this->once())->method('addFailureException');
     $jobExecutionManager = new JobExecutionManager($this->entityManager);
     $jobExecutionManager->markAsFailed($jobExecution);
 }
 /**
  * Show a report
  *
  * @param Request $request
  * @param integer $id
  *
  * @return template
  */
 public function showAction(Request $request, $id)
 {
     $jobExecution = $this->findOr404('AkeneoBatchBundle:JobExecution', $id);
     $this->eventDispatcher->dispatch(JobExecutionEvents::PRE_SHOW, new GenericEvent($jobExecution));
     if ('json' === $request->getRequestFormat()) {
         $archives = [];
         foreach ($this->archivist->getArchives($jobExecution) as $key => $files) {
             $label = $this->translator->transchoice(sprintf('pim_import_export.download_archive.%s', $key), count($files));
             $archives[$key] = ['label' => ucfirst($label), 'files' => $files];
         }
         if (!$this->jobExecutionManager->checkRunningStatus($jobExecution)) {
             $this->jobExecutionManager->markAsFailed($jobExecution);
         }
         return new JsonResponse(['jobExecution' => $this->serializer->normalize($jobExecution, 'json'), 'hasLog' => file_exists($jobExecution->getLogFile()), 'archives' => $archives]);
     }
     return $this->render(sprintf('PimImportExportBundle:%sExecution:show.html.twig', ucfirst($this->getJobType())), array('execution' => $jobExecution));
 }
 /**
  * Show a job execution report
  *
  * @param Request $request
  * @param int     $id
  *
  * @return \Symfony\Component\HttpFoundation\Response|JsonResponse
  */
 public function showAction(Request $request, $id)
 {
     $jobExecution = $this->findOr404('Akeneo\\Component\\Batch\\Model\\JobExecution', $id);
     $this->eventDispatcher->dispatch(JobExecutionEvents::PRE_SHOW, new GenericEvent($jobExecution));
     if ('json' === $request->getRequestFormat()) {
         $archives = [];
         foreach ($this->archivist->getArchives($jobExecution) as $archiveName => $files) {
             $label = $this->translator->transchoice(sprintf('pim_mass_edit.download_archive.%s', $archiveName), count($files));
             $archives[$archiveName] = ['label' => ucfirst($label), 'files' => $files];
         }
         if (!$this->jobExecutionManager->checkRunningStatus($jobExecution)) {
             $this->jobExecutionManager->markAsFailed($jobExecution);
         }
         // limit the number of step execution returned to avoid memory overflow
         $context = ['limit_warnings' => 100];
         return new JsonResponse(['jobExecution' => $this->serializer->normalize($jobExecution, 'json', $context), 'hasLog' => file_exists($jobExecution->getLogFile()), 'archives' => $archives]);
     }
     return $this->render(sprintf('PimEnrichBundle:MassEditExecution:show.html.twig', ucfirst($this->getJobType())), ['execution' => $jobExecution]);
 }
 /**
  * Show a report
  *
  * @param Request $request
  * @param int     $id
  *
  * @return \Symfony\Component\HttpFoundation\Response|JsonResponse
  */
 public function showAction(Request $request, $id)
 {
     $jobExecution = $this->jobExecutionRepo->find($id);
     if (null === $jobExecution) {
         throw new NotFoundHttpException('Akeneo\\Component\\Batch\\Model\\JobExecution entity not found');
     }
     $this->eventDispatcher->dispatch(JobExecutionEvents::PRE_SHOW, new GenericEvent($jobExecution));
     if ('json' === $request->getRequestFormat()) {
         $archives = [];
         foreach ($this->archivist->getArchives($jobExecution) as $key => $files) {
             $label = $this->translator->transChoice(sprintf('pim_import_export.download_archive.%s', $key), count($files));
             $archives[$key] = ['label' => ucfirst($label), 'files' => $files];
         }
         if (!$this->jobExecutionManager->checkRunningStatus($jobExecution)) {
             $this->jobExecutionManager->markAsFailed($jobExecution);
         }
         // limit the number of step execution returned to avoid memory overflow
         $context = ['limit_warnings' => 100];
         return new JsonResponse(['jobExecution' => $this->serializer->normalize($jobExecution, 'json', $context), 'hasLog' => file_exists($jobExecution->getLogFile()), 'archives' => $archives]);
     }
     return $this->templating->renderResponse(sprintf('PimImportExportBundle:%sExecution:show.html.twig', ucfirst($this->getJobType())), ['execution' => $jobExecution]);
 }