ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\Repository\Deletion\Deletion Class Reference
+ Collaboration diagram for ILIAS\Repository\Deletion\Deletion:

Public Member Functions

 __construct (protected TreeInterface $tree, protected PermissionInterface $permission, protected EventInterface $event, protected ObjectInterface $object, protected bool $trash_enabled)
 
 deleteObjectsByRefIds (array $ids)
 Delete: If trash is enabled, objects are moved to the trash. More...
 
 removeObjectsFromSystemByRefIds (array $ref_ids, bool $direct_from_tree=false)
 Remove objects from system directly ($direct_from_tree === true) or from trash ($direct_from_tree === false) More...
 

Protected Member Functions

 removeDeletedNodes (int $a_node_id, array $a_checked, bool $a_delete_objects, array &$a_affected_ids)
 Remove already deleted objects within the objects in trash. More...
 
 moveToTrash (array $ids)
 

Detailed Description

Definition at line 23 of file Deletion.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Repository\Deletion\Deletion::__construct ( protected TreeInterface  $tree,
protected PermissionInterface  $permission,
protected EventInterface  $event,
protected ObjectInterface  $object,
protected bool  $trash_enabled 
)

Definition at line 25 of file Deletion.php.

31 {
32
33 }

Member Function Documentation

◆ deleteObjectsByRefIds()

ILIAS\Repository\Deletion\Deletion::deleteObjectsByRefIds ( array  $ids)

Delete: If trash is enabled, objects are moved to the trash.

If trash is disabled, objects are removed from system directly.

Returns
int[]

Definition at line 40 of file Deletion.php.

