ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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())
69 {
71 $GLOBALS['ilLog']->write(__METHOD__.': Restore trash to recovery folder');
72 $this->restore();
73 break;
74
76 $GLOBALS['ilLog']->write(__METHOD__.': Remove selected from system.');
77 $GLOBALS['ilLog']->write(__METHOD__.': Type limit: '. print_r($this->getTypesLimit(),TRUE));
78 $GLOBALS['ilLog']->write(__METHOD__.': Age limit: '. (string) $this->getAgeLimit());
79 $GLOBALS['ilLog']->write(__METHOD__.': Number limit: '. (string) $this->getNumberLimit());
81 return TRUE;
82 }
83 }
84
88 protected function restore()
89 {
90 $deleted = $this->readDeleted();
91
92 $GLOBALS['ilLog']->write(__METHOD__.': Found deleted : '.print_r($deleted,TRUE));
93
94 $factory = new ilObjectFactory();
95
96 foreach($deleted as $tmp_num => $deleted_info)
97 {
98 $ref_obj = $factory->getInstanceByRefId($deleted_info['child'], FALSE);
99 if(!$ref_obj instanceof ilObject)
100 {
101 continue;
102 }
103
104 $GLOBALS['tree']->deleteNode($deleted_info['tree'],$deleted_info['child']);
105 $GLOBALS['ilLog']->write(__METHOD__.': Object tree entry deleted');
106
107 if($ref_obj->getType() != 'rolf')
108 {
109 $GLOBALS['rbacadmin']->revokePermission($deleted_info['child']);
110 $ref_obj->putInTree(RECOVERY_FOLDER_ID);
111 $ref_obj->setPermissions(RECOVERY_FOLDER_ID);
112 $GLOBALS['ilLog']->write(__METHOD__.': Object moved to recovery folder');
113 }
114 }
115 }
116
120 protected function removeSelectedFromSystem()
121 {
122 $factory = new ilObjectFactory();
123
124 $deleted = $this->readSelectedDeleted();
125 foreach($deleted as $tmp_num => $deleted_info)
126 {
127 $sub_nodes = $this->readDeleted($deleted_info['tree']);
128
129 foreach($sub_nodes as $tmp_num => $subnode_info)
130 {
131 $ref_obj = $factory->getInstanceByRefId($subnode_info['child'], FALSE);
132 if(!$ref_obj instanceof ilObject)
133 {
134 continue;
135 }
136
137 $ref_obj->delete();
138 ilTree::_removeEntry($subnode_info['tree'],$subnode_info['child']);
139 }
140 }
141 }
142
146 protected function readSelectedDeleted()
147 {
148 global $ilDB;
149
150 $and_types = '';
151 ilLoggerFactory::getLogger('sysc')->dump($this->getTypesLimit());
152
153 $types = array();
154 foreach((array) $this->getTypesLimit() as $id => $type)
155 {
156 if($type)
157 {
158 $types[] = $type;
159 }
160 }
161 if(count($types))
162 {
163 $and_types = 'AND '.$ilDB->in('o.type', $this->getTypesLimit(),FALSE,'text').' ';
164 }
165
166 $and_age = '';
167 $age_limit = $this->getAgeLimit()->get(IL_CAL_UNIX);
168 if($age_limit > 0)
169 {
170 $and_age = 'AND r.deleted < '.$ilDB->quote($this->getAgeLimit()->get(IL_CAL_DATETIME)).' ';
171 }
172 $limit = '';
173 if($this->getNumberLimit())
174 {
175 $limit = 'LIMIT '.(int) $this->getNumberLimit();
176 }
177
178 $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id '.
179 'JOIN object_data o on r.obj_id = o.obj_id '.
180 'WHERE tree < '.$ilDB->quote(0,'integer').' '.
181 'AND child = -tree ';
182
183 $query .= $and_age;
184 $query .= $and_types;
185 $query .= 'ORDER BY depth desc ';
186 $query .= $limit;
187
188 $GLOBALS['ilLog']->write($query);
189
190 $deleted = array();
191 $res = $ilDB->query($query);
192 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
193 {
194 $deleted[] = array(
195 'tree' => $row->tree,
196 'child' => $row->child
197 );
198 }
199 return $deleted;
200
201 }
202
203
204
205
211 protected function readDeleted($tree_id = null)
212 {
213 global $ilDB;
214
215 $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id '.
216 'JOIN object_data o on r.obj_id = o.obj_id ';
217
218 if($tree_id === null)
219 {
220 $query .= 'WHERE tree < '.$ilDB->quote(0,'integer').' ';
221 }
222 else
223 {
224 $query .= 'WHERE tree = '.$ilDB->quote($tree_id,'integer').' ';
225 }
226 $query .= 'ORDER BY depth desc';
227
228 $res = $ilDB->query($query);
229
230 $deleted = array();
231 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
232 {
233 $deleted[] = array(
234 'tree' => $row->tree,
235 'child' => $row->child
236 );
237 }
238 return $deleted;
239 }
240
241}
242?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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
_removeEntry($a_tree, $a_child, $a_db_table="tree")
STATIC METHOD Removes a single entry from a tree.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilDB