ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSCCronTrash.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
29 class ilSCCronTrash extends CronJob
30 {
31  protected ilLanguage $lng;
32  protected ilTree $tree;
34 
35  public function __construct()
36  {
37  global $DIC;
38 
39  $this->lng = $DIC->language();
40  $this->tree = $DIC->repositoryTree();
41  $this->objDefinition = $DIC['objDefinition'];
42  $this->lng->loadLanguageModule('sysc');
43  }
44 
45  public function getId(): string
46  {
47  return 'sysc_trash';
48  }
49 
50  public function getTitle(): string
51  {
52  return $this->lng->txt('sysc_cron_empty_trash');
53  }
54 
55  public function getDescription(): string
56  {
57  return $this->lng->txt('sysc_cron_empty_trash_desc');
58  }
59 
61  {
62  return JobScheduleType::WEEKLY;
63  }
64 
65  public function getValidScheduleTypes(): array
66  {
67  return [
68  JobScheduleType::DAILY,
69  JobScheduleType::WEEKLY,
70  JobScheduleType::MONTHLY,
71  JobScheduleType::QUARTERLY,
73  ];
74  }
75 
76  public function getDefaultScheduleValue(): ?int
77  {
78  return 1;
79  }
80 
81  public function hasAutoActivation(): bool
82  {
83  return false;
84  }
85 
86  public function hasFlexibleSchedule(): bool
87  {
88  return true;
89  }
90 
91  public function hasCustomSettings(): bool
92  {
93  return true;
94  }
95 
96  public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
97  {
98  $this->lng->loadLanguageModule('sysc');
99 
100  $settings = new ilSetting('sysc');
101 
102  // limit number
103  $num = new ilNumberInputGUI($this->lng->txt('sysc_trash_limit_num'), 'number');
104  $num->allowDecimals(false);
105  $num->setInfo($this->lng->txt('purge_count_limit_desc'));
106  $num->setSize(10);
107  $num->setMinValue(1);
108  $num->setValue($settings->get('num', ''));
109  $a_form->addItem($num);
110 
111  $age = new ilNumberInputGUI($this->lng->txt('sysc_trash_limit_age'), 'age');
112  $age->allowDecimals(false);
113  $age->setInfo($this->lng->txt('purge_age_limit_desc'));
114  $age->setSize(4);
115  $age->setMinValue(1);
116  $age->setMaxLength(4);
117 
118  if ($settings->get('age', '')) {
119  $age->setValue($settings->get('age', ''));
120  }
121 
122  $a_form->addItem($age);
123 
124  // limit types
125  $types = new ilSelectInputGUI($this->lng->txt('sysc_trash_limit_type'), 'types');
126  $sub_objects = $this->tree->lookupTrashedObjectTypes();
127 
128  $options = [];
129  $options[0] = '';
130  foreach ($sub_objects as $obj_type) {
131  if (!$this->objDefinition->isRBACObject($obj_type) || !$this->objDefinition->isAllowedInRepository($obj_type)) {
132  continue;
133  }
134  $options[$obj_type] = $this->lng->txt('obj_' . $obj_type);
135  }
136  asort($options);
137  $types->setOptions($options);
138  $types->setValue($settings->get('types', ''));
139  $a_form->addItem($types);
140  }
141 
142  public function saveCustomSettings(ilPropertyFormGUI $a_form): bool
143  {
144  $settings = new ilSetting('sysc');
145 
146  if ((string) $a_form->getInput('number') === '') {
147  $settings->delete('num');
148  } else {
149  $settings->set('num', (string) ((int) $a_form->getInput('number')));
150  }
151 
152  if ((string) $a_form->getInput('age') === '') {
153  $settings->delete('age');
154  } else {
155  $settings->set('age', (string) ((int) $a_form->getInput('age')));
156  }
157 
158  if ($a_form->getInput('types') === '') {
159  $settings->delete('types');
160  } else {
161  $settings->set('types', $a_form->getInput('types'));
162  }
163 
164  return true; // #18579
165  }
166 
167  public function run(): JobResult
168  {
169  $trash = new ilSystemCheckTrash();
170  $trash->setMode(ilSystemCheckTrash::MODE_TRASH_REMOVE);
171 
172  $settings = new ilSetting('sysc');
173 
174  $trash->setNumberLimit((int) $settings->get('num', '0'));
175  $trash->setTypesLimit(array_filter([$settings->get('types', '')]));
176 
177  $age = (int) $settings->get('age', '0');
178  if ($age) {
179  $date = new ilDateTime(time(), IL_CAL_UNIX);
180  $date->increment(IL_CAL_DAY, $age * -1);
181  $trash->setAgeLimit($date);
182  }
183  $trash->start();
184 
185  $result = new JobResult();
186  $result->setStatus(JobResult::STATUS_OK);
187  return $result;
188  }
189 }
This class represents a selection list property in a property form.
ilObjectDefinition $objDefinition
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.
allowDecimals(bool $a_value)
const IL_CAL_DAY
This class represents a number property in a property form.
global $DIC
Definition: shib_login.php:22
addCustomSettingsToForm(ilPropertyFormGUI $a_form)