40 : void
41 {
42 // check if objects are already deleted
43 if (count($del_ids = $this->tree->getDeletedTreeNodeIds($ids)) > 0) {
44 throw new AlreadyDeletedException('Deletion: Some tree nodes are already deleted: ' . implode(', ', $del_ids));
45 }
46
47 // check delelete permissions
48 if (count($miss_ids = $this->permission->getRefIdsWithoutDeletePermission($ids)) > 0) {
49 throw new MissingPermissionException('Deletion: missing permission: ' . implode(', ', $miss_ids));
50 }
51
52 if ($this->trash_enabled) {
53 $this->moveToTrash($ids);
54 } else {
55 $this->removeObjectsFromSystemByRefIds($ids, true);
56 }
57 }
removeObjectsFromSystemByRefIds(array $ref_ids, bool $direct_from_tree=false)
Remove objects from system directly ($direct_from_tree === true) or from trash ($direct_from_tree ===...
Definition: Deletion.php:63

References ILIAS\Repository\Deletion\Deletion\moveToTrash(), and ILIAS\Repository\Deletion\Deletion\removeObjectsFromSystemByRefIds().

+ Here is the call graph for this function:

◆ moveToTrash()

ILIAS\Repository\Deletion\Deletion::moveToTrash ( array  $ids)
protected

Definition at line 226 of file Deletion.php.

226 : void
227 {
228 // save subtree / delete subtree from tree
229 $affected_ids = [];
230 $affected_parents = [];
231 foreach ($ids as $id) {
232 if ($this->tree->isDeleted($id)) {
233 throw new AlreadyDeletedException("Move To Trash: Object with ref_id: " . $id . " already deleted.");
234 }
235
236 $subnodes = $this->tree->getSubtree($this->tree->getNodeData($id));
237
238 foreach ($subnodes as $subnode) {
239 $this->permission->revokePermission((int) $subnode["child"]);
240
241 $affected_ids[$subnode["child"]] = $subnode["child"];
242 $affected_parents[$subnode["child"]] = $subnode["parent"];
243 }
244
245 $this->event->beforeMoveToTrash($id, $subnodes);
246
247 if (!$this->tree->moveToTrash($id)) {
248 throw new AlreadyDeletedException("Move To Trash: Object with ref_id: " . $id . " already deleted.");
249 }
250 $affected_ids[$id] = $id;
251 }
252
253 // send global events
254 foreach ($affected_ids as $aid) {
255 $this->event->afterMoveToTrash($aid, $affected_parents[$aid]);
256 }
257 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

Referenced by ILIAS\Repository\Deletion\Deletion\deleteObjectsByRefIds().

+ Here is the caller graph for this function:

◆ removeDeletedNodes()

ILIAS\Repository\Deletion\Deletion::removeDeletedNodes ( int  $a_node_id,
array  $a_checked,
bool  $a_delete_objects,
array &  $a_affected_ids 
)
protected

Remove already deleted objects within the objects in trash.

Definition at line 163 of file Deletion.php.

168 : void {
169
170 foreach ($this->tree->getTrashedSubtrees($a_node_id) as $tree_id) {
171 // $tree_id is negative here
172 // only continue recursion if fetched node wasn't touched already!
173 if (!in_array($tree_id, $a_checked)) {
174 $deleted_tree = $this->tree->getTree($tree_id);
175 $a_checked[] = $tree_id;
176
177 $tree_id *= (-1);
178 // $tree_id is positive here
179 $del_node_data = $deleted_tree->getNodeData($tree_id);
180 $del_subtree_nodes = $deleted_tree->getSubTree($del_node_data);
181 // delete trash in the trash of trash...
182 $this->removeDeletedNodes($tree_id, $a_checked, $a_delete_objects, $a_affected_ids);
183
184 if ($a_delete_objects) {
185 foreach ($del_subtree_nodes as $node) {
186 $object = $this->object->getInstanceByRefId($node["ref_id"]);
187 if (!is_null($object)) {
188 $a_affected_ids[$node["ref_id"]] = [
189 "ref_id" => $node["ref_id"],
190 "obj_id" => $object->getId(),
191 "type" => $object->getType(),
192 "old_parent_ref_id" => $node["parent"]
193 ];
194 $this->event->beforeObjectRemoval(
195 $object->getId(),
196 $object->getRefId(),
197 $object->getType(),
198 $object->getTitle()
199 );
200 try {
201 $object->delete();
202 } catch (\Exception $e) {
203 $this->event->failedRemoval(
204 $object->getId(),
205 $object->getRefId(),
206 $object->getType(),
207 $object->getTitle(),
208 $e->getMessage()
209 );
210 }
211 }
212 }
213 }
214 // tree instance with -child tree id
215 $trash_tree = $this->tree->getTree((int) $del_node_data['tree']);
216 $trash_tree->deleteTree($del_node_data);
217 $this->event->afterTreeDeletion(
218 (int) $del_node_data['tree'],
219 (int) $del_node_data['child']
220 );
221 }
222 }
223 }
removeDeletedNodes(int $a_node_id, array $a_checked, bool $a_delete_objects, array &$a_affected_ids)
Remove already deleted objects within the objects in trash.
Definition: Deletion.php:163

References Vendor\Package\$e, and ILIAS\Repository\Deletion\Deletion\removeDeletedNodes().

Referenced by ILIAS\Repository\Deletion\Deletion\removeDeletedNodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeObjectsFromSystemByRefIds()

ILIAS\Repository\Deletion\Deletion::removeObjectsFromSystemByRefIds ( array  $ref_ids,
bool  $direct_from_tree = false 
)

Remove objects from system directly ($direct_from_tree === true) or from trash ($direct_from_tree === false)

Definition at line 63 of file Deletion.php.

66 : void {
67
68 $affected_ids = [];
69 $ref_ids = array_map('intval', $ref_ids);
70 foreach ($ref_ids as $id) {
71 $saved_tree = null;
72
73 // get subtree nodes
74 if (!$direct_from_tree) {
75 // from trash
76 $saved_tree = $this->tree->getTrashTree($id);
77 $node_data = $saved_tree->getNodeData($id);
78 // subtree nodes from trashed tree will include the $id node itself, too
79 $subtree_nodes = $saved_tree->getSubTree($node_data);
80 } else {
81 // from main tree
82 $node_data = $this->tree->getNodeData($id);
83 // subtree nodes will include the $id node itself, too
84 $subtree_nodes = $this->tree->getSubTree($node_data);
85 }
86
87 $this->event->beforeSubTreeRemoval(
88 $node_data['obj_id']
89 );
90
91 // remember already checked deleted node_ids
92 if (!$direct_from_tree) {
93 $checked[] = -$id;
94 } else {
95 $checked[] = $id;
96 }
97
98 // dive in recursive manner in each already deleted subtrees and remove these objects too
99
100 foreach ($subtree_nodes as $node) {
101 if (!$node_obj = $this->object->getInstanceByRefId($node["ref_id"])) {
102 continue;
103 }
104
105 // NOTE: This has been outside of the for loop before
106 $this->removeDeletedNodes($node["ref_id"], $checked, true, $affected_ids);
107
108 $this->event->beforeObjectRemoval(
109 $node_obj->getId(),
110 $node_obj->getRefId(),
111 $node_obj->getType(),
112 $node_obj->getTitle()
113 );
114 $affected_ids[$node["ref_id"]] = [
115 "ref_id" => $node["ref_id"],
116 "obj_id" => $node_obj->getId(),
117 "type" => $node_obj->getType(),
118 "old_parent_ref_id" => $node["parent"]
119 ];
120
121 try {
122 $node_obj->delete();
123 } catch (\Exception $e) {
124 $this->event->failedRemoval(
125 $node_obj->getId(),
126 $node_obj->getRefId(),
127 $node_obj->getType(),
128 $node_obj->getTitle(),
129 $e->getMessage()
130 );
131 }
132 }
133
134 // Use the saved tree object here (negative tree_id)
135 if (!$direct_from_tree) {
136 if ($saved_tree) {
137 $saved_tree->deleteTree($node_data);
138 }
139 } else {
140 $this->tree->deleteTree($node_data);
141 }
142
143 $this->event->afterTreeDeletion(
144 (int) $node_data['tree'],
145 (int) $node_data['child']
146 );
147 }
148
149 // send global events
150 foreach ($affected_ids as $aid) {
151 $this->event->afterObjectRemoval(
152 $aid["obj_id"],
153 $aid["ref_id"],
154 $aid["type"],
155 $aid["old_parent_ref_id"]
156 );
157 }
158 }

Referenced by ILIAS\Repository\Deletion\Deletion\deleteObjectsByRefIds().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: