1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pim\Bundle\ExcelConnectorBundle\Archiver; |
4
|
|
|
|
5
|
|
|
use Akeneo\Component\Batch\Model\JobExecution; |
6
|
|
|
use Akeneo\Component\Batch\Step\ItemStep; |
7
|
|
|
use League\Flysystem\Filesystem; |
8
|
|
|
use Pim\Bundle\BaseConnectorBundle\Archiver\AbstractFilesystemArchiver; |
9
|
|
|
use Pim\Bundle\ExcelConnectorBundle\Reader\FileIteratorReader; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Archive job execution files into conventional directories |
13
|
|
|
* |
14
|
|
|
* @author Antoine Guigan <[email protected]> |
15
|
|
|
* @copyright 2014 Akeneo SAS (http://www.akeneo.com) |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
*/ |
18
|
|
|
class FileIteratorReaderArchiver extends AbstractFilesystemArchiver |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param Filesystem $filesystem |
22
|
|
|
*/ |
23
|
|
|
public function __construct(Filesystem $filesystem) |
24
|
|
|
{ |
25
|
|
|
$this->filesystem = $filesystem; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function supports(JobExecution $jobExecution) |
32
|
|
|
{ |
33
|
|
|
return true; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Archive files used by job execution (input / output) |
38
|
|
|
* |
39
|
|
|
* @param JobExecution $jobExecution |
40
|
|
|
*/ |
41
|
|
|
public function archive(JobExecution $jobExecution) |
42
|
|
|
{ |
43
|
|
|
foreach ($jobExecution->getJobInstance()->getJob()->getSteps() as $step) { |
44
|
|
|
if (!$step instanceof ItemStep) { |
45
|
|
|
continue; |
46
|
|
|
} |
47
|
|
|
$reader = $step->getReader(); |
48
|
|
|
|
49
|
|
|
if ($reader instanceof FileIteratorReader) { |
50
|
|
|
$key = strtr( |
51
|
|
|
$this->getRelativeArchivePath($jobExecution), |
52
|
|
|
[ |
53
|
|
|
'%filename%' => basename($reader->getFilePath()), |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
$this->filesystem->put($key, file_get_contents($reader->getFilePath())); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function getName() |
65
|
|
|
{ |
66
|
|
|
return 'excel_input'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|