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\EzPublishIOBundle\ApiLoader\HandlerFactory; |
10
|
|
|
use eZ\Bundle\EzPublishIOBundle\Migration\FileListerInterface; |
11
|
|
|
use eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler; |
12
|
|
|
use eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException; |
13
|
|
|
use Iterator; |
14
|
|
|
use LimitIterator; |
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
|
17
|
|
|
class BinaryFileLister extends MigrationHandler implements FileListerInterface |
18
|
|
|
{ |
19
|
|
|
/** @var \eZ\Bundle\EzPublishIOBundle\Migration\FileLister\FileIteratorInterface */ |
20
|
|
|
private $fileList; |
21
|
|
|
|
22
|
|
|
/** @var string Directory where files are stored, within the storage dir. Example: 'original' */ |
23
|
|
|
private $filesDir; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory $metadataHandlerFactory |
27
|
|
|
* @param \eZ\Bundle\EzPublishIOBundle\ApiLoader\HandlerFactory $binarydataHandlerFactory |
28
|
|
|
* @param \Psr\Log\LoggerInterface $logger |
29
|
|
|
* @param \Iterator $fileList |
30
|
|
|
* @param string $filesDir Directory where files are stored, within the storage dir. Example: 'original' |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
HandlerFactory $metadataHandlerFactory, |
34
|
|
|
HandlerFactory $binarydataHandlerFactory, |
35
|
|
|
LoggerInterface $logger = null, |
36
|
|
|
Iterator $fileList, |
37
|
|
|
$filesDir |
38
|
|
|
) { |
39
|
|
|
$this->fileList = $fileList; |
|
|
|
|
40
|
|
|
$this->filesDir = $filesDir; |
41
|
|
|
|
42
|
|
|
$this->fileList->rewind(); |
43
|
|
|
|
44
|
|
|
parent::__construct($metadataHandlerFactory, $binarydataHandlerFactory, $logger); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function countFiles() |
48
|
|
|
{ |
49
|
|
|
return count($this->fileList); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function loadMetadataList($limit = null, $offset = null) |
53
|
|
|
{ |
54
|
|
|
$metadataList = []; |
55
|
|
|
$fileLimitList = new LimitIterator($this->fileList, $offset, $limit); |
56
|
|
|
|
57
|
|
|
foreach ($fileLimitList as $fileId) { |
58
|
|
|
try { |
59
|
|
|
$metadataList[] = $this->fromMetadataHandler->load($this->filesDir . '/' . $fileId); |
60
|
|
|
} catch (BinaryFileNotFoundException $e) { |
61
|
|
|
$this->logMissingFile($fileId); |
62
|
|
|
|
63
|
|
|
continue; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $metadataList; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
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.