ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSystemCheckTrash.php
Go to the documentation of this file.
1 <?php
7 {
8  const MODE_TRASH_RESTORE = 1;
9  const MODE_TRASH_REMOVE = 2;
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  {
28  return $this->limit_number;
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['DIC']['ilLog']->info('Handling delete');
68  switch ($this->getMode()) {
69  case self::MODE_TRASH_RESTORE:
70  $GLOBALS['DIC']['ilLog']->info('Restore trash to recovery folder');
71  $this->restore();
72  break;
73 
74  case self::MODE_TRASH_REMOVE:
75  $GLOBALS['DIC']['ilLog']->info('Remove selected from system.');
76  $GLOBALS['DIC']['ilLog']->info('Type limit: ' . print_r($this->getTypesLimit(), true));
77  $GLOBALS['DIC']['ilLog']->info('Age limit: ' . (string) $this->getAgeLimit());
78  $GLOBALS['DIC']['ilLog']->info('Number limit: ' . (string) $this->getNumberLimit());
79  $this->removeSelectedFromSystem();
80  return true;
81  }
82  }
83 
87  protected function restore()
88  {
89  $deleted = $this->readDeleted();
90 
91  $GLOBALS['DIC']['ilLog']->info('Found deleted : ' . print_r($deleted, true));
92 
93  $factory = new ilObjectFactory();
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['DIC']['tree']->deleteNode($deleted_info['tree'], $deleted_info['child']);
102  $GLOBALS['DIC']['ilLog']->info('Object tree entry deleted');
103 
104  if ($ref_obj->getType() != 'rolf') {
105  $GLOBALS['DIC']['rbacadmin']->revokePermission($deleted_info['child']);
106  $ref_obj->putInTree(RECOVERY_FOLDER_ID);
107  $ref_obj->setPermissions(RECOVERY_FOLDER_ID);
108  $GLOBALS['DIC']['ilLog']->info('Object moved to recovery folder');
109  }
110  }
111  }
112 
116  protected function removeSelectedFromSystem()
117  {
118  $factory = new ilObjectFactory();
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 $DIC;
142 
143  $ilDB = $DIC['ilDB'];
144 
145  $and_types = '';
146  ilLoggerFactory::getLogger('sysc')->dump($this->getTypesLimit());
147 
148  $types = array();
149  foreach ((array) $this->getTypesLimit() as $id => $type) {
150  if ($type) {
151  $types[] = $type;
152  }
153  }
154  if (count($types)) {
155  $and_types = 'AND ' . $ilDB->in('o.type', $this->getTypesLimit(), false, 'text') . ' ';
156  }
157 
158  $and_age = '';
159  $age_limit = $this->getAgeLimit()->get(IL_CAL_UNIX);
160  if ($age_limit > 0) {
161  $and_age = 'AND r.deleted < ' . $ilDB->quote($this->getAgeLimit()->get(IL_CAL_DATETIME)) . ' ';
162  }
163  $limit = '';
164  if ($this->getNumberLimit()) {
165  $limit = 'LIMIT ' . (int) $this->getNumberLimit();
166  }
167 
168  $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id ' .
169  'JOIN object_data o on r.obj_id = o.obj_id ' .
170  'WHERE tree < ' . $ilDB->quote(0, 'integer') . ' ' .
171  'AND child = -tree ';
172 
173  $query .= $and_age;
174  $query .= $and_types;
175  $query .= 'ORDER BY depth desc ';
176  $query .= $limit;
177 
178  $GLOBALS['DIC']['ilLog']->info($query);
179 
180  $deleted = array();
181  $res = $ilDB->query($query);
182  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
183  $deleted[] = array(
184  'tree' => $row->tree,
185  'child' => $row->child
186  );
187  }
188  return $deleted;
189  }
190 
191 
192 
193 
199  protected function readDeleted($tree_id = null)
200  {
201  global $DIC;
202 
203  $ilDB = $DIC['ilDB'];
204 
205  $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id ' .
206  'JOIN object_data o on r.obj_id = o.obj_id ';
207 
208  if ($tree_id === null) {
209  $query .= 'WHERE tree < ' . $ilDB->quote(0, 'integer') . ' ';
210  } else {
211  $query .= 'WHERE tree = ' . $ilDB->quote($tree_id, 'integer') . ' ';
212  }
213  $query .= 'ORDER BY depth desc';
214 
215  $res = $ilDB->query($query);
216 
217  $deleted = array();
218  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
219  $deleted[] = array(
220  'tree' => $row->tree,
221  'child' => $row->child
222  );
223  }
224  return $deleted;
225  }
226 }
readSelectedDeleted()
read deleted according to filter settings
Class ilObjectFactory.
const IL_CAL_DATETIME
$type
global $DIC
Definition: saml.php:7
static _removeEntry($a_tree, $a_child, $a_db_table="tree")
STATIC METHOD Removes a single entry from a tree.
readDeleted($tree_id=null)
Read deleted objects type $ilDB.
$factory
Definition: metadata.php:43
if(!array_key_exists('StateId', $_REQUEST)) $id
const IL_CAL_UNIX
Class for single dates.
foreach($_POST as $key=> $value) $res
Date and time handling
$query
$row
removeSelectedFromSystem()
remove (containers) from system
global $ilDB
static getLogger($a_component_id)
Get component logger.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
restore()
Restore to recovery folder.