Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

TreeHandler.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Legacy\Content;
8
9 use eZ\Publish\API\Repository\Exceptions\NotFoundException;
10 use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway;
11 use eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper;
12 use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
13 use eZ\Publish\Core\Persistence\Legacy\Content\Mapper as ContentMapper;
14
19 class TreeHandler
20 {
26 protected $locationGateway;
27
33 protected $locationMapper;
34
40 protected $contentGateway;
41
47 protected $contentMapper;
48
54 protected $fieldHandler;
55
63 public function __construct(
64 LocationGateway $locationGateway,
65 LocationMapper $locationMapper,
66 ContentGateway $contentGateway,
67 ContentMapper $contentMapper,
68 FieldHandler $fieldHandler
69 ) {
70 $this->locationGateway = $locationGateway;
71 $this->locationMapper = $locationMapper;
72 $this->contentGateway = $contentGateway;
73 $this->contentMapper = $contentMapper;
74 $this->fieldHandler = $fieldHandler;
75 }
76
86 public function loadContentInfo($contentId)
87 {
88 return $this->contentMapper->extractContentInfoFromRow(
89 $this->contentGateway->loadContentInfo($contentId)
90 );
91 }
92
98 public function removeRawContent($contentId)
99 {
100 $this->locationGateway->removeElementFromTrash(
101 $this->loadContentInfo($contentId)->mainLocationId
102 );
103
104 foreach ($this->listVersions($contentId) as $versionInfo) {
105 $this->fieldHandler->deleteFields($contentId, $versionInfo);
106 }
107 // Must be called before deleteRelations()
108 $this->contentGateway->removeReverseFieldRelations($contentId);
109 $this->contentGateway->deleteRelations($contentId);
110 $this->contentGateway->deleteVersions($contentId);
111 $this->contentGateway->deleteNames($contentId);
112 $this->contentGateway->deleteContent($contentId);
113 }
114
126 public function listVersions($contentId, $status = null, $limit = -1)
127 {
128 $rows = $this->contentGateway->listVersions($contentId, $status, $limit);
129 if (empty($rows)) {
130 return [];
131 }
132
133 $idVersionPairs = array_map(
134 function ($row) use ($contentId) {
135 return [
136 'id' => $contentId,
137 'version' => $row['ezcontentobject_version_version'],
138 ];
139 },
140 $rows
141 );
142 $nameRows = $this->contentGateway->loadVersionedNameData($idVersionPairs);
143
144 return $this->contentMapper->extractVersionInfoListFromRows(
145 $rows,
146 $nameRows
147 );
148 }
149
161 public function loadLocation($locationId, array $translations = null, bool $useAlwaysAvailable = true)
162 {
163 $data = $this->locationGateway->getBasicNodeData($locationId, $translations, $useAlwaysAvailable);
164
165 return $this->locationMapper->createLocationFromRow($data);
166 }
167
183 public function removeSubtree($locationId)
184 {
185 $locationRow = $this->locationGateway->getBasicNodeData($locationId);
186 $contentId = $locationRow['contentobject_id'];
187 $mainLocationId = $locationRow['main_node_id'];
188
189 $subLocations = $this->locationGateway->getChildren($locationId);
190 foreach ($subLocations as $subLocation) {
191 $this->removeSubtree($subLocation['node_id']);
192 }
193
194 if ($locationId == $mainLocationId) {
195 if (1 == $this->locationGateway->countLocationsByContentId($contentId)) {
196 $this->removeRawContent($contentId);
197 } else {
198 $newMainLocationRow = $this->locationGateway->getFallbackMainNodeData(
199 $contentId,
200 $locationId
201 );
202
203 $this->changeMainLocation(
204 $contentId,
205 $newMainLocationRow['node_id']
206 );
207 }
208 }
209
210 $this->locationGateway->removeLocation($locationId);
211 $this->locationGateway->deleteNodeAssignment($contentId);
212 }
213
222 public function setSectionForSubtree($locationId, $sectionId)
223 {
224 $nodeData = $this->locationGateway->getBasicNodeData($locationId);
225
226 $this->locationGateway->setSectionForSubtree($nodeData['path_string'], $sectionId);
227 }
228
239 public function changeMainLocation($contentId, $locationId)
240 {
241 $parentLocationId = $this->loadLocation($locationId)->parentId;
242
243 // Update ezcontentobject_tree and eznode_assignment tables
244 $this->locationGateway->changeMainLocation(
245 $contentId,
246 $locationId,
247 $this->loadContentInfo($contentId)->currentVersionNo,
248 $parentLocationId
249 );
250
251 // Update subtree section to the one of the new main location parent location content
252 $destinationContentId = $this->loadLocation($parentLocationId)->contentId;
253 try {
254 $sectionId = $this->loadContentInfo($destinationContentId)->sectionId;
255 } catch (NotFoundException $e) {
256 $sectionId = null;
257 }
258
259 if ($sectionId !== null) {
260 $this->setSectionForSubtree(
261 $locationId,
262 $sectionId
263 );
264 }
265 }
266 }
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler
Field Handler.
Definition: FieldHandler.php:22
eZ\Publish\Core\Persistence\Legacy\Content\Gateway
Base class for content gateways.
Definition: Persistence/Legacy/Content/Gateway.php:21
eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper
Mapper for Location objects.
Definition: Publish/Core/Persistence/Legacy/Content/Location/Mapper.php:16
eZ\Publish\Core\Persistence\Legacy\Content\Mapper
Mapper for Content Handler.
Definition: Publish/Core/Persistence/Legacy/Content/Mapper.php:27
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler
The TreeHandler is an intersect between ContentHandler and LocationHandler, used to avoid circular de...
Definition: TreeHandler.php:20
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\$contentGateway
$contentGateway
Definition: TreeHandler.php:40
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\__construct
__construct(LocationGateway $locationGateway, LocationMapper $locationMapper, ContentGateway $contentGateway, ContentMapper $contentMapper, FieldHandler $fieldHandler)
Definition: TreeHandler.php:63
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\$contentMapper
$contentMapper
Definition: TreeHandler.php:47
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\$locationGateway
$locationGateway
Definition: TreeHandler.php:26
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\loadLocation
loadLocation($locationId, array $translations=null, bool $useAlwaysAvailable=true)
Loads the data for the location identified by $locationId.
Definition: TreeHandler.php:161
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\changeMainLocation
changeMainLocation($contentId, $locationId)
Changes main location of content identified by given $contentId to location identified by given $loca...
Definition: TreeHandler.php:239
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\removeSubtree
removeSubtree($locationId)
Removes all Locations under and including $locationId.
Definition: TreeHandler.php:183
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\$fieldHandler
$fieldHandler
Definition: TreeHandler.php:54
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\listVersions
listVersions($contentId, $status=null, $limit=-1)
Returns the versions for $contentId.
Definition: TreeHandler.php:126
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\removeRawContent
removeRawContent($contentId)
Deletes raw content data.
Definition: TreeHandler.php:98
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\$locationMapper
$locationMapper
Definition: TreeHandler.php:33
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\setSectionForSubtree
setSectionForSubtree($locationId, $sectionId)
Set section on all content objects in the subtree.
Definition: TreeHandler.php:222
eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler\loadContentInfo
loadContentInfo($contentId)
Returns the metadata object for a content identified by $contentId.
Definition: TreeHandler.php:86
eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway
Definition: Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php:7
eZ\Publish\Core\Persistence\Legacy\Content
Definition: FieldHandler.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.