1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Bundle\EzPublishIOBundle\Migration\FileLister; |
8
|
|
|
|
9
|
|
|
use eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator; |
10
|
|
|
use eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPurger\ImageFileList; |
11
|
|
|
use eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory; |
12
|
|
|
use eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface; |
13
|
|
|
use eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler; |
14
|
|
|
use eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException; |
15
|
|
|
use Iterator; |
16
|
|
|
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; |
17
|
|
|
use LimitIterator; |
18
|
|
|
use Psr\Log\LoggerInterface; |
19
|
|
|
|
20
|
|
|
class ImageFileLister extends MigrationHandler implements FileListerInterface |
21
|
|
|
{ |
22
|
|
|
/** @var ImageFileList */ |
23
|
|
|
private $imageFileList; |
24
|
|
|
|
25
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator */ |
26
|
|
|
private $variationPathGenerator; |
27
|
|
|
|
28
|
|
|
/** @var \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration */ |
29
|
|
|
private $filterConfiguration; |
30
|
|
|
|
31
|
|
|
/** @var string Directory where images are stored, within the storage dir. Example: 'images' */ |
32
|
|
|
private $imagesDir; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory $metadataHandlerFactory |
36
|
|
|
* @param \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory $binarydataHandlerFactory |
37
|
|
|
* @param \Psr\Log\LoggerInterface $logger |
38
|
|
|
* @param \Iterator $imageFileList |
39
|
|
|
* @param \eZ\Bundle\EzPublishCoreBundle\Imagine\VariationPathGenerator |
40
|
|
|
* @param \Liip\ImagineBundle\Imagine\Filter\FilterConfiguration |
41
|
|
|
* @param string $imagesDir Directory where images are stored, within the storage dir. Example: 'images' |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
HandlerFactory $metadataHandlerFactory, |
45
|
|
|
HandlerFactory $binarydataHandlerFactory, |
46
|
|
|
LoggerInterface $logger = null, |
47
|
|
|
Iterator $imageFileList, |
48
|
|
|
VariationPathGenerator $variationPathGenerator, |
49
|
|
|
FilterConfiguration $filterConfiguration, |
50
|
|
|
$imagesDir |
51
|
|
|
) { |
52
|
|
|
$this->imageFileList = $imageFileList; |
|
|
|
|
53
|
|
|
$this->variationPathGenerator = $variationPathGenerator; |
54
|
|
|
$this->filterConfiguration = $filterConfiguration; |
55
|
|
|
$this->imagesDir = $imagesDir; |
56
|
|
|
|
57
|
|
|
$this->imageFileList->rewind(); |
58
|
|
|
|
59
|
|
|
parent::__construct($metadataHandlerFactory, $binarydataHandlerFactory, $logger); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function countFiles() |
63
|
|
|
{ |
64
|
|
|
return count($this->imageFileList); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function loadMetadataList($limit = null, $offset = null) |
68
|
|
|
{ |
69
|
|
|
$metadataList = []; |
70
|
|
|
$imageLimitList = new LimitIterator($this->imageFileList, $offset, $limit); |
71
|
|
|
$aliasNames = array_keys($this->filterConfiguration->all()); |
72
|
|
|
|
73
|
|
|
foreach ($imageLimitList as $originalImageId) { |
74
|
|
|
try { |
75
|
|
|
$metadataList[] = $this->fromMetadataHandler->load($this->imagesDir . '/' . $originalImageId); |
76
|
|
|
} catch (BinaryFileNotFoundException $e) { |
77
|
|
|
$this->logMissingFile($originalImageId); |
78
|
|
|
|
79
|
|
|
continue; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
foreach ($aliasNames as $aliasName) { |
83
|
|
|
$variationImageId = $this->variationPathGenerator->getVariationPath($originalImageId, $aliasName); |
84
|
|
|
|
85
|
|
|
try { |
86
|
|
|
$metadataList[] = $this->fromMetadataHandler->load($this->imagesDir . '/' . $variationImageId); |
87
|
|
|
} catch (BinaryFileNotFoundException $e) { |
88
|
|
|
$this->logMissingFile($variationImageId); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $metadataList; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.