Skip to content

Commit 8705ed2

Browse files
[FEATURE] Cron: Use "Component" mechanisms to gather and register jobs
Co-authored-by: Nils Haagen <nhaagen@concepts-and-training.de>
1 parent 7450173 commit 8705ed2

134 files changed

Lines changed: 2118 additions & 1799 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/ILIAS/Authentication/Authentication.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function offsetGet(mixed $offset): mixed
4747
}
4848
public function offsetSet(mixed $offset, mixed $value): void
4949
{
50-
if (!is_string($offset)) {
50+
if (!\is_string($offset)) {
5151
throw new \InvalidArgumentException('Offset needs to be of type string.');
5252
}
5353
\ilSession::set($offset, $value);
@@ -67,7 +67,14 @@ public function offsetUnset(mixed $offset): void
6767
new Component\Resource\Endpoint($this, 'sessioncheck.php');
6868
$contribute[Component\Resource\PublicAsset::class] = fn() =>
6969
new Component\Resource\ComponentJS($this, 'js/dist/SessionReminder.min.js');
70-
$contribute[User\Settings\UserSettings::class] = fn() =>
70+
$contribute[User\Settings\UserSettings::class] = static fn() =>
7171
new Authentication\UserSettings\Settings();
72+
73+
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
74+
new \ilAuthDestroyExpiredSessionsCron(
75+
self::class,
76+
$use[\ILIAS\Language\Language::class],
77+
$use[\ILIAS\Logging\LoggerFactory::class]
78+
);
7279
}
7380
}

components/ILIAS/Authentication/classes/Cron/class.ilAuthDestroyExpiredSessionsCron.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@
1919
declare(strict_types=1);
2020

2121
use ILIAS\Cron\Job\JobResult;
22-
use ILIAS\Cron\CronJob;
22+
use ILIAS\Cron\AbstractCronJob;
2323

24-
class ilAuthDestroyExpiredSessionsCron extends CronJob
24+
class ilAuthDestroyExpiredSessionsCron extends AbstractCronJob
2525
{
26-
protected ilLanguage $lng;
27-
28-
public function __construct()
26+
public function init(): void
2927
{
30-
global $DIC;
31-
32-
$this->lng = $DIC->language();
33-
$this->lng->loadLanguageModule('auth');
28+
$this->language->loadLanguageModule('auth');
3429
}
3530

3631
public function getId(): string
@@ -40,12 +35,12 @@ public function getId(): string
4035

4136
public function getTitle(): string
4237
{
43-
return $this->lng->txt('auth_cron_destroy_expired_sessions');
38+
return $this->language->txt('auth_cron_destroy_expired_sessions');
4439
}
4540

4641
public function getDescription(): string
4742
{
48-
return $this->lng->txt('auth_cron_destroy_expired_sessions_desc');
43+
return $this->language->txt('auth_cron_destroy_expired_sessions_desc');
4944
}
5045

5146
public function hasAutoActivation(): bool

components/ILIAS/Authentication/service.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@
2323
<pluginslot id="authhk" name="AuthenticationHook" />
2424
</pluginslots>
2525
<logging />
26-
<crons>
27-
<cron id="auth_destroy_expired_sessions" class="ilAuthDestroyExpiredSessionsCron" />
28-
</crons>
2926
</service>

components/ILIAS/BookingManager/BookingManager.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,18 @@ public function init(
3939

4040
$contribute[Component\Resource\PublicAsset::class] = fn() =>
4141
new Component\Resource\ComponentJS($this, "ScheduleInput.js");
42+
43+
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
44+
new \ilBookCronNotification(
45+
self::class,
46+
$use[\ILIAS\Language\Language::class],
47+
$use[\ILIAS\Logging\LoggerFactory::class]
48+
);
49+
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
50+
new \ilBookingPrefBookCron(
51+
self::class,
52+
$use[\ILIAS\Language\Language::class],
53+
$use[\ILIAS\Logging\LoggerFactory::class]
54+
);
4255
}
4356
}

components/ILIAS/BookingManager/classes/class.ilBookCronNotification.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@
1818

1919
use ILIAS\Cron\Job\Schedule\JobScheduleType;
2020
use ILIAS\Cron\Job\JobResult;
21-
use ILIAS\Cron\CronJob;
21+
use ILIAS\Cron\AbstractCronJob;
2222

2323
/**
2424
* Cron for booking manager notification
2525
* @author Alexander Killing <killing@leifos.de>
2626
*/
27-
class ilBookCronNotification extends CronJob
27+
class ilBookCronNotification extends AbstractCronJob
2828
{
2929
protected \ILIAS\BookingManager\InternalRepoService $repo;
30-
protected ilLanguage $lng;
3130
protected ilLogger $book_log;
3231

33-
public function __construct()
32+
public function init(): void
3433
{
3534
global $DIC;
3635

37-
$this->lng = $DIC->language();
36+
$this->language->loadLanguageModule('book');
3837

39-
$this->book_log = ilLoggerFactory::getLogger("book");
38+
$this->book_log = $this->logger_factory->getComponentLogger('book');
4039
$this->repo = $DIC->bookingManager()
4140
->internal()
4241
->repo();
@@ -49,18 +48,12 @@ public function getId(): string
4948

5049
public function getTitle(): string
5150
{
52-
$lng = $this->lng;
53-
54-
$lng->loadLanguageModule("book");
55-
return $lng->txt("book_notification");
51+
return $this->language->txt("book_notification");
5652
}
5753

5854
public function getDescription(): string
5955
{
60-
$lng = $this->lng;
61-
62-
$lng->loadLanguageModule("book");
63-
return $lng->txt("book_notification_info");
56+
return $this->language->txt("book_notification_info");
6457
}
6558

6659
public function getDefaultScheduleType(): JobScheduleType

components/ILIAS/BookingManager/classes/class.ilBookingPrefBookCron.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,34 @@
1818

1919
use ILIAS\Cron\Job\Schedule\JobScheduleType;
2020
use ILIAS\Cron\Job\JobResult;
21-
use ILIAS\Cron\CronJob;
21+
use ILIAS\Cron\AbstractCronJob;
2222

2323
/**
2424
* Cron for booking pools
2525
* - Automatic booking for overdue pools with booking by preferences
2626
*
2727
* @author Alexander Killing <killing@leifos.de>
2828
*/
29-
class ilBookingPrefBookCron extends CronJob
29+
class ilBookingPrefBookCron extends AbstractCronJob
3030
{
31-
protected ilLanguage $lng;
32-
33-
public function __construct()
31+
public function getId(): string
3432
{
35-
global $DIC;
36-
37-
$this->lng = $DIC->language();
33+
return "book_pref_book";
3834
}
3935

40-
public function getId(): string
36+
public function init(): void
4137
{
42-
return "book_pref_book";
38+
$this->language->loadLanguageModule('book');
4339
}
4440

4541
public function getTitle(): string
4642
{
47-
$lng = $this->lng;
48-
49-
$lng->loadLanguageModule("book");
50-
51-
return $lng->txt("book_pref_book_cron");
43+
return $this->language->txt("book_pref_book_cron");
5244
}
5345

5446
public function getDescription(): string
5547
{
56-
$lng = $this->lng;
57-
58-
$lng->loadLanguageModule("book");
59-
60-
return $lng->txt("book_pref_book_cron_info");
48+
return $this->language->txt("book_pref_book_cron_info");
6149
}
6250

6351
public function getDefaultScheduleType(): JobScheduleType

components/ILIAS/BookingManager/module.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,5 @@
2121
<web_access_checker>
2222
<secure_path path="ilBookingManager" checking-class="ilObjBookingPoolAccess"/>
2323
</web_access_checker>
24-
<crons>
25-
<cron id="book_notification" class="ilBookCronNotification" />
26-
<cron id="book_pref_book" class="ilBookingPrefBookCron" />
27-
</crons>
2824
<logging />
2925
</module>

components/ILIAS/COPage/COPage.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,11 @@ public function getTarget(): string
123123
}
124124
};
125125

126+
$contribute[\ILIAS\Cron\CronJob::class] = static fn() =>
127+
new \ilCleanCOPageHistoryCronjob(
128+
self::class,
129+
$use[\ILIAS\Language\Language::class],
130+
$use[\ILIAS\Logging\LoggerFactory::class]
131+
);
126132
}
127133
}

components/ILIAS/COPage/Cron/class.ilCleanCOPageHistoryCronjob.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@
2121
use ILIAS\COPage\History\HistoryManager;
2222
use ILIAS\Cron\Job\Schedule\JobScheduleType;
2323
use ILIAS\Cron\Job\JobResult;
24-
use ILIAS\Cron\CronJob;
24+
use ILIAS\Cron\AbstractCronJob;
2525

2626
/**
2727
* @author Alexander Killing <killing@leifos.de>
2828
*/
29-
class ilCleanCOPageHistoryCronjob extends CronJob
29+
class ilCleanCOPageHistoryCronjob extends AbstractCronJob
3030
{
3131
protected HistoryManager $history_manager;
3232
protected ilSetting $settings;
33-
protected ilLanguage $lng;
3433

35-
public function __construct()
34+
public function init(): void
3635
{
3736
global $DIC;
3837

39-
$this->lng = $DIC->language();
38+
$this->language->loadLanguageModule("copg");
39+
4040
$this->settings = $DIC->settings();
4141
$this->history_manager = $DIC
4242
->copage()
@@ -52,18 +52,12 @@ public function getId(): string
5252

5353
public function getTitle(): string
5454
{
55-
$lng = $this->lng;
56-
57-
$lng->loadLanguageModule("copg");
58-
return $lng->txt("copg_history_cleanup_cron");
55+
return $this->language->txt("copg_history_cleanup_cron");
5956
}
6057

6158
public function getDescription(): string
6259
{
63-
$lng = $this->lng;
64-
65-
$lng->loadLanguageModule("copg");
66-
return $lng->txt("copg_history_cleanup_cron_info");
60+
return $this->language->txt("copg_history_cleanup_cron_info");
6761
}
6862

6963
public function getDefaultScheduleType(): JobScheduleType
@@ -117,7 +111,7 @@ public function run(): JobResult
117111

118112
public function addCustomSettingsToForm(ilPropertyFormGUI $a_form): void
119113
{
120-
$lng = $this->lng;
114+
$lng = $this->language;
121115
$lng->loadLanguageModule("copg");
122116

123117
$ti = new ilNumberInputGUI(

components/ILIAS/COPage/service.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
<pageobject parent_type="stys" class_name="ilPageLayoutPage" directory="Layout/classes"/>
3939
</copage>
4040
<logging />
41-
<crons>
42-
<cron id="copg_history_cleanup" class="ilCleanCOPageHistoryCronjob" path="Services/COPage/Cron" />
43-
</crons>
4441
<objects>
4542
<object id="adve" class_name="AdvancedEditing" dir="classes"
4643
checkbox="0" inherit="0" translate="sys" rbac="1" system="1" administration="1">

0 commit comments

Comments
 (0)