ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRepUtil Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilRepUtil:

Public Member Functions

 __construct ()
 
 deleteObjectType (string $a_type)
 

Static Public Member Functions

static deleteObjects (int $a_cur_ref_id, array $a_ids)
 Delete objects. More...
 
static removeObjectsFromSystem (array $a_ref_ids, bool $a_from_recovery_folder=false)
 remove objects from trash bin and all entries therefore every object needs a specific deleteObject() method More...
 
static restoreObjects (int $a_cur_ref_id, array $a_ref_ids)
 Move objects from trash back to repository. More...
 

Protected Member Functions

 findTypeInTrash (string $a_type)
 
 getObjectTypeId (string $a_type)
 

Protected Attributes

ilDBInterface $db
 
ilTree $tree
 
ilSetting $settings
 

Static Private Member Functions

static 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...
 
static insertSavedNodes (int $a_source_id, int $a_dest_id, int $a_tree_id, array &$a_affected_ids)
 Recursive method to insert all saved nodes of the clipboard. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Repository Utilities (application layer, put GUI related stuff into ilRepositoryTrashGUI)

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 24 of file class.ilRepUtil.php.

Constructor & Destructor Documentation

◆ __construct()

ilRepUtil::__construct ( )

Definition at line 30 of file class.ilRepUtil.php.

31 {
32 global $DIC;
33
34 $this->db = $DIC->database();
35 $this->tree = $DIC->repositoryTree();
36 $this->settings = $DIC->settings();
37 }
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ deleteObjects()

static ilRepUtil::deleteObjects ( int  $a_cur_ref_id,
array  $a_ids 
)
static

Delete objects.

Move them to trash (if trash feature is enabled).

Parameters
int$a_cur_ref_id
int[]$a_idsref ids
Exceptions
ilRepositoryException
Deprecated:
will be removed with ilias 11

Definition at line 46 of file class.ilRepUtil.php.

49 : void {
50 global $DIC;
51
52 $DIC->repository()->internal()->domain()->deletion()->deleteObjectsByRefIds($a_ids);
53 }

Referenced by ilFileVersionsGUI\confirmDeleteFile().

+ Here is the caller graph for this function:

◆ deleteObjectType()

ilRepUtil::deleteObjectType ( string  $a_type)

Definition at line 410 of file class.ilRepUtil.php.

412 : void {
416
417 // delete object instances (repository/trash)
418
419 $ref_ids_in_tree = $tree->getSubTree($tree->getNodeData(ROOT_FOLDER_ID), false, [$a_type]);
420 if ($ref_ids_in_tree) {
421 self::deleteObjects(0, $ref_ids_in_tree);
422 }
423
424 if ($ilSetting->get('enable_trash')) {
425 $ref_ids_in_trash = $this->findTypeInTrash($a_type);
426 if ($ref_ids_in_trash) {
427 self::removeObjectsFromSystem($ref_ids_in_trash);
428 }
429 }
430
431 // delete "component"
432 $type_id = $this->getObjectTypeId($a_type);
433 if ($type_id) {
434 // see ilRepositoryObjectPlugin::beforeActivation()
435
436 $ilDB->manipulate("DELETE FROM object_data" .
437 " WHERE obj_id = " . $ilDB->quote($type_id, "integer"));
438
439 // RBAC
440
441 // basic operations
442 $ilDB->manipulate("DELETE FROM rbac_ta" .
443 " WHERE typ_id = " . $ilDB->quote($type_id, "integer") /*.
444 " AND ".$ilDB->in("ops_id", array(1, 2, 3, 4, 6), "", "integer") */);
445
446 // creation operation
447 $set = $ilDB->query("SELECT ops_id" .
448 " FROM rbac_operations " .
449 " WHERE class = " . $ilDB->quote("create", "text") .
450 " AND operation = " . $ilDB->quote("create_" . $a_type, "text"));
451 $row = $ilDB->fetchAssoc($set);
452 $create_ops_id = $row["ops_id"];
453 if ($create_ops_id) {
454 $ilDB->manipulate("DELETE FROM rbac_operations" .
455 " WHERE ops_id = " . $ilDB->quote($create_ops_id, "integer"));
456
457 $ilDB->manipulate("DELETE FROM rbac_templates" .
458 " WHERE ops_id = " . $ilDB->quote($create_ops_id, "integer"));
459
460 // container create
461 foreach (["root", "cat", "crs", "grp", "fold"] as $parent_type) {
462 $parent_type_id = $this->getObjectTypeId($parent_type);
463 if ($parent_type_id) {
464 $ilDB->manipulate("DELETE FROM rbac_ta" .
465 " WHERE typ_id = " . $ilDB->quote($parent_type_id, "integer") .
466 " AND ops_id = " . $ilDB->quote($create_ops_id, "integer"));
467 }
468 }
469 }
470 }
471
472 // delete new item settings
474 }
ilSetting $settings
ilDBInterface $db
static removeObjectsFromSystem(array $a_ref_ids, bool $a_from_recovery_folder=false)
remove objects from trash bin and all entries therefore every object needs a specific deleteObject() ...
findTypeInTrash(string $a_type)
getObjectTypeId(string $a_type)
static deleteObjects(int $a_cur_ref_id, array $a_ids)
Delete objects.
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
const ROOT_FOLDER_ID
Definition: constants.php:32
global $ilSetting
Definition: privfeed.php:31

◆ findTypeInTrash()

ilRepUtil::findTypeInTrash ( string  $a_type)
protected

Definition at line 377 of file class.ilRepUtil.php.

379 : array {
381
382 $res = [];
383
384 $set = $ilDB->query("SELECT child" .
385 " FROM tree" .
386 " JOIN object_reference ref ON (tree.child = ref.ref_id)" .
387 " JOIN object_data od ON (od.obj_id = ref.obj_id)" .
388 " WHERE tree.tree < " . $ilDB->quote(0, "integer") .
389 " AND od.type = " . $ilDB->quote($a_type, "text"));
390 while ($row = $ilDB->fetchAssoc($set)) {
391 $res[] = $row["child"];
392 }
393
394 return $res;
395 }
$res
Definition: ltiservices.php:69

References $res.

◆ getObjectTypeId()

ilRepUtil::getObjectTypeId ( string  $a_type)
protected

Definition at line 397 of file class.ilRepUtil.php.

399 : int {
401
402 $set = $ilDB->query("SELECT obj_id" .
403 " FROM object_data " .
404 " WHERE type = " . $ilDB->quote("typ", "text") .
405 " AND title = " . $ilDB->quote($a_type, "text"));
406 $row = $ilDB->fetchAssoc($set);
407 return (int) $row["obj_id"];
408 }

◆ insertSavedNodes()

static ilRepUtil::insertSavedNodes ( int  $a_source_id,
int  $a_dest_id,
int  $a_tree_id,
array &  $a_affected_ids 
)
staticprivate

Recursive method to insert all saved nodes of the clipboard.

Definition at line 329 of file class.ilRepUtil.php.

