ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSystemCheckTrash.php
Go to the documentation of this file.
1<?php
7{
10
11 private $limit_number = 0;
12 private $limit_age = null;
13 private $limit_types = array();
14
15
16 public function __construct()
17 {
18 $this->limit_age = new ilDate(0, IL_CAL_UNIX);
19 }
20
21 public function setNumberLimit($a_limit)
22 {
23 $this->limit_number = $a_limit;
24 }
25
26 public function getNumberLimit()
27 {
29 }
30
31 public function setAgeLimit(ilDateTime $dt)
32 {
33 $this->limit_age = $dt;
34 }
35
40 public function getAgeLimit()
41 {
42 return $this->limit_age;
43 }
44
45 public function setTypesLimit($a_types)
46 {
47 $this->limit_types = (array) $a_types;
48 }
49
50 public function getTypesLimit()
51 {
52 return (array) $this->limit_types;
53 }
54
55 public function setMode($a_mode)
56 {
57 $this->mode = $a_mode;
58 }
59
60 public function getMode()
61 {
62 return $this->mode;
63 }
64
65 public function start()
66 {
67 $GLOBALS['ilLog']->write(__METHOD__ . ': Handling delete');
68 switch ($this->getMode()) {
70 $GLOBALS['ilLog']->write(__METHOD__ . ': Restore trash to recovery folder');
71 $this->restore();
72 break;
73
75 $GLOBALS['ilLog']->write(__METHOD__ . ': Remove selected from system.');
76 $GLOBALS['ilLog']->write(__METHOD__ . ': Type limit: ' . print_r($this->getTypesLimit(), true));
77 $GLOBALS['ilLog']->write(__METHOD__ . ': Age limit: ' . (string) $this->getAgeLimit());
78 $GLOBALS['ilLog']->write(__METHOD__ . ': Number limit: ' . (string) $this->getNumberLimit());
80 return true;
81 }
82 }
83
87 protected function restore()
88 {
89 $deleted = $this->readDeleted();
90
91 $GLOBALS['ilLog']->write(__METHOD__ . ': Found deleted : ' . print_r($deleted, true));
92
94
95 foreach ($deleted as $tmp_num => $deleted_info) {
96 $ref_obj = $factory->getInstanceByRefId($deleted_info['child'], false);
97 if (!$ref_obj instanceof ilObject) {
98 continue;
99 }
100
101 $GLOBALS['tree']->deleteNode($deleted_info['tree'], $deleted_info['child']);
102 $GLOBALS['ilLog']->write(__METHOD__ . ': Object tree entry deleted');
103
104 if ($ref_obj->getType() != 'rolf') {
105 $GLOBALS['rbacadmin']->revokePermission($deleted_info['child']);
106 $ref_obj->putInTree(RECOVERY_FOLDER_ID);
107 $ref_obj->setPermissions(RECOVERY_FOLDER_ID);
108 $GLOBALS['ilLog']->write(__METHOD__ . ': Object moved to recovery folder');
109 }
110 }
111 }
112
116 protected function removeSelectedFromSystem()
117 {
119
120 $deleted = $this->readSelectedDeleted();
121 foreach ($deleted as $tmp_num => $deleted_info) {
122 $sub_nodes = $this->readDeleted($deleted_info['tree']);
123
124 foreach ($sub_nodes as $tmp_num => $subnode_info) {
125 $ref_obj = $factory->getInstanceByRefId($subnode_info['child'], false);
126 if (!$ref_obj instanceof ilObject) {
127 continue;
128 }
129
130 $ref_obj->delete();
131 ilTree::_removeEntry($subnode_info['tree'], $subnode_info['child']);
132 }
133 }
134 }
135
139 protected function readSelectedDeleted()
140 {
141 global $ilDB;
142
143 $and_types = '';
144 ilLoggerFactory::getLogger('sysc')->dump($this->getTypesLimit());
145
146 $types = array();
147 foreach ((array) $this->getTypesLimit() as $id => $type) {
148 if ($type) {
149 $types[] = $type;
150 }
151 }
152 if (count($types)) {
153 $and_types = 'AND ' . $ilDB->in('o.type', $this->getTypesLimit(), false, 'text') . ' ';
154 }
155
156 $and_age = '';
157 $age_limit = $this->getAgeLimit()->get(IL_CAL_UNIX);
158 if ($age_limit > 0) {
159 $and_age = 'AND r.deleted < ' . $ilDB->quote($this->getAgeLimit()->get(IL_CAL_DATETIME)) . ' ';
160 }
161 $limit = '';
162 if ($this->getNumberLimit()) {
163 $limit = 'LIMIT ' . (int) $this->getNumberLimit();
164 }
165
166 $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id ' .
167 'JOIN object_data o on r.obj_id = o.obj_id ' .
168 'WHERE tree < ' . $ilDB->quote(0, 'integer') . ' ' .
169 'AND child = -tree ';
170
171 $query .= $and_age;
172 $query .= $and_types;
173 $query .= 'ORDER BY depth desc ';
174 $query .= $limit;
175
176 $GLOBALS['ilLog']->write($query);
177
178 $deleted = array();
179 $res = $ilDB->query($query);
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $deleted[] = array(
182 'tree' => $row->tree,
183 'child' => $row->child
184 );
185 }
186 return $deleted;
187 }
188
189
190
191
197 protected function readDeleted($tree_id = null)
198 {
199 global $ilDB;
200
201 $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id ' .
202 'JOIN object_data o on r.obj_id = o.obj_id ';
203
204 if ($tree_id === null) {
205 $query .= 'WHERE tree < ' . $ilDB->quote(0, 'integer') . ' ';
206 } else {
207 $query .= 'WHERE tree = ' . $ilDB->quote($tree_id, 'integer') . ' ';
208 }
209 $query .= 'ORDER BY depth desc';
210
211 $res = $ilDB->query($query);
212
213 $deleted = array();
214 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
215 $deleted[] = array(
216 'tree' => $row->tree,
217 'child' => $row->child
218 );
219 }
220 return $deleted;
221 }
222}
$factory
Definition: metadata.php:47
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
const IL_CAL_DATETIME
@classDescription Date and time handling
Class for single dates.
static getLogger($a_component_id)
Get component logger.
Class ilObjectFactory.
Class ilObject Basic functions for all objects.
restore()
Restore to recovery folder.
readSelectedDeleted()
read deleted according to filter settings
readDeleted($tree_id=null)
Read deleted objects @global type $ilDB.
removeSelectedFromSystem()
remove (containers) from system
static _removeEntry($a_tree, $a_child, $a_db_table="tree")
STATIC METHOD Removes a single entry from a tree.
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$query
$type
foreach($_POST as $key=> $value) $res
global $ilDB