|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the BinaryFileMigrationHandler class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishIOBundle\Migration\MigrationHandler; |
|
12
|
|
|
use eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException; |
|
13
|
|
|
use eZ\Publish\SPI\IO\BinaryFile; |
|
14
|
|
|
use eZ\Publish\SPI\IO\BinaryFileCreateStruct; |
|
15
|
|
|
|
|
16
|
|
|
class BinaryFileMigrationHandler extends MigrationHandler |
|
17
|
|
|
{ |
|
18
|
|
|
public function countFiles() //TODO move to parent? |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->fromMetadataHandler->count($this->scope); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function loadMetadataList($limit = null, $offset = null) //TODO move to parent? |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->fromMetadataHandler->loadList($this->scope, $limit, $offset); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function migrateFile(BinaryFile $binaryFile) |
|
29
|
|
|
{ |
|
30
|
|
|
try { |
|
31
|
|
|
$binaryFileResource = $this->fromBinarydataHandler->getResource($binaryFile->id); |
|
32
|
|
|
} catch (BinaryFileNotFoundException $e) { |
|
33
|
|
|
//TODO log |
|
34
|
|
|
|
|
35
|
|
|
return false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$binaryFileCreateStruct = new BinaryFileCreateStruct(); |
|
39
|
|
|
$binaryFileCreateStruct->id = $binaryFile->id; |
|
40
|
|
|
$binaryFileCreateStruct->setInputStream($binaryFileResource); |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
$this->toBinarydataHandler->create($binaryFileCreateStruct); |
|
44
|
|
|
} catch (\RuntimeException $e) { |
|
45
|
|
|
//TODO log |
|
46
|
|
|
|
|
47
|
|
|
return false; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$metadataCreateStruct = new BinaryFileCreateStruct(); |
|
51
|
|
|
$metadataCreateStruct->id = $binaryFile->id; |
|
52
|
|
|
$metadataCreateStruct->size = $binaryFile->size; |
|
53
|
|
|
$metadataCreateStruct->mtime = $binaryFile->mtime; |
|
54
|
|
|
$metadataCreateStruct->mimeType = $this->fromMetadataHandler->getMimeType($binaryFile->id); |
|
55
|
|
|
|
|
56
|
|
|
try { |
|
57
|
|
|
$this->toMetadataHandler->create($metadataCreateStruct); |
|
58
|
|
|
} catch (\RuntimeException $e) { |
|
59
|
|
|
//TODO log |
|
60
|
|
|
|
|
61
|
|
|
return false; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return true; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|