334 : void {
335 global $DIC;
336
337 $tree = $DIC->repositoryTree();
338
339 ilLoggerFactory::getLogger('rep')->debug('Restoring from trash: source_id: ' . $a_source_id . ', dest_id: ' . $a_dest_id . ', tree_id:' . $a_tree_id);
340 ilLoggerFactory::getLogger('rep')->info('Restoring ref_id ' . $a_source_id . ' from trash.');
341
342 // read child of node
343 $saved_tree = new ilTree($a_tree_id);
344 $childs = $saved_tree->getChilds($a_source_id);
345
346 // then delete node and put in tree
347 try {
348 $tree->insertNodeFromTrash($a_source_id, $a_dest_id, $a_tree_id, ilTree::POS_LAST_NODE, true);
349 } catch (Exception $e) {
350 ilLoggerFactory::getLogger('rep')->error('Restore from trash failed with message: ' . $e->getMessage());
351 throw $e;
352 }
353
354 $ref_obj = ilObjectFactory::getInstanceByRefId($a_source_id, false);
355 if ($ref_obj instanceof ilObject) {
356 $lroles = $GLOBALS['rbacreview']->getRolesOfRoleFolder($a_source_id, true);
357 foreach ($lroles as $role_id) {
358 $role = new ilObjRole($role_id);
359 $role->setParent($a_source_id);
360 $role->delete();
361 }
362 if ($a_dest_id) {
363 $ref_obj->setPermissions($a_dest_id);
364 }
365 }
366 foreach ($childs as $child) {
367 self::insertSavedNodes($child["child"], $a_source_id, $a_tree_id, $a_affected_ids);
368 }
369 }
static getLogger(string $a_component_id)
Get component logger.
Class ilObjRole.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static insertSavedNodes(int $a_source_id, int $a_dest_id, int $a_tree_id, array &$a_affected_ids)
Recursive method to insert all saved nodes of the clipboard.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
insertNodeFromTrash(int $a_source_id, int $a_target_id, int $a_tree_id, int $a_pos=self::POS_LAST_NODE, bool $a_reset_deleted_date=false)
Insert node from trash deletes trash entry.
const POS_LAST_NODE
$GLOBALS["DIC"]
Definition: wac.php:54

◆ removeDeletedNodes()

static ilRepUtil::removeDeletedNodes ( int  $a_node_id,
array  $a_checked,
bool  $a_delete_objects,
array &  $a_affected_ids 
)
staticprivate

Remove already deleted objects within the objects in trash.

Definition at line 183 of file class.ilRepUtil.php.

188 : void {
189 global $DIC;
190
191 $ilLog = $DIC["ilLog"];
192 $ilDB = $DIC->database();
193 $tree = $DIC->repositoryTree();
194 $logger = $DIC->logger()->rep();
195
196 $log = $ilLog;
197
198 // this queries for trash items in the trash of deleted nodes
199 $q = 'SELECT tree FROM tree WHERE parent = ' . $ilDB->quote($a_node_id, ilDBConstants::T_INTEGER) .
200 ' AND tree < 0 ' .
201 ' AND tree = -1 * child' ;
202
203 $r = $ilDB->query($q);
204
205 while ($row = $ilDB->fetchObject($r)) {
206 // only continue recursion if fetched node wasn't touched already!
207 if (!in_array($row->tree, $a_checked)) {
208 $deleted_tree = new ilTree($row->tree);
209 $a_checked[] = $row->tree;
210
211 $row->tree *= (-1);
212 $del_node_data = $deleted_tree->getNodeData($row->tree);
213 $del_subtree_nodes = $deleted_tree->getSubTree($del_node_data);
214 // delete trash in the trash of trash...
215 self::removeDeletedNodes($row->tree, $a_checked, $a_delete_objects, $a_affected_ids);
216
217 if ($a_delete_objects) {
218 foreach ($del_subtree_nodes as $node) {
219 $node_obj = ilObjectFactory::getInstanceByRefId($node["ref_id"]);
220 $logger->info(
221 'removeDeletedNodes: delete obj_id: ' . $node_obj->getId() .
222 ', ref_id: ' . $node_obj->getRefId() .
223 ', type: ' . $node_obj->getType() .
224 ', title: ' . $node_obj->getTitle()
225 );
226 $a_affected_ids[$node["ref_id"]] = [
227 "ref_id" => $node["ref_id"],
228 "obj_id" => $node_obj->getId(),
229 "type" => $node_obj->getType(),
230 "old_parent_ref_id" => $node["parent"]
231 ];
232 $node_obj->delete();
233 }
234 }
235 // tree instance with -child tree id
236 $trash_tree = new ilTree($del_node_data['tree']);
237 $trash_tree->deleteTree($del_node_data);
238 $logger->info(
239 'removeDeltedNodes: deleted tree, tree_id: ' . $del_node_data['tree'] .
240 ', child: ' . $del_node_data['child']
241 );
242 }
243 }
244 }
static 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.
$log
Definition: ltiresult.php:34
$q
Definition: shib_logout.php:23

