ILIAS  release_8 Revision v8.24
class.ilSCTreeTasksGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
23
30{
31 protected const TYPE_DUPLICATES = 'duplicates';
32 public const TYPE_DUMP = 'dump';
33 protected const TYPE_MISSING = 'missing_reference';
34 protected const TYPE_MISSING_TREE = 'missing_tree';
35 protected const TYPE_STRUCTURE = 'structure';
36
37 protected ilTree $tree;
39 protected Factory $refinery;
41
42 public function __construct(ilSCTask $task = null)
43 {
44 global $DIC;
46
47 $this->tree = $DIC->repositoryTree();
48 $this->http = $DIC->http();
49 $this->refinery = $DIC->refinery();
50 $this->db = $DIC->database();
51 }
52
53 protected function getDuplicateIdFromRequest(): int
54 {
55 if ($this->http->wrapper()->query()->has('duplicate_id')) {
56 return $this->http->wrapper()->query()->retrieve(
57 'duplicate_id',
58 $this->refinery->kindlyTo()->int()
59 );
60 }
61 return 0;
62 }
63
64 public function getGroupTitle(): string
65 {
66 return $this->getLang()->txt('sysc_grp_tree');
67 }
68
69 public function getGroupDescription(): string
70 {
71 return $this->getLang()->txt('sysc_grp_tree_desc');
72 }
73
74 public function getTitle(): string
75 {
76 switch ($this->getTask()->getIdentifier()) {
77 case self::TYPE_DUMP:
78 return $this->getLang()->txt('sysc_task_tree_dump');
79
81 return $this->getLang()->txt('sysc_task_tree_duplicates');
82
84 return $this->getLang()->txt('sysc_task_tree_missing_reference');
85
87 return $this->getLang()->txt('sysc_task_tree_missing_tree');
88
90 return $this->getLang()->txt('sysc_task_structure');
91 }
92 return '';
93 }
94
95 public function getDescription(): string
96 {
97 switch ($this->getTask()->getIdentifier()) {
98 case self::TYPE_DUMP:
99 return $this->getLang()->txt('sysc_task_tree_dump_desc');
100
102 return $this->getLang()->txt('sysc_task_tree_duplicates_desc');
103
105 return $this->getLang()->txt('sysc_task_tree_missing_reference_desc');
106
108 return $this->getLang()->txt('sysc_task_tree_missing_tree_desc');
109
111 return $this->getLang()->txt('sysc_task_structure_desc');
112 }
113 return '';
114 }
115
116 public function getActions(): array
117 {
118 $repair = false;
119 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
120 $repair = true;
121 }
122
123 $actions = array();
124 switch ($this->getTask()->getIdentifier()) {
126
127 $actions[] = array(
128 'txt' => $this->getLang()->txt('sysc_action_validate'),
129 'command' => 'validateDuplicates'
130 );
131
132 if ($repair) {
133 $actions[] = array(
134 'txt' => $this->getLang()->txt('sysc_action_repair'),
135 'command' => 'repairDuplicates'
136 );
137 }
138 break;
139
140 case self::TYPE_DUMP:
141
142 $validator = new ilValidator();
143 if ($validator->hasScanLog()) {
144 $actions[] = array(
145 'txt' => $this->getLang()->txt('sysc_action_show_tree'),
146 'command' => 'showTree'
147 );
148 }
149
150 $actions[] = array(
151 'txt' => $this->getLang()->txt('sysc_action_list_tree'),
152 'command' => 'listTree'
153 );
154 break;
155
157
158 $actions[] = array(
159 'txt' => $this->getLang()->txt('sysc_action_validate'),
160 'command' => 'findMissing'
161 );
162
163 if ($repair) {
164 $actions[] = array(
165 'txt' => $this->getLang()->txt('sysc_action_repair'),
166 'command' => 'confirmRepairMissing'
167 );
168 }
169 break;
170
172
173 $actions[] = array(
174 'txt' => $this->getLang()->txt('sysc_action_validate'),
175 'command' => 'findMissingTreeEntries'
176 );
177
178 if ($repair) {
179 $actions[] = array(
180 'txt' => $this->getLang()->txt('sysc_action_repair'),
181 'command' => 'confirmRepairMissingTreeEntries'
182 );
183 }
184 break;
185
187
188 $actions[] = array(
189 'txt' => $this->getLang()->txt('sysc_action_validate'),
190 'command' => 'analyzeStructure'
191 );
192
193 if ($repair) {
194 $actions[] = array(
195 'txt' => $this->getLang()->txt('sysc_action_repair'),
196 'command' => 'confirmRepairStructure'
197 );
198 }
199 break;
200
201 }
202 return $actions;
203 }
204
205 public function analyzeStructure(): void
206 {
207 $tasks = new ilSCTreeTasks($this->getTask());
208 $num_failures = $tasks->validateStructure();
209
210 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
211 // error message
212 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_structure_failures') . ' ' . $num_failures, true);
213 } else {
214 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
215 }
216 $this->getCtrl()->returnToParent($this);
217 }
218
219 protected function confirmRepairStructure(): void
220 {
222 $this->getLang()->txt('sysc_message_tree_structure_confirm'),
223 $this->getLang()->txt('sysc_btn_tree_structure'),
224 'repairStructure'
225 );
226 }
227
228 protected function repairStructure(): void
229 {
230 $tasks = new ilSCTreeTasks($this->getTask());
231
232 if ($this->tree->getTreeImplementation() instanceof ilMaterializedPathTree) {
234 } elseif ($this->tree->getTreeImplementation() instanceof ilNestedSetTree) {
235 $this->tree->renumber(ROOT_FOLDER_ID);
236 }
237
238 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
239 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
240 $this->getTask()->update();
241
242 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
243 $this->getCtrl()->returnToParent($this);
244 }
245
246 public function listTree(): void
247 {
248 $validator = new ilValidator(true);
249 $errors_count = $validator->dumpTree();
250
251 if ($errors_count) {
252 $this->getTask()->setStatus(ilSCTask::STATUS_FAILED);
253 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_list_failures') . ' ' . $errors_count, true);
254 } else {
255 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
256 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_message_success'), true);
257 }
258
259 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
260 $this->getTask()->update();
261
262 $this->getCtrl()->returnToParent($this);
263 }
264
265 public function showTree(): void
266 {
267 $validator = new ilValidator();
268 $scan_log = $validator->readScanLog();
269
270 if (is_array($scan_log)) {
271 $scan_log = '<pre>' . implode("", $scan_log) . '</pre>';
272 $this->tpl->setContent($scan_log);
273 }
274 }
275
276 public function validateDuplicates(): void
277 {
278 $tasks = new ilSCTreeTasks($this->getTask());
279 $num_failures = $tasks->validateDuplicates();
280
281 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
282 // error message
283 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_duplicate_failures') . ' ' . $num_failures, true);
284 } else {
285 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
286 }
287 $this->getCtrl()->returnToParent($this);
288 }
289
290 protected function repairDuplicates(): void
291 {
292 $deepest_duplicate = ilSCTreeTasks::findDeepestDuplicate();
293
294 $table = new ilSCTreeDuplicatesTableGUI($this, 'repairTask');
295 $table->init();
296 $table->parse($deepest_duplicate);
297
298 $this->tpl->setContent($table->getHTML());
299 }
300
301 protected function deleteDuplicatesFromRepository(): void
302 {
304
305 $tasks = new ilSCTreeTasks($this->getTask());
306 if ($tasks->checkDuplicates()) {
308 }
309
310 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_deleted_duplicate'), true);
311 $this->getCtrl()->returnToParent($this);
312 }
313
314 protected function deleteDuplicatesFromTrash(): void
315 {
317
318 $tasks = new ilSCTreeTasks($this->getTask());
319 if ($tasks->checkDuplicates()) {
321 }
322
323 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_deleted_duplicate'), true);
324 $this->getCtrl()->returnToParent($this);
325 }
326
327 protected function findMissing(): void
328 {
329 $tasks = new ilSCTreeTasks($this->getTask());
330 $num_failures = $tasks->findMissing();
331
332 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
333 // error message
334 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_missing_failures') . ' ' . $num_failures, true);
335 } else {
336 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
337 }
338 $this->getCtrl()->returnToParent($this);
339 }
340
341 protected function confirmRepairMissing(): void
342 {
344 $this->getLang()->txt('sysc_message_tree_missing_confirm'),
345 $this->getLang()->txt('sysc_btn_tree_missing'),
346 'repairMissing'
347 );
348 }
349
350 protected function repairMissing(): void
351 {
352 $tasks = new ilSCTreeTasks($this->getTask());
353 $tasks->repairMissing();
354
355 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
356 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
357 $this->getTask()->update();
358
359 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
360 $this->getCtrl()->returnToParent($this);
361 }
362
363 protected function findMissingTreeEntries(): void
364 {
365 $tasks = new ilSCTreeTasks($this->getTask());
366 $num_failures = $tasks->findMissingTreeEntries();
367
368 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
369 // error message
370 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_missing_tree_failures') . ' ' . $num_failures, true);
371 } else {
372 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
373 }
374 $this->getCtrl()->returnToParent($this);
375 }
376
377 protected function confirmRepairMissingTreeEntries(): void
378 {
380 $this->getLang()->txt('sysc_message_tree_missing_confirm'),
381 $this->getLang()->txt('sysc_btn_tree_missing'),
382 'repairMissingTreeEntries'
383 );
384 }
385
386 protected function repairMissingTreeEntries(): void
387 {
388 $tasks = new ilSCTreeTasks($this->getTask());
389 $tasks->repairMissingTreeEntries();
390
391 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
392 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
393 $this->getTask()->update();
394
395 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
396 $this->getCtrl()->returnToParent($this);
397 }
398}
Builds data types.
Definition: Factory.php:21
const IL_CAL_UNIX
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static createFromParentRelation(ilDBInterface $db)
Base class for nested set path based trees.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showSimpleConfirmation(string $a_text, string $a_btn_text, string $a_cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const STATUS_COMPLETED
const STATUS_FAILED
Handles tree tasks.
__construct(ilSCTask $task=null)
getActions()
array( 'txt' => $lng->txt('sysc_action_repair') 'command' => 'repairTask' );
Defines a system check task.
static findDeepestDuplicate()
static deleteDuplicateFromTree(int $a_duplicate_id, bool $a_delete_trash)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
Interface GlobalHttpState.
Interface ilDBInterface.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc