ILIAS  release_8 Revision v8.23
class.ilSCCronTrash.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
25 class ilSCCronTrash extends ilCronJob
26 {
27  protected ilLanguage $lng;
28  protected ilTree $tree;
30 
31  public function __construct()
32  {
33  global $DIC;
34 
35  $this->lng = $DIC->language();
36  $this->tree = $DIC->repositoryTree();
37  $this->objDefinition = $DIC['objDefinition'];
38  $this->lng->loadLanguageModule('sysc');
39  }
40 
41  public function getId(): string
42  {
43  return 'sysc_trash';
44  }
45 
46  public function getTitle(): string
47  {
48  return $this->lng->txt('sysc_cron_empty_trash');
49  }
50 
51  public function getDescription(): string
52  {
53  return $this->lng->txt('sysc_cron_empty_trash_desc');
54  }
55 
56  public function getDefaultScheduleType(): int
57  {
58  return self::SCHEDULE_TYPE_WEEKLY;
59  }
60 
61  public function getValidScheduleTypes(): array
62  {
63  return [
64  self::SCHEDULE_TYPE_DAILY,
65  self::SCHEDULE_TYPE_WEEKLY,
66  self::SCHEDULE_TYPE_MONTHLY,
67  self::SCHEDULE_TYPE_QUARTERLY,
68  self::SCHEDULE_TYPE_YEARLY
69  ];
70  }
71 
72  public function getDefaultScheduleValue(): ?int
73  {
74  return 1;
75  }
76 
77  public function hasAutoActivation(): bool
78  {
79  return false;
80  }
81 
82  public function hasFlexibleSchedule(): bool
83  {
84  return true;
85  }
86 
87  public function hasCustomSettings(): bool
88  {
89  return true;
90  }
91 
92  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
93  {
94  $this->lng->loadLanguageModule('sysc');
95 
96  $settings = new ilSetting('sysc');
97 
98  // limit number
99  $num = new ilNumberInputGUI($this->lng->txt('sysc_trash_limit_num'), 'number');
100  $num->allowDecimals(false);
101  $num->setInfo($this->lng->txt('purge_count_limit_desc'));
102  $num->setSize(10);
103  $num->setMinValue(1);
104  $num->setValue($settings->get('num', ''));
105  $a_form->addItem($num);
106 
107  $age = new ilNumberInputGUI($this->lng->txt('sysc_trash_limit_age'), 'age');
108  $age->allowDecimals(false);
109  $age->setInfo($this->lng->txt('purge_age_limit_desc'));
110  $age->setSize(4);
111  $age->setMinValue(1);
112  $age->setMaxLength(4);
113 
114  if ($settings->get('age', '')) {
115  $age->setValue($settings->get('age', ''));
116  }
117 
118  $a_form->addItem($age);
119 
120  // limit types
121  $types = new ilSelectInputGUI($this->lng->txt('sysc_trash_limit_type'), 'types');
122  $sub_objects = $this->tree->lookupTrashedObjectTypes();
123 
124  $options = [];
125  $options[0] = '';
126  foreach ($sub_objects as $obj_type) {
127  if (!$this->objDefinition->isRBACObject($obj_type) || !$this->objDefinition->isAllowedInRepository($obj_type)) {
128  continue;
129  }
130  $options[$obj_type] = $this->lng->txt('obj_' . $obj_type);
131  }
132  asort($options);
133  $types->setOptions($options);
134  $types->setValue($settings->get('types', ''));
135  $a_form->addItem($types);
136  }
137 
138  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
139  {
140  $settings = new ilSetting('sysc');
141 
142  if ((string) $a_form->getInput('number') === '') {
143  $settings->delete('num');
144  } else {
145  $settings->set('num', (string) ((int) $a_form->getInput('number')));
146  }
147 
148  if ((string) $a_form->getInput('age') === '') {
149  $settings->delete('age');
150  } else {
151  $settings->set('age', (string) ((int) $a_form->getInput('age')));
152  }
153 
154  if ($a_form->getInput('types') === '') {
155  $settings->delete('types');
156  } else {
157  $settings->set('types', $a_form->getInput('types'));
158  }
159 
160  return true; // #18579
161  }
162 
163  public function run(): ilCronJobResult
164  {
165  $trash = new ilSystemCheckTrash();
166  $trash->setMode(ilSystemCheckTrash::MODE_TRASH_REMOVE);
167 
168  $settings = new ilSetting('sysc');
169 
170  $trash->setNumberLimit((int) $settings->get('num', '0'));
171  $trash->setTypesLimit(array_filter([$settings->get('types', '')]));
172 
173  $age = (int) $settings->get('age', '0');
174  if ($age) {
175  $date = new ilDateTime(time(), IL_CAL_UNIX);
176  $date->increment(IL_CAL_DAY, $age * -1);
177  $trash->setAgeLimit($date);
178  }
179  $trash->start();
180 
181  $result = new ilCronJobResult();
182  $result->setStatus(ilCronJobResult::STATUS_OK);
183  return $result;
184  }
185 }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
ilObjectDefinition $objDefinition
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
saveCustomSettings(ilPropertyFormGUI $a_form)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
allowDecimals(bool $a_value)
parses the objects.xml it handles the xml-description of all ilias objects
const IL_CAL_DAY
This class represents a number property in a property form.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)