ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSCTreeTasksGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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 return $actions;
202 }
203
204 public function analyzeStructure(): void
205 {
206 $tasks = new ilSCTreeTasks($this->getTask());
207 $num_failures = $tasks->validateStructure();
208
209 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
210 // error message
211 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_structure_failures') . ' ' . $num_failures, true);
212 } else {
213 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
214 }
215 $this->getCtrl()->returnToParent($this);
216 }
217
218 protected function confirmRepairStructure(): void
219 {
221 $this->getLang()->txt('sysc_message_tree_structure_confirm'),
222 $this->getLang()->txt('sysc_btn_tree_structure'),
223 'repairStructure'
224 );
225 }
226
227 protected function repairStructure(): void
228 {
229 $tasks = new ilSCTreeTasks($this->getTask());
230
231 if ($this->tree->getTreeImplementation() instanceof ilMaterializedPathTree) {
233 } elseif ($this->tree->getTreeImplementation() instanceof ilNestedSetTree) {
234 $this->tree->renumber(ROOT_FOLDER_ID);
235 }
236
237 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
238 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
239 $this->getTask()->update();
240
241 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
242 $this->getCtrl()->returnToParent($this);
243 }
244
245 public function listTree(): void
246 {
247 $validator = new ilValidator(true);
248 $errors_count = $validator->dumpTree();
249
250 if ($errors_count) {
251 $this->getTask()->setStatus(ilSCTask::STATUS_FAILED);
252 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_list_failures') . ' ' . $errors_count, true);
253 } else {
254 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
255 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
256 }
257
258 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
259 $this->getTask()->update();
260
261 $this->getCtrl()->returnToParent($this);
262 }
263
264 public function showTree(): void
265 {
266 $validator = new ilValidator();
267 $scan_log = $validator->readScanLog();
268
269 if (is_array($scan_log)) {
270 $scan_log = '<pre>' . implode("", $scan_log) . '</pre>';
271 $this->tpl->setContent($scan_log);
272 }
273 }
274
275 public function validateDuplicates(): void
276 {
277 $tasks = new ilSCTreeTasks($this->getTask());
278 $num_failures = $tasks->validateDuplicates();
279
280 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
281 // error message
282 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_duplicate_failures') . ' ' . $num_failures, true);
283 } else {
284 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
285 }
286 $this->getCtrl()->returnToParent($this);
287 }
288
289 protected function repairDuplicates(): void
290 {
291 $deepest_duplicate = ilSCTreeTasks::findDeepestDuplicate();
292
293 $table = new ilSCTreeDuplicatesTableGUI($this, 'repairTask');
294 $table->init();
295 $table->parse($deepest_duplicate);
296
297 $this->tpl->setContent($table->getHTML());
298 }
299
300 protected function deleteDuplicatesFromRepository(): void
301 {
303
304 $tasks = new ilSCTreeTasks($this->getTask());
305 if ($tasks->checkDuplicates()) {
307 }
308
309 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_deleted_duplicate'), true);
310 $this->getCtrl()->returnToParent($this);
311 }
312
313 protected function deleteDuplicatesFromTrash(): void
314 {
316
317 $tasks = new ilSCTreeTasks($this->getTask());
318 if ($tasks->checkDuplicates()) {
320 }
321
322 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_deleted_duplicate'), true);
323 $this->getCtrl()->returnToParent($this);
324 }
325
326 protected function findMissing(): void
327 {
328 $tasks = new ilSCTreeTasks($this->getTask());
329 $num_failures = $tasks->findMissing();
330
331 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
332 // error message
333 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_missing_failures') . ' ' . $num_failures, true);
334 } else {
335 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
336 }
337 $this->getCtrl()->returnToParent($this);
338 }
339
340 protected function confirmRepairMissing(): void
341 {
343 $this->getLang()->txt('sysc_message_tree_missing_confirm'),
344 $this->getLang()->txt('sysc_btn_tree_missing'),
345 'repairMissing'
346 );
347 }
348
349 protected function repairMissing(): void
350 {
351 $tasks = new ilSCTreeTasks($this->getTask());
352 $tasks->repairMissing();
353
354 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
355 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
356 $this->getTask()->update();
357
358 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
359 $this->getCtrl()->returnToParent($this);
360 }
361
362 protected function findMissingTreeEntries(): void
363 {
364 $tasks = new ilSCTreeTasks($this->getTask());
365 $num_failures = $tasks->findMissingTreeEntries();
366
367 if ($this->getTask()->getStatus() == ilSCTask::STATUS_FAILED) {
368 // error message
369 $this->tpl->setOnScreenMessage('failure', $this->getLang()->txt('sysc_tree_missing_tree_failures') . ' ' . $num_failures, true);
370 } else {
371 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
372 }
373 $this->getCtrl()->returnToParent($this);
374 }
375
376 protected function confirmRepairMissingTreeEntries(): void
377 {
379 $this->getLang()->txt('sysc_message_tree_missing_confirm'),
380 $this->getLang()->txt('sysc_btn_tree_missing'),
381 'repairMissingTreeEntries'
382 );
383 }
384
385 protected function repairMissingTreeEntries(): void
386 {
387 $tasks = new ilSCTreeTasks($this->getTask());
388 $tasks->repairMissingTreeEntries();
389
390 $this->getTask()->setStatus(ilSCTask::STATUS_COMPLETED);
391 $this->getTask()->setLastUpdate(new ilDateTime(time(), IL_CAL_UNIX));
392 $this->getTask()->update();
393
394 $this->tpl->setOnScreenMessage('success', $this->getLang()->txt('sysc_message_success'), true);
395 $this->getCtrl()->returnToParent($this);
396 }
397}
Builds data types.
Definition: Factory.php:36
const IL_CAL_UNIX
@classDescription Date and time handling
Base class for materialize path based trees Based on implementation of Werner Randelshofer.
static createFromParentRelation(ilDBInterface $db)
Base class for nested set path based trees.
Abstract class for component tasks.
showSimpleConfirmation(string $a_text, string $a_btn_text, string $a_cmd)
Defines a system check task.
const STATUS_COMPLETED
const STATUS_FAILED
Handles tree tasks.
getActions()
array( 'txt' => $lng->txt('sysc_action_repair') 'command' => 'repairTask' );
__construct(?ilSCTask $task=null)
Defines a system check task.
static findDeepestDuplicate()
static deleteDuplicateFromTree(int $a_duplicate_id, bool $a_delete_trash)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
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
Interface GlobalHttpState.
Interface ilDBInterface.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26