ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilSystemCheckTrash 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 ilSystemCheckTrash:

Public Member Functions

 __construct ()
 
 setNumberLimit (int $a_limit)
 
 getNumberLimit ()
 
 setAgeLimit (ilDateTime $dt)
 
 getAgeLimit ()
 
 setTypesLimit (array $a_types)
 
 getTypesLimit ()
 
 setMode (int $a_mode)
 
 getMode ()
 
 start ()
 

Data Fields

const MODE_TRASH_RESTORE = 1
 
const MODE_TRASH_REMOVE = 2
 

Protected Member Functions

 restore ()
 
 removeSelectedFromSystem ()
 
 readSelectedDeleted ()
 
 readDeleted (?int $tree_id=null)
 

Protected Attributes

ilLogger $logger
 
ilDBInterface $db
 
ilTree $tree
 
ilRbacAdmin $admin
 

Private Attributes

int $limit_number = 0
 
ilDateTime $limit_age
 
array $limit_types = array()
 
int $mode
 

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

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 23 of file class.ilSystemCheckTrash.php.

Constructor & Destructor Documentation

◆ __construct()

ilSystemCheckTrash::__construct ( )

Definition at line 38 of file class.ilSystemCheckTrash.php.

References $DIC, IL_CAL_UNIX, and ILIAS\Repository\logger().

39  {
40  global $DIC;
41 
42  $this->logger = $DIC->logger()->sysc();
43  $this->db = $DIC->database();
44  $this->tree = $DIC->repositoryTree();
45  $this->admin = $DIC->rbac()->admin();
46 
47  $this->limit_age = new ilDate(0, IL_CAL_UNIX);
48  }
const IL_CAL_UNIX
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ getAgeLimit()

ilSystemCheckTrash::getAgeLimit ( )

Definition at line 65 of file class.ilSystemCheckTrash.php.

References $limit_age.

Referenced by readSelectedDeleted(), and start().

65  : ilDateTime
66  {
67  return $this->limit_age;
68  }
+ Here is the caller graph for this function:

◆ getMode()

ilSystemCheckTrash::getMode ( )

Definition at line 85 of file class.ilSystemCheckTrash.php.

References $mode.

Referenced by start().

85  : int
86  {
87  return $this->mode;
88  }
+ Here is the caller graph for this function:

◆ getNumberLimit()

ilSystemCheckTrash::getNumberLimit ( )

Definition at line 55 of file class.ilSystemCheckTrash.php.

References $limit_number.

Referenced by readSelectedDeleted(), and start().

55  : int
56  {
57  return $this->limit_number;
58  }
+ Here is the caller graph for this function:

◆ getTypesLimit()

ilSystemCheckTrash::getTypesLimit ( )

Definition at line 75 of file class.ilSystemCheckTrash.php.

References $limit_types.

Referenced by readSelectedDeleted(), and start().

75  : array
76  {
77  return $this->limit_types;
78  }
+ Here is the caller graph for this function:

◆ readDeleted()

ilSystemCheckTrash::readDeleted ( ?int  $tree_id = null)
protected

Definition at line 207 of file class.ilSystemCheckTrash.php.

References $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by removeSelectedFromSystem(), and restore().

207  : array
208  {
209  $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id ' .
210  'JOIN object_data o on r.obj_id = o.obj_id ';
211 
212  if ($tree_id === null) {
213  $query .= 'WHERE tree < ' . $this->db->quote(0, 'integer') . ' ';
214  } else {
215  $query .= 'WHERE tree = ' . $this->db->quote($tree_id, 'integer') . ' ';
216  }
217  $query .= 'ORDER BY depth desc';
218 
219  $res = $this->db->query($query);
220 
221  $deleted = array();
222  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
223  $deleted[] = array(
224  'tree' => $row->tree,
225  'child' => $row->child
226  );
227  }
228  return $deleted;
229  }
$res
Definition: ltiservices.php:69
$query
+ Here is the caller graph for this function:

◆ readSelectedDeleted()

ilSystemCheckTrash::readSelectedDeleted ( )
protected

Definition at line 156 of file class.ilSystemCheckTrash.php.

