/**
  * {@inheritdoc}
  */
 public function supports(JobExecution $jobExecution)
 {
     foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) {
         if ($step instanceof ItemStep && $this->isUsableWriter($step->getWriter())) {
             return true;
         }
     }
     return false;
 }
 function it_returns_false_for_the_unsupported_job(ItemReaderInterface $reader, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step)
 {
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getReader()->willReturn($reader);
     $this->supports($jobExecution)->shouldReturn(false);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function updateJobExecution(JobExecution $jobExecution)
 {
     $uow = $this->getJobManager()->getUnitOfWork();
     $jobInstance = $jobExecution->getJobInstance();
     if ($jobInstance && UnitOfWork::STATE_DETACHED === $uow->getEntityState($jobInstance)) {
         /** @var JobInstance $jobInstance */
         $jobInstance = $uow->merge($jobInstance);
         $jobExecution->setJobInstance($jobInstance);
     }
     parent::updateJobExecution($jobExecution);
 }
 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);
 }
 /**
  * Archive files used by job execution (input / output)
  *
  * @param JobExecution $jobExecution
  */
 public function archive(JobExecution $jobExecution)
 {
     foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) {
         if (!$step instanceof ItemStep) {
             continue;
         }
         $reader = $step->getReader();
         if ($reader instanceof FileIteratorReader) {
             $key = strtr($this->getRelativeArchivePath($jobExecution), ['%filename%' => basename($reader->getFilePath())]);
             $this->filesystem->put($key, file_get_contents($reader->getFilePath()));
         }
     }
 }
 function it_archives_unvalid_items(InvalidItemsCollector $collector, CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Filesystem $filesystem)
 {
     $collector->getInvalidItems()->willReturn(['items']);
     $jobExecution->getId()->willReturn('id');
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $filesystem->put('type/alias/id/invalid/invalid_items.csv', '')->shouldBeCalled();
     $writer->setFilePath('/tmp/archivist/type/alias/id/invalid/invalid_items.csv')->shouldBeCalled();
     $writer->initialize()->shouldBeCalled();
     $writer->write(['items'])->shouldBeCalled();
     $writer->flush()->shouldBeCalled();
     $this->archive($jobExecution);
 }
 /**
  * {@inheritdoc}
  */
 public function archive(JobExecution $jobExecution)
 {
     foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) {
         if (!$step instanceof ItemStep) {
             continue;
         }
         $writer = $step->getWriter();
         if ($writer instanceof FileWriter && $writer instanceof ArchivableWriterInterface && count($writer->getWrittenFiles()) > 1) {
             $filesystem = $this->getZipFilesystem($jobExecution, sprintf('%s.zip', pathinfo($writer->getPath(), PATHINFO_FILENAME)));
             foreach ($writer->getWrittenFiles() as $fullPath => $localPath) {
                 $filesystem->write($localPath, file_get_contents($fullPath), true);
             }
         }
     }
 }
 /**
  * Archive files used by job execution (input / output)
  *
  * @param JobExecution $jobExecution
  */
 public function archive(JobExecution $jobExecution)
 {
     foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) {
         if (!$step instanceof ItemStep) {
             continue;
         }
         $writer = $step->getWriter();
         if ($writer instanceof ArchivableWriterInterface && count($writer->getWrittenFiles()) > 1) {
             continue;
         }
         if ($writer instanceof FileWriter && is_file($path = $writer->getPath())) {
             $key = strtr($this->getRelativeArchivePath($jobExecution), array('%filename%' => basename($writer->getPath())));
             $this->filesystem->write($key, file_get_contents($path), true);
         }
     }
 }
 function it_creates_a_file_if_writer_is_correct(CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $factory, $filesystem)
 {
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getWriter()->willReturn($writer);
     $writer->getWrittenFiles()->willReturn(['/tmp/tmp' => 'tmp', '/tmp/tmp2' => 'tmp2']);
     $writer->getPath()->willReturn('/tmp/tmp');
     $adapter = new LocalAdapter('/tmp');
     $fs = new Filesystem($adapter);
     $fs->write('tmp', '', true);
     $fs->write('tmp2', '', true);
     $factory->createZip(Argument::any())->willReturn($filesystem);
     $filesystem->write('tmp', '', true)->shouldBeCalled();
     $filesystem->write('tmp2', '', true)->shouldBeCalled();
     $this->archive($jobExecution);
 }
 function it_creates_a_file_if_writer_is_correct(CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $factory, $filesystem)
 {
     $file1 = tempnam(sys_get_temp_dir(), 'spec');
     $file2 = tempnam(sys_get_temp_dir(), 'spec');
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getWriter()->willReturn($writer);
     $writer->getWrittenFiles()->willReturn([$file1 => 'file1', $file2 => 'file2']);
     $writer->getPath()->willReturn(sys_get_temp_dir());
     $filesystem->has('type/alias/12/archive')->willReturn(false);
     $filesystem->createDir('type/alias/12/archive')->shouldBeCalled();
     $factory->createZip(Argument::any())->willReturn($filesystem);
     $filesystem->put('file1', '')->shouldBeCalled();
     $filesystem->put('file2', '')->shouldBeCalled();
     $this->archive($jobExecution);
     unlink($file1);
     unlink($file2);
 }
 /**
  * @param JobExecution         $jobExecution
  * @param string|UserInterface $user
  * @param string               $type
  * @param string               $status
  */
 protected function generateMassEditNotify(JobExecution $jobExecution, $user, $type, $status)
 {
     $this->manager->notify([$user], sprintf('pim_mass_edit.notification.%s.%s', $type, $status), $status, ['route' => 'pim_enrich_job_tracker_show', 'routeParams' => ['id' => $jobExecution->getId()], 'messageParams' => ['%label%' => $jobExecution->getJobInstance()->getLabel()]]);
 }
 /**
  * Get the relative archive path in the file system
  *
  * @param JobExecution $jobExecution
  *
  * @return string
  */
 protected function getRelativeArchivePath(JobExecution $jobExecution)
 {
     $jobInstance = $jobExecution->getJobInstance();
     return sprintf('%s/%s/%s/%s/%%filename%%', $jobInstance->getType(), $jobInstance->getAlias(), $jobExecution->getId(), $this->getName());
 }
 /**
  * Get the relative archive path in the file system
  *
  * @param JobExecution $jobExecution
  *
  * @return string
  */
 protected function getRelativeArchivePath(JobExecution $jobExecution)
 {
     $jobInstance = $jobExecution->getJobInstance();
     return $jobInstance->getType() . DIRECTORY_SEPARATOR . $jobInstance->getAlias() . DIRECTORY_SEPARATOR . $jobExecution->getId() . DIRECTORY_SEPARATOR . $this->getName() . DIRECTORY_SEPARATOR . '%filename%';
 }
 /**
  * {@inheritDoc}
  */
 public function getJobInstance()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getJobInstance', array());
     return parent::getJobInstance();
 }