|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Transfer. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE file located |
|
7
|
|
|
* in the root directory. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Transfer\EzPlatform\Repository\Manager\Core; |
|
11
|
|
|
|
|
12
|
|
|
use eZ\Publish\API\Repository\Repository; |
|
13
|
|
|
use Transfer\Data\ObjectInterface; |
|
14
|
|
|
use Transfer\Data\TreeObject; |
|
15
|
|
|
use Transfer\EzPlatform\Exception\UnsupportedObjectOperationException; |
|
16
|
|
|
use Transfer\EzPlatform\Repository\Values\ContentObject; |
|
17
|
|
|
use Transfer\EzPlatform\Repository\Values\EzPlatformObject; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Content tree service. |
|
21
|
|
|
* |
|
22
|
|
|
* @internal |
|
23
|
|
|
*/ |
|
24
|
|
|
class ContentTreeService extends AbstractRepositoryService |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var ObjectService Object service |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $objectService; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param Repository $repository |
|
33
|
|
|
* @param array $options |
|
34
|
|
|
* @param ObjectService $objectService Object service |
|
35
|
|
|
*/ |
|
36
|
74 |
|
public function __construct(Repository $repository, array $options, ObjectService $objectService) |
|
37
|
|
|
{ |
|
38
|
74 |
|
parent::__construct($repository, $options); |
|
39
|
74 |
|
$this->objectService = $objectService; |
|
40
|
74 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
4 |
|
public function createOrUpdate($object) |
|
46
|
|
|
{ |
|
47
|
4 |
|
if (!$object instanceof TreeObject) { |
|
48
|
1 |
|
throw new UnsupportedObjectOperationException(TreeObject::class, get_class($object)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
$this->publishContentObjects($object); |
|
52
|
3 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Publishes content objects. |
|
56
|
|
|
* |
|
57
|
|
|
* @param TreeObject $object |
|
58
|
|
|
* |
|
59
|
|
|
* @throws \InvalidArgumentException |
|
60
|
|
|
*/ |
|
61
|
3 |
|
private function publishContentObjects(TreeObject $object) |
|
62
|
|
|
{ |
|
63
|
3 |
|
$last = $this->objectService->createOrUpdate($object->data); |
|
64
|
|
|
|
|
65
|
3 |
|
foreach ($object->getNodes() as $subObject) { |
|
66
|
3 |
|
if ($subObject instanceof TreeObject) { |
|
67
|
2 |
|
$this->publishContentObjects($subObject); |
|
68
|
2 |
|
} else { |
|
69
|
|
|
/* @var ContentObject $subObject */ |
|
70
|
2 |
|
$subObject->addParentLocation($last->getProperty('content_info')->mainLocationId); |
|
71
|
2 |
|
$this->objectService->createOrUpdate($subObject); |
|
72
|
|
|
} |
|
73
|
3 |
|
} |
|
74
|
3 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Bulk-deletions is not supported. |
|
78
|
|
|
* |
|
79
|
|
|
* @param ObjectInterface $object |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function remove($object) |
|
82
|
|
|
{ |
|
83
|
1 |
|
if ($this->logger) { |
|
84
|
1 |
|
$this->logger->warning(sprintf( |
|
85
|
1 |
|
'Attempted to delete using %s, which is not supported. Use the implementations of %s instead.', |
|
86
|
1 |
|
__CLASS__, |
|
87
|
|
|
EzPlatformObject::class |
|
88
|
1 |
|
)); |
|
89
|
1 |
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
return; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|