/**
  * Add context in version manager
  *
  * @param JobExecutionEvent $event
  */
 public function addContext(JobExecutionEvent $event)
 {
     $jobInstance = $event->getJobExecution()->getJobInstance();
     if ($jobInstance->getType() === JobInstance::TYPE_IMPORT) {
         $this->versionContext->addContextInfo(sprintf('%s "%s"', JobInstance::TYPE_IMPORT, $jobInstance->getCode()));
     }
 }
 /**
  * Delegate archiving to the registered archivers
  *
  * @param JobExecutionEvent $event
  */
 public function beforeStatusUpgrade(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     foreach ($this->archivers as $archiver) {
         $archiver->archive($jobExecution);
     }
 }
 /**
  * Use the notifiers to notify
  *
  * @param JobExecutionEvent $jobExecutionEvent
  */
 public function afterJobExecution(JobExecutionEvent $jobExecutionEvent)
 {
     $jobExecution = $jobExecutionEvent->getJobExecution();
     foreach ($this->notifiers as $notifier) {
         $notifier->notify($jobExecution);
     }
 }
 function it_register_an_event_and_verify_if_job_is_supported(JobExecutionEvent $event, JobExecution $jobExecution, ArchiverInterface $archiver)
 {
     $archiver->getName()->willReturn('output');
     $this->registerArchiver($archiver);
     $event->getJobExecution()->willReturn($jobExecution);
     $archiver->supports($jobExecution)->willReturn(true)->shouldBeCalled();
     $archiver->archive($jobExecution)->shouldBeCalled();
     $this->beforeStatusUpgrade($event);
 }
 function let(NotificationManager $manager, JobExecutionEvent $event, JobExecution $jobExecution, StepExecution $stepExecution, ArrayCollection $warnings, JobInstance $jobInstance, UserInterface $user, BatchStatus $status)
 {
     $this->beConstructedWith($manager);
     $jobExecution->getUser()->willReturn($user);
     $jobExecution->getStepExecutions()->willReturn([$stepExecution]);
     $jobExecution->getStatus()->willReturn($status);
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $stepExecution->getWarnings()->willReturn($warnings);
     $jobExecution->getId()->willReturn(5);
     $jobInstance->getType()->willReturn('export');
     $jobInstance->getLabel()->willReturn('Foo export');
     $event->getJobExecution()->willReturn($jobExecution);
 }
 /**
  * Notify a user of the end of the job
  *
  * @param JobExecutionEvent $event
  *
  * @return null
  */
 public function afterJobExecution(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $user = $jobExecution->getUser();
     if (null === $user) {
         return;
     }
     if ($jobExecution->getStatus()->isUnsuccessful()) {
         $status = 'error';
     } else {
         $status = 'success';
         foreach ($jobExecution->getStepExecutions() as $stepExecution) {
             if ($stepExecution->getWarnings()->count()) {
                 $status = 'warning';
                 break;
             }
         }
     }
     $type = $jobExecution->getJobInstance()->getType();
     $this->manager->notify([$user], sprintf('pim_import_export.notification.%s.%s', $type, $status), $status, ['route' => sprintf('pim_importexport_%s_execution_show', $type), 'routeParams' => ['id' => $jobExecution->getId()], 'messageParams' => ['%label%' => $jobExecution->getJobInstance()->getLabel()]]);
 }
 /**
  * Notify a user of the end of the job
  *
  * @param JobExecutionEvent $event
  */
 public function afterJobExecution(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $user = $jobExecution->getUser();
     if (null === $user) {
         return;
     }
     if ($jobExecution->getStatus()->isUnsuccessful()) {
         $status = 'error';
     } else {
         $status = 'success';
         foreach ($jobExecution->getStepExecutions() as $stepExecution) {
             if ($stepExecution->getWarnings()->count()) {
                 $status = 'warning';
                 break;
             }
         }
     }
     $type = $jobExecution->getJobInstance()->getType();
     // TODO: maybe create a registry or something similar to load routes ?
     $this->generateNotification($jobExecution, $user, $type, $status);
 }
 function let(VersionContext $versionContext, JobExecutionEvent $event, JobExecution $jobExecution, JobInstance $jobInstance)
 {
     $this->beConstructedWith($versionContext);
     $event->getJobExecution()->willReturn($jobExecution);
     $jobExecution->getJobInstance()->willReturn($jobInstance);
 }
Пример #9
0
 /**
  * Log the job execution before its status is upgraded
  *
  * @param JobExecutionEvent $event
  */
 public function beforeJobStatusUpgrade(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $this->logger->debug(sprintf('Upgrading JobExecution status: %s', $jobExecution));
 }
 /**
  * Set the job execution log file
  *
  * @param JobExecutionEvent $event
  */
 public function setJobExecutionLogFile(JobExecutionEvent $event)
 {
     $jobExecution = $event->getJobExecution();
     $jobExecution->setLogFile($this->logger->getFilename());
 }