References $id, $query, $res, $type, ilDBConstants\FETCHMODE_OBJECT, getAgeLimit(), getNumberLimit(), getTypesLimit(), IL_CAL_DATETIME, IL_CAL_UNIX, ILIAS\Repository\logger(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by removeSelectedFromSystem().

156  : array
157  {
158  $and_types = '';
159  $this->logger->dump($this->getTypesLimit());
160 
161  $types = array();
162  foreach ($this->getTypesLimit() as $id => $type) {
163  if ($type) {
164  $types[] = $type;
165  }
166  }
167  if (count($types)) {
168  $and_types = 'AND ' . $this->db->in('o.type', $this->getTypesLimit(), false, ilDBConstants::T_TEXT) . ' ';
169  }
170 
171  $and_age = '';
172  $age_limit = $this->getAgeLimit()->get(IL_CAL_UNIX);
173  if ($age_limit > 0) {
174  $and_age = 'AND r.deleted < ' . $this->db->quote(
175  $this->getAgeLimit()->get(IL_CAL_DATETIME),
177  ) . ' ';
178  }
179  $limit = '';
180  if ($this->getNumberLimit()) {
181  $limit = 'LIMIT ' . $this->getNumberLimit();
182  }
183 
184  $query = 'SELECT child,tree FROM tree t JOIN object_reference r ON child = r.ref_id ' .
185  'JOIN object_data o on r.obj_id = o.obj_id ' .
186  'WHERE tree < ' . $this->db->quote(0, ilDBConstants::T_INTEGER) . ' ' .
187  'AND child = -tree ';
188 
189  $query .= $and_age;
190  $query .= $and_types;
191  $query .= 'ORDER BY depth desc ';
192  $query .= $limit;
193 
194  $this->logger->info($query);
195 
196  $deleted = array();
197  $res = $this->db->query($query);
198  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199  $deleted[] = array(
200  'tree' => $row->tree,
201  'child' => $row->child
202  );
203  }
204  return $deleted;
205  }
$res
Definition: ltiservices.php:69
const IL_CAL_DATETIME
$type
const IL_CAL_UNIX
$query
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeSelectedFromSystem()

ilSystemCheckTrash::removeSelectedFromSystem ( )
protected

Definition at line 138 of file class.ilSystemCheckTrash.php.

References ilTree\_removeEntry(), ilObjectFactory\getInstanceByRefId(), readDeleted(), and readSelectedDeleted().

Referenced by start().

138  : void
139  {
140  $deleted = $this->readSelectedDeleted();
141  foreach ($deleted as $del_num => $deleted_info) {
142  $sub_nodes = $this->readDeleted((int) ($deleted_info['tree'] ?? 0));
143 
144  foreach ($sub_nodes as $sub_num => $subnode_info) {
145  $ref_obj = ilObjectFactory::getInstanceByRefId((int) ($subnode_info['child'] ?? 0), false);
146  if (!$ref_obj instanceof ilObject) {
147  continue;
148  }
149 
150  $ref_obj->delete();
151  ilTree::_removeEntry((int) ($subnode_info['tree'] ?? 0), (int) ($subnode_info['child'] ?? 0));
152  }
153  }
154  }
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
readDeleted(?int $tree_id=null)
static _removeEntry(int $a_tree, int $a_child, string $a_db_table="tree")
STATIC METHOD Removes a single entry from a tree.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ restore()

ilSystemCheckTrash::restore ( )
protected

Definition at line 112 of file class.ilSystemCheckTrash.php.

References ilObjectFactory\getInstanceByRefId(), ILIAS\Repository\int(), ILIAS\Repository\logger(), readDeleted(), and RECOVERY_FOLDER_ID.

Referenced by start().