References ilObjectFactory\getInstanceByRefId().

+ Here is the call graph for this function:

◆ removeObjectsFromSystem()

static ilRepUtil::removeObjectsFromSystem ( array  $a_ref_ids,
bool  $a_from_recovery_folder = false 
)
static

remove objects from trash bin and all entries therefore every object needs a specific deleteObject() method

Parameters
int[]$a_ref_ids
bool$a_from_recovery_folder
Exceptions
ilDatabaseException
ilInvalidTreeStructureException
ilObjectNotFoundException
ilRepositoryException

Definition at line 64 of file class.ilRepUtil.php.

67 : void {
68 global $DIC;
69
70 $ilLog = $DIC["ilLog"];
71 $ilAppEventHandler = $DIC["ilAppEventHandler"];
72 $tree = $DIC->repositoryTree();
73 $logger = $DIC->logger()->rep();
74
75 $log = $ilLog;
76
77 $affected_ids = [];
78
79 // DELETE THEM
80 $a_ref_ids = array_map('intval', $a_ref_ids);
81 foreach ($a_ref_ids as $id) {
82 $saved_tree = null;
83 // GET COMPLETE NODE_DATA OF ALL SUBTREE NODES
84 if (!$a_from_recovery_folder) {
86 $tree_id = end($trees);
87
88 if ($tree_id) {
89 $saved_tree = new ilTree($tree_id);
90 $node_data = $saved_tree->getNodeData($id);
91 $subtree_nodes = $saved_tree->getSubTree($node_data);
92 } else {
93 throw new ilRepositoryException('No valid tree id found for node id: ' . $id);
94 }
95 } else {
96 $node_data = $tree->getNodeData($id);
97 $subtree_nodes = $tree->getSubTree($node_data);
98 }
99
100 global $DIC;
101
102 $ilUser = $DIC->user();
103 $tree = $DIC->repositoryTree();
104
106 $node_data['obj_id'],
107 $ilUser->getId(),
108 'purge',
109 null
110 );
111 // END ChangeEvent: Record remove from system.
112
113 // remember already checked deleted node_ids
114 if (!$a_from_recovery_folder) {
115 $checked[] = -$id;
116 } else {
117 $checked[] = $id;
118 }
119
120 // dive in recursive manner in each already deleted subtrees and remove these objects too
121 self::removeDeletedNodes($id, $checked, true, $affected_ids);
122
123 foreach ($subtree_nodes as $node) {
124 if (!$node_obj = ilObjectFactory::getInstanceByRefId($node["ref_id"], false)) {
125 continue;
126 }
127
128 $logger->info(
129 'delete obj_id: ' . $node_obj->getId() .
130 ', ref_id: ' . $node_obj->getRefId() .
131 ', type: ' . $node_obj->getType() .
132 ', title: ' . $node_obj->getTitle()
133 );
134 $affected_ids[$node["ref_id"]] = [
135 "ref_id" => $node["ref_id"],
136 "obj_id" => $node_obj->getId(),
137 "type" => $node_obj->getType(),
138 "old_parent_ref_id" => $node["parent"]
139 ];
140
141 // this is due to bug #1860 (even if this will not completely fix it)
142 // and the fact, that media pool folders may find their way into
143 // the recovery folder (what results in broken pools, if the are deleted)
144 // Alex, 2006-07-21
145 if (!$a_from_recovery_folder || $node_obj->getType() !== "fold") {
146 $node_obj->delete();
147 }
148 }
149
150 // Use the saved tree object here (negative tree_id)
151 if (!$a_from_recovery_folder) {
152 if ($saved_tree) {
153 $saved_tree->deleteTree($node_data);
154 }
155 } else {
156 $tree->deleteTree($node_data);
157 }
158
159 $logger->info(
160 'deleted tree, tree_id: ' . $node_data['tree'] .
161 ', child: ' . $node_data['child']
162 );
163 }
164
165 // send global events
166 foreach ($affected_ids as $aid) {
167 $ilAppEventHandler->raise(
168 "components/ILIAS/ILIASObject",
169 "delete",
170 [
171 "obj_id" => $aid["obj_id"],
172 "ref_id" => $aid["ref_id"],
173 "type" => $aid["type"],
174 "old_parent_ref_id" => $aid["old_parent_ref_id"]
175 ]
176 );
177 }
178 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _recordWriteEvent(int $obj_id, int $usr_id, string $action, ?int $parent_obj_id=null)
Records a write event.
static lookupTreesForNode(int $node_id)
deleteTree(array $a_node)
delete node and the whole subtree under this node

