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