112  : void
113  {
114  $deleted = $this->readDeleted();
115 
116  $this->logger->info('Found deleted : ' . print_r($deleted, true));
117 
118 
119  foreach ($deleted as $tmp_num => $deleted_info) {
120  $child_id = (int) ($deleted_info['child'] ?? 0);
121  $ref_obj = ilObjectFactory::getInstanceByRefId($child_id, false);
122  if (!$ref_obj instanceof ilObject) {
123  continue;
124  }
125 
126  $this->tree->deleteNode((int) ($deleted_info['tree'] ?? 0), $child_id);
127  $this->logger->info('Object tree entry deleted');
128 
129  if ($ref_obj->getType() !== 'rolf') {
130  $this->admin->revokePermission($child_id);
131  $ref_obj->putInTree(RECOVERY_FOLDER_ID);
132  $ref_obj->setPermissions(RECOVERY_FOLDER_ID);
133  $this->logger->info('Object moved to recovery folder');
134  }
135  }
136  }
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
readDeleted(?int $tree_id=null)
const RECOVERY_FOLDER_ID
Definition: constants.php:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAgeLimit()

ilSystemCheckTrash::setAgeLimit ( ilDateTime  $dt)

Definition at line 60 of file class.ilSystemCheckTrash.php.

60  : void
61  {
62  $this->limit_age = $dt;
63  }

◆ setMode()

ilSystemCheckTrash::setMode ( int  $a_mode)

Definition at line 80 of file class.ilSystemCheckTrash.php.

80  : void
81  {
82  $this->mode = $a_mode;
83  }

◆ setNumberLimit()

ilSystemCheckTrash::setNumberLimit ( int  $a_limit)

Definition at line 50 of file class.ilSystemCheckTrash.php.

50  : void
51  {
52  $this->limit_number = $a_limit;
53  }

◆ setTypesLimit()

ilSystemCheckTrash::setTypesLimit ( array  $a_types)

Definition at line 70 of file class.ilSystemCheckTrash.php.

70  : void
71  {
72  $this->limit_types = $a_types;
73  }

◆ start()

ilSystemCheckTrash::start ( )

Definition at line 90 of file class.ilSystemCheckTrash.php.

References getAgeLimit(), getMode(), getNumberLimit(), getTypesLimit(), ILIAS\Repository\logger(), removeSelectedFromSystem(), and restore().

90  : bool
91  {
92  $this->logger->info('Handling delete');
93  switch ($this->getMode()) {
94  case self::MODE_TRASH_RESTORE:
95  $this->logger->info('Restore trash to recovery folder');
96  $this->restore();
97  return true;
98  break;
99 
100  case self::MODE_TRASH_REMOVE:
101  $this->logger->info('Remove selected from system.');
102  $this->logger->info('Type limit: ' . print_r($this->getTypesLimit(), true));
103  $this->logger->info('Age limit: ' . $this->getAgeLimit());
104  $this->logger->info('Number limit: ' . $this->getNumberLimit());
105  $this->removeSelectedFromSystem();
106  return true;
107  break;
108  }
109  return false;
110  }
+ Here is the call graph for this function:

Field Documentation

◆ $admin

ilRbacAdmin ilSystemCheckTrash::$admin
protected

Definition at line 36 of file class.ilSystemCheckTrash.php.

◆ $db

ilDBInterface ilSystemCheckTrash::$db
protected

Definition at line 34 of file class.ilSystemCheckTrash.php.

◆ $limit_age

ilDateTime ilSystemCheckTrash::$limit_age
private

Definition at line 29 of file class.ilSystemCheckTrash.php.

Referenced by getAgeLimit().

◆ $limit_number

int ilSystemCheckTrash::$limit_number = 0
private

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

Referenced by getNumberLimit().

◆ $limit_types

array ilSystemCheckTrash::$limit_types = array()
private

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

Referenced by getTypesLimit().

◆ $logger

ilLogger ilSystemCheckTrash::$logger
protected

Definition at line 33 of file class.ilSystemCheckTrash.php.

◆ $mode

int ilSystemCheckTrash::$mode
private

Definition at line 31 of file class.ilSystemCheckTrash.php.

Referenced by getMode().

◆ $tree

ilTree ilSystemCheckTrash::$tree
protected

Definition at line 35 of file class.ilSystemCheckTrash.php.

◆ MODE_TRASH_REMOVE

const ilSystemCheckTrash::MODE_TRASH_REMOVE = 2

◆ MODE_TRASH_RESTORE

const ilSystemCheckTrash::MODE_TRASH_RESTORE = 1

Definition at line 25 of file class.ilSystemCheckTrash.php.

Referenced by ilObjSystemCheckGUI\initFormTrash().


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