ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
CleanupStage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use Psr\Log\LoggerInterface;
27
32class CleanupStage implements ImportStage
33{
34 public function __construct(private readonly LoggerInterface $log)
35 {
36 }
37
38 public function getIdentifier(): string
39 {
40 return 'cleanup';
41 }
42
43 public function getLabel(): ?string
44 {
45 return null;
46 }
47
48 public function getDescription(): ?string
49 {
50 return null;
51 }
52
53 public function process(ImportSession $session): StageResult
54 {
55 if ($session->hasFileToImport()) {
56 $temp_dir = dirname($session->fileToImport());
57 if ($temp_dir !== '' && file_exists($temp_dir) && is_dir($temp_dir)) {
58 $this->removeDirectory($temp_dir);
59 } else {
60 $this->log->warning("Temporary import directory does not exist: {$temp_dir}");
61 }
62 }
63
64 if ($session->hasImportBaseDir() && is_dir($session->importBaseDir())) {
65 $this->removeDirectory($session->importBaseDir());
66 } else {
67 $this->log->warning("Import target base directory does not exist: {$session->importBaseDir()}");
68 }
69
71 }
72
73 private function removeDirectory(string $path): void
74 {
75 foreach (array_diff(scandir($path), ['.', '..']) as $file) {
76 if (is_dir("$path/$file")) {
77 $this->removeDirectory("$path/$file");
78 } else {
79 unlink("$path/$file");
80 }
81 }
82
83 rmdir($path);
84 }
85}
Immutable JSON-capable import session shared by question pool and test wizards.
Final import stage that cleans up the temporary files and directories after successful import or erro...
process(ImportSession $session)
Process the current stage.
__construct(private readonly LoggerInterface $log)
getLabel()
Get the label of the stage which will be displayed in the workflow UI.
getIdentifier()
Get the unique identifier of the stage.
getDescription()
Get the description of the stage which will be displayed in the workflow UI.
$log
Definition: ltiauth.php:50