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

TrashHandler.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Cache;
8
9 use eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler as TrashHandlerInterface;
10 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
11 use eZ\Publish\SPI\Persistence\Content\Relation;
12
16 class TrashHandler extends AbstractHandler implements TrashHandlerInterface
17 {
18 private const EMPTY_TRASH_BULK_SIZE = 100;
19 private const CONTENT_IDENTIFIER = 'content';
20 private const LOCATION_PATH_IDENTIFIER = 'location_path';
21
25 public function loadTrashItem($id)
26 {
27 $this->logger->logCall(__METHOD__, ['id' => $id]);
28
29 return $this->persistenceHandler->trashHandler()->loadTrashItem($id);
30 }
31
35 public function trashSubtree($locationId)
36 {
37 $this->logger->logCall(__METHOD__, ['locationId' => $locationId]);
38
39 $location = $this->persistenceHandler->locationHandler()->load($locationId);
40 $reverseRelations = $this->persistenceHandler->contentHandler()->loadRelations($location->contentId);
41
42 $return = $this->persistenceHandler->trashHandler()->trashSubtree($locationId);
43
44 $relationTags = [];
45 if (!empty($reverseRelations)) {
46 $relationTags = array_map(function (Relation $relation) {
47 return $this->cacheIdentifierGenerator->generateTag(
48 self::CONTENT_IDENTIFIER,
49 [$relation->destinationContentId]
50 );
51 }, $reverseRelations);
52 }
53
54 $tags = array_merge(
55 [
56 $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$location->contentId]),
57 $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$locationId]),
58 ],
59 $relationTags
60 );
61 $this->cache->invalidateTags(array_values(array_unique($tags)));
62
63 return $return;
64 }
65
69 public function recover($trashedId, $newParentId)
70 {
71 $this->logger->logCall(__METHOD__, ['id' => $trashedId, 'newParentId' => $newParentId]);
72
73 $return = $this->persistenceHandler->trashHandler()->recover($trashedId, $newParentId);
74
75 $location = $this->persistenceHandler->locationHandler()->load($return);
76 $reverseRelations = $this->persistenceHandler->contentHandler()->loadRelations($location->contentId);
77
78 $relationTags = [];
79 if (!empty($reverseRelations)) {
80 $relationTags = array_map(function (Relation $relation) {
81 return $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$relation->destinationContentId]);
82 }, $reverseRelations);
83 }
84
85 $tags = array_merge(
86 [
87 $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$location->contentId]),
88 $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$trashedId]),
89 ],
90 $relationTags
91 );
92 $this->cache->invalidateTags(array_values(array_unique($tags)));
93
94 return $return;
95 }
96
100 public function findTrashItems(Criterion $criterion = null, $offset = 0, $limit = null, array $sort = null)
101 {
102 $this->logger->logCall(__METHOD__, ['criterion' => $criterion ? get_class($criterion) : 'null']);
103
104 return $this->persistenceHandler->trashHandler()->findTrashItems($criterion, $offset, $limit, $sort);
105 }
106
110 public function emptyTrash()
111 {
112 $this->logger->logCall(__METHOD__, []);
113
114 // We can not use the return value of emptyTrash method because, in the next step, we are not able
115 // to fetch the reverse relations of deleted content.
116 $tags = [];
117 $offset = 0;
118 do {
119 $trashedItems = $this->persistenceHandler->trashHandler()->findTrashItems(null, $offset, self::EMPTY_TRASH_BULK_SIZE);
120 foreach ($trashedItems as $trashedItem) {
121 $reverseRelations = $this->persistenceHandler->contentHandler()->loadReverseRelations($trashedItem->contentId);
122
123 foreach ($reverseRelations as $relation) {
124 $tags[$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$relation->sourceContentId])] = true;
125 }
126
127 $tags[$this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$trashedItem->contentId])] = true;
128 $tags[$this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$trashedItem->id])] = true;
129 }
130 $offset += self::EMPTY_TRASH_BULK_SIZE;
131 // Once offset is larger than total count we can exit
132 } while ($trashedItems->totalCount > $offset);
133
134 $return = $this->persistenceHandler->trashHandler()->emptyTrash();
135
136 if (!empty($tags)) {
137 $this->cache->invalidateTags(array_keys($tags));
138 }
139
140 return $return;
141 }
142
146 public function deleteTrashItem($trashedId)
147 {
148 $this->logger->logCall(__METHOD__, ['id' => $trashedId]);
149
150 // We can not use the return value of deleteTrashItem method because, in the next step, we are not able
151 // to fetch the reverse relations of deleted content.
152 $trashed = $this->persistenceHandler->trashHandler()->loadTrashItem($trashedId);
153
154 $reverseRelations = $this->persistenceHandler->contentHandler()->loadReverseRelations($trashed->contentId);
155
156 $relationTags = array_map(function (Relation $relation) {
157 return $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$relation->sourceContentId]);
158 }, $reverseRelations);
159
160 $return = $this->persistenceHandler->trashHandler()->deleteTrashItem($trashedId);
161
162 $tags = array_merge(
163 [
164 $this->cacheIdentifierGenerator->generateTag(self::CONTENT_IDENTIFIER, [$return->contentId]),
165 $this->cacheIdentifierGenerator->generateTag(self::LOCATION_PATH_IDENTIFIER, [$trashedId]),
166 ],
167 $relationTags
168 );
169 $this->cache->invalidateTags(array_values(array_unique($tags)));
170
171 return $return;
172 }
173 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion.php:15
eZ\Publish\Core\Persistence\Cache\AbstractHandler
Class AbstractHandler.
Definition: AbstractHandler.php:21
eZ\Publish\Core\Persistence\Cache\TrashHandler
Definition: TrashHandler.php:17
eZ\Publish\Core\Persistence\Cache\TrashHandler\CONTENT_IDENTIFIER
const CONTENT_IDENTIFIER
Definition: TrashHandler.php:19
eZ\Publish\Core\Persistence\Cache\TrashHandler\LOCATION_PATH_IDENTIFIER
const LOCATION_PATH_IDENTIFIER
Definition: TrashHandler.php:20
eZ\Publish\Core\Persistence\Cache\TrashHandler\loadTrashItem
loadTrashItem($id)
{Loads the data for the trashed location identified by $id.$id is the same as original location (whic...
Definition: TrashHandler.php:25
eZ\Publish\Core\Persistence\Cache\TrashHandler\emptyTrash
emptyTrash()
{Empties the trash Everything contained in the trash must be removed.\eZ\Publish\API\Repository\Value...
Definition: TrashHandler.php:110
eZ\Publish\Core\Persistence\Cache\TrashHandler\recover
recover($trashedId, $newParentId)
{Returns a trashed location to normal state.Recreates the originally trashed location in the new posi...
Definition: TrashHandler.php:69
eZ\Publish\Core\Persistence\Cache\TrashHandler\findTrashItems
findTrashItems(Criterion $criterion=null, $offset=0, $limit=null, array $sort=null)
{Returns all trashed locations satisfying the $criterion (if provided), sorted with $sort (if any)....
Definition: TrashHandler.php:100
eZ\Publish\Core\Persistence\Cache\TrashHandler\trashSubtree
trashSubtree($locationId)
{Sends a subtree starting to $locationId to the trash and returns a Trashed object corresponding to $...
Definition: TrashHandler.php:35
eZ\Publish\Core\Persistence\Cache\TrashHandler\deleteTrashItem
deleteTrashItem($trashedId)
{Removes a trashed location identified by $trashedLocationId from trash Associated content has to be ...
Definition: TrashHandler.php:146
eZ\Publish\Core\Persistence\Cache\TrashHandler\EMPTY_TRASH_BULK_SIZE
const EMPTY_TRASH_BULK_SIZE
Definition: TrashHandler.php:18
eZ\Publish\SPI\Persistence\Content\Relation
Class representing a relation between content.
Definition: SPI/Persistence/Content/Relation.php:15
eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler
The Trash Handler interface defines operations on Location elements in the storage engine.
Definition: SPI/Persistence/Content/Location/Trash/Handler.php:15
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion/Ancestor.php:7
eZ\Publish\Core\Persistence\Cache
Definition: AbstractHandler.php:7
eZ\Publish\SPI\Persistence\Content\Relation
Definition: SPI/Persistence/Content/Relation/CreateStruct.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.