Referenced by ilObjEmployeeTalkGUI\confirmedDeleteObject(), and ilObjOrgUnitGUI\confirmedDeleteObject().

+ Here is the caller graph for this function:

◆ restoreObjects()

static ilRepUtil::restoreObjects ( int  $a_cur_ref_id,
array  $a_ref_ids 
)
static

Move objects from trash back to repository.

Parameters
int$a_cur_ref_id
int[]$a_ref_ids
Exceptions
ilDatabaseException
ilObjectNotFoundException
ilRepositoryException

Definition at line 254 of file class.ilRepUtil.php.

257 : void {
258 global $DIC;
259
260 $rbacsystem = $DIC->rbac()->system();
261 $ilAppEventHandler = $DIC["ilAppEventHandler"];
262 $lng = $DIC->language();
263 $tree = $DIC->repositoryTree();
264
265 $cur_obj_id = ilObject::_lookupObjId($a_cur_ref_id);
266
267 $no_create = [];
268
269 foreach ($a_ref_ids as $id) {
271
272 if (!$rbacsystem->checkAccess('create', $a_cur_ref_id, $obj_data->getType())) {
274 }
275 }
276
277 if (count($no_create)) {
278 throw new ilRepositoryException($lng->txt("msg_no_perm_paste") . " " . implode(',', $no_create));
279 }
280
281 $affected_ids = [];
282
283 foreach ($a_ref_ids as $id) {
284 $affected_ids[$id] = $id;
285
286 // INSERT AND SET PERMISSIONS
287 try {
288 $tree_ids = ilTree::lookupTreesForNode($id);
289 $tree_id = $tree_ids[0];
290 self::insertSavedNodes($id, $a_cur_ref_id, $tree_id, $affected_ids);
291 } catch (Exception $e) {
292 throw new ilRepositoryException('Restore from trash failed with message: ' . $e->getMessage());
293 }
294
295
296 // BEGIN ChangeEvent: Record undelete.
297 global $DIC;
298
299 $ilUser = $DIC->user();
300
301
304 $ilUser->getId(),
305 'undelete',
307 );
309 $cur_obj_id,
310 $ilUser->getId()
311 );
312 // END PATCH ChangeEvent: Record undelete.
313 }
314
315 // send events
316 foreach ($affected_ids as $id) {
317 // send global event
318 $ilAppEventHandler->raise(
319 "components/ILIAS/ILIASObject",
320 "undelete",
321 ["obj_id" => ilObject::_lookupObjId($id), "ref_id" => $id]
322 );
323 }
324 }
static _catchupWriteEvents(int $obj_id, int $usr_id, ?string $timestamp=null)
Catches up with all write events which occured before the specified timestamp.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
getParentId(int $a_node_id)
get parent id of given node
global $lng
Definition: privfeed.php:31

Referenced by ilRepositoryTrashGUI\doRestoreToNewLocation().

+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilRepUtil::$db
protected

Definition at line 26 of file class.ilRepUtil.php.

◆ $settings

ilSetting ilRepUtil::$settings
protected

Definition at line 28 of file class.ilRepUtil.php.

◆ $tree

ilTree ilRepUtil::$tree
protected

Definition at line 27 of file class.ilRepUtil.php.


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