/** * Archive files used by job execution (input / output) * * @param JobExecution $jobExecution */ public function archive(JobExecution $jobExecution) { $job = $this->jobRegistry->get($jobExecution->getJobInstance()->getJobName()); foreach ($job->getSteps() as $step) { if (!$step instanceof ItemStep) { continue; } $reader = $step->getReader(); if ($this->isReaderUsable($reader)) { $jobParameters = $jobExecution->getJobParameters(); $filePath = $jobParameters->get('filePath'); $key = strtr($this->getRelativeArchivePath($jobExecution), ['%filename%' => basename($filePath)]); $this->filesystem->put($key, file_get_contents($filePath)); } } }
function it_create_a_file_when_reader_is_valid($jobRegistry, CsvReader $reader, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, JobParameters $jobParameters, $filesystem) { $pathname = tempnam(sys_get_temp_dir(), 'spec'); $filename = basename($pathname); $jobInstance->getJobName()->willReturn('my_job_name'); $jobRegistry->get('my_job_name')->willReturn($job); $jobExecution->getJobInstance()->willReturn($jobInstance); $jobExecution->getId()->willReturn(12); $jobInstance->getType()->willReturn('type'); $job->getSteps()->willReturn([$step]); $step->getReader()->willReturn($reader); $jobExecution->getJobParameters()->willReturn($jobParameters); $jobParameters->get('filePath')->willReturn($pathname); $filesystem->put('type' . DIRECTORY_SEPARATOR . 'my_job_name' . DIRECTORY_SEPARATOR . '12' . DIRECTORY_SEPARATOR . 'input' . DIRECTORY_SEPARATOR . $filename, '')->shouldBeCalled(); $this->archive($jobExecution); unlink($pathname); }
/** * {@inheritdoc} */ public function supports(JobExecution $jobExecution) { if ($jobExecution->getJobParameters()->has('invalid_items_file_format')) { return $this->invalidItemFileFormat === $jobExecution->getJobParameters()->get('invalid_items_file_format'); } return false; }
/** * Accessor for the job parameters * * @return JobParameters * */ public function getJobParameters() { return $this->jobExecution->getJobParameters(); }