38 private \ILIAS\HTTP\GlobalHttpState
$http;
46 $this->main_tpl = $DIC->ui()->mainTemplate();
49 if (isset($DIC[
'http'])) {
50 $this->
http = $DIC->http();
53 if (isset($DIC[
'lng'])) {
54 $this->
lng = $DIC->language();
57 if (isset($DIC[
'refinery'])) {
61 if (isset($DIC[
'ilObjDataCache'])) {
62 $this->objectDataCache = $DIC[
'ilObjDataCache'];
65 if (isset($DIC[
'rbacreview'])) {
66 $this->rbacReview = $DIC->rbac()->review();
69 if (isset($DIC[
'cron.repository'])) {
70 $this->cronRepository = $DIC->cron()->repository();
73 if (isset($DIC[
'ilSetting'])) {
76 $include_roles = $DIC[
'ilSetting']->get(
77 'cron_inactive_user_delete_include_roles',
80 if ($include_roles === null) {
81 $this->include_roles = [];
83 $this->include_roles = array_filter(array_map(
'intval', explode(
',', $include_roles)));
87 'cron_inactive_user_delete_period',
88 (
string) self::DEFAULT_INACTIVITY_PERIOD
91 'cron_inactive_user_reminder_period',
92 (
string) self::DEFAULT_REMINDER_PERIOD
103 $number = (string) $number;
105 return strpos($number,
',') || strpos($number,
'.');
110 $time_difference = 0;
112 switch ($schedule_time) {
114 $time_difference = 86400;
117 $time_difference = 60 * $multiplier;
120 $time_difference = 3600 * $multiplier;
123 $time_difference = 86400 * $multiplier;
126 $time_difference = 604800;
129 $time_difference = 2629743;
132 $time_difference = 7889229;
135 $time_difference = 31556926;
139 return $time_difference;
144 return "user_inactive";
149 return $this->
lng->txt(
"delete_inactive_user_accounts");
154 return $this->
lng->txt(
"delete_inactive_user_accounts_desc");
159 return self::SCHEDULE_TYPE_DAILY;
186 $rbacreview = $DIC->rbac()->review();
187 $ilLog = $DIC[
'ilLog'];
191 $checkMail = $this->period - $reminder_time;
195 $userMailsDelivered = 0;
196 foreach ($usr_ids as $usr_id) {
202 foreach ($this->include_roles as $role_id) {
203 if ($rbacreview->isAssigned($usr_id, $role_id)) {
215 $timestamp_last_login = strtotime($user->getLastLogin());
216 $grace_period_over = time() - ($this->period * 24 * 60 * 60);
217 if ($timestamp_last_login < $grace_period_over) {
220 } elseif ($reminder_time > 0) {
221 $timestamp_for_deletion = $timestamp_last_login - $grace_period_over;
226 $account_will_be_deleted_on
229 $userMailsDelivered++;
241 "CRON - ilCronDeleteInactiveUserAccounts::run(), deleted " .
242 "=> $userDeleted User(s), sent reminder mail to $userMailsDelivered User(s)" 246 $result->setStatus($status);
253 $cron_timing = $this->cronRepository->getCronJobData($this->
getId());
254 $time_difference = 0;
257 if (!is_array($cron_timing) || !isset($cron_timing[0]) || !is_array($cron_timing[0])) {
258 return time() + $date_for_deletion + $time_difference;
261 if (array_key_exists(
'schedule_type', $cron_timing[0])) {
262 if ($cron_timing[0][
'schedule_value'] !== null) {
263 $multiplier = (
int) $cron_timing[0][
'schedule_value'];
266 (
int) $cron_timing[0][
'schedule_type'],
270 return time() + $date_for_deletion + $time_difference;
275 $this->
lng->loadLanguageModule(
"user");
278 $schedule->setTitle($this->
lng->txt(
'delete_inactive_user_accounts_frequency'));
279 $schedule->setInfo($this->
lng->txt(
'delete_inactive_user_accounts_frequency_desc'));
282 $this->
lng->txt(
'delete_inactive_user_accounts_include_roles'),
283 'cron_inactive_user_delete_include_roles' 285 $sub_mlist->
setInfo($this->
lng->txt(
'delete_inactive_user_accounts_include_roles_desc'));
287 foreach ($this->rbacReview->getGlobalRoles() as $role_id) {
289 $roles[$role_id] = $this->objectDataCache->lookupTitle($role_id);
292 $sub_mlist->setOptions($roles);
293 $setting = $this->
settings->get(
'cron_inactive_user_delete_include_roles', null);
294 if ($setting === null) {
297 $setting = explode(
',', $setting);
299 $sub_mlist->setValue($setting);
300 $sub_mlist->setWidth(300);
303 $default_setting = (string) self::DEFAULT_INACTIVITY_PERIOD;
306 $this->
lng->txt(
'delete_inactive_user_accounts_period'),
307 'cron_inactive_user_delete_period' 310 $sub_text->setInfo($this->
lng->txt(
'delete_inactive_user_accounts_period_desc'));
311 $sub_text->setValue($this->
settings->get(
"cron_inactive_user_delete_period", $default_setting));
312 $sub_text->setSize(4);
313 $sub_text->setMaxLength(4);
314 $sub_text->setRequired(
true);
318 $this->
lng->txt(
'send_mail_to_inactive_users'),
319 'cron_inactive_user_reminder_period' 322 $sub_period->setInfo($this->
lng->txt(
"send_mail_to_inactive_users_desc"));
323 $sub_period->setValue($this->
settings->get(
"cron_inactive_user_reminder_period", $default_setting));
324 $sub_period->setSuffix($this->
lng->txt(
"send_mail_to_inactive_users_suffix"));
325 $sub_period->setSize(4);
326 $sub_period->setMaxLength(4);
327 $sub_period->setRequired(
false);
328 $sub_period->setMinValue(0);
334 $this->
lng->loadLanguageModule(
"user");
338 $cron_period = $this->
http->wrapper()->post()->retrieve(
343 $cron_period_custom = 0;
345 $reminder_period =
'';
347 $empty_string_trafo = $this->
refinery->custom()->transformation(
static function ($value):
string {
352 throw new Exception(
'The value to be transformed is not an empty string');
355 if ($this->
http->wrapper()->post()->has(
'sdyi')) {
356 $cron_period_custom = $this->
http->wrapper()->post()->retrieve(
359 $this->refinery->kindlyTo()->int(),
365 if ($this->
http->wrapper()->post()->has(
'cron_inactive_user_delete_period')) {
366 $delete_period = $this->
http->wrapper()->post()->retrieve(
367 'cron_inactive_user_delete_period',
369 $this->refinery->kindlyTo()->int(),
371 $this->
refinery->kindlyTo()->float(),
378 if ($this->
http->wrapper()->post()->has(
'cron_inactive_user_reminder_period')) {
379 $reminder_period = $this->
http->wrapper()->post()->retrieve(
380 'cron_inactive_user_reminder_period',
383 $this->refinery->byTrying([
384 $this->refinery->kindlyTo()->int(),
386 $this->
refinery->kindlyTo()->float(),
397 $this->
lng->txt(
'send_mail_to_inactive_users_numbers_only')
401 if ($this->
isDecimal($reminder_period)) {
404 $this->
lng->txt(
'send_mail_to_inactive_users_numbers_only')
408 if ($reminder_period >= $delete_period) {
411 $this->
lng->txt(
'send_mail_to_inactive_users_must_be_smaller_than')
417 $check_window_logic = $delete_period - $reminder_period;
419 if ($check_window_logic < $cron_period_custom) {
423 if ($check_window_logic <= 7) {
427 if ($check_window_logic <= 31) {
431 if ($check_window_logic <= 92) {
435 if ($check_window_logic <= 366) {
443 $this->
lng->txt(
'send_mail_reminder_window_too_small')
448 if ($delete_period > 0) {
449 $roles = implode(
',', $this->
http->wrapper()->post()->retrieve(
450 'cron_inactive_user_delete_include_roles',
452 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->int()),
457 $this->
settings->set(
'cron_inactive_user_delete_include_roles', $roles);
458 $this->
settings->set(
'cron_inactive_user_delete_period', (
string) $delete_period);
461 if ($this->reminderTimer > $reminder_period) {
465 $this->
settings->set(
'cron_inactive_user_reminder_period', (
string) $reminder_period);
468 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"form_input_not_valid"));
ilGlobalTemplateInterface $main_tpl
ilCronJobRepository $cronRepository
getTimeDifferenceBySchedule(int $schedule_time, int $multiplier)
static getUserIdsByInactivityPeriod(int $periodInDays)
Get ids of all users that have been inactive for at least the given period.
static removeEntriesFromTableIfLastLoginIsNewer()
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
const SCHEDULE_TYPE_IN_MINUTES
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_MONTHLY
This will be replaced with an ENUM in ILIAS 9
ilObjectDataCache $objectDataCache
const SCHEDULE_TYPE_WEEKLY
This will be replaced with an ENUM in ILIAS 9
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Refinery Factory $refinery
static http()
Fetches the global http state from ILIAS.
const DEFAULT_REMINDER_PERIOD
const SCHEDULE_TYPE_IN_DAYS
This will be replaced with an ENUM in ILIAS 9
static sendReminderMailIfNeeded(ilObjUser $user, int $reminderTime, int $time_frame_for_deletion)
getDefaultScheduleValue()
saveCustomSettings(ilPropertyFormGUI $a_form)
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
const SCHEDULE_TYPE_YEARLY
This will be replaced with an ENUM in ILIAS 9
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
const SCHEDULE_TYPE_DAILY
This will be replaced with an ENUM in ILIAS 9
const SCHEDULE_TYPE_QUARTERLY
This will be replaced with an ENUM in ILIAS 9
calculateDeletionData(int $date_for_deletion)
ILIAS HTTP GlobalHttpState $http
const DEFAULT_INACTIVITY_PERIOD
const SCHEDULE_TYPE_IN_HOURS
This will be replaced with an ENUM in ILIAS 9