Skip to content

Commit d3d7404

Browse files
committed
Component/Filesystem: contribute cron jobs
1 parent 8507815 commit d3d7404

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

components/ILIAS/Filesystem/Filesystem.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,12 @@ public function init(
3636
new \ilFileSystemSetupAgent(
3737
$pull[\ILIAS\Refinery\Factory::class]
3838
);
39+
40+
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
41+
new \ilFileSystemCleanTempDirCron(
42+
'components\\' . self::class,
43+
$use[\ILIAS\Language\Language::class],
44+
true
45+
);
3946
}
4047
}

components/ILIAS/Filesystem/classes/class.ilFileSystemCleanTempDirCron.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,25 @@
2828
class ilFileSystemCleanTempDirCron extends ilCronJob
2929
{
3030
protected \ILIAS\Filesystem\Filesystem $filesystem;
31-
32-
protected ilLanguage $language;
33-
3431
protected ilLogger $logger;
3532

36-
/**
37-
* @inheritDoc
38-
*/
39-
public function __construct()
33+
public function __construct(
34+
string $component,
35+
\ILIAS\Language\Language $lng,
36+
bool $registration = false
37+
) {
38+
parent::__construct($component, $lng);
39+
if (!$registration) {
40+
$this->additionalConstruct();
41+
}
42+
}
43+
44+
private function additionalConstruct()
4045
{
4146
/**
4247
* @var $DIC Container
4348
*/
4449
global $DIC;
45-
if ($DIC->offsetExists('lng')) {
46-
$this->language = $DIC['lng'];
47-
}
4850
if ($DIC->offsetExists('filesystem')) {
4951
$this->filesystem = $DIC->filesystem()->temp();
5052
}
@@ -64,12 +66,12 @@ public function getId(): string
6466

6567
public function getTitle(): string
6668
{
67-
return $this->language->txt('file_system_clean_temp_dir_cron');
69+
return $this->lng->txt('file_system_clean_temp_dir_cron');
6870
}
6971

7072
public function getDescription(): string
7173
{
72-
return $this->language->txt("file_system_clean_temp_dir_cron_info");
74+
return $this->lng->txt("file_system_clean_temp_dir_cron_info");
7375
}
7476

7577
public function hasAutoActivation(): bool
@@ -128,7 +130,7 @@ public function run(): ilCronJobResult
128130
$folders = $this->filesystem->finder()->in([""]);
129131
$folders = $folders->directories();
130132
$folders = $folders->date($date);
131-
$folders = $folders->sort(fn (
133+
$folders = $folders->sort(fn(
132134
Metadata $a,
133135
Metadata $b
134136
): int => strlen($a->getPath()) - strlen($b->getPath()));

components/ILIAS/Filesystem/service.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
id="filesys">
44
<baseclasses>
55
</baseclasses>
6-
<crons>
7-
<cron id="file_system_clean_temp_dir" class="ilFileSystemCleanTempDirCron" />
8-
</crons>
96
</service>

0 commit comments

Comments
 (0)