46 private \ILIAS\HTTP\GlobalHttpState
$http;
56 if (isset($DIC[
'ilDB'])) {
60 if (isset($DIC[
'tpl'])) {
61 $this->main_tpl = $DIC[
'tpl'];
63 if (isset($DIC[
'http'])) {
64 $this->
http = $DIC[
'http'];
67 if (isset($DIC[
'lng'])) {
68 $this->
lng = $DIC[
'lng'];
71 if (isset($DIC[
'ilLog'])) {
72 $this->log = $DIC[
'ilLog'];
75 if (isset($DIC[
'refinery'])) {
79 if (isset($DIC[
'ilObjDataCache'])) {
83 if (isset($DIC[
'rbacreview'])) {
84 $this->rbac_review = $DIC[
'rbacreview'];
87 if (isset($DIC[
'cron.repository'])) {
88 $this->cronRepository = $DIC[
'cron.repository'];
91 if (isset($DIC[
'ilSetting'])) {
99 $include_roles = $this->
settings->get(
100 'cron_inactive_user_delete_include_roles',
103 if ($include_roles === null) {
104 $this->include_roles = [];
106 $this->include_roles = array_filter(array_map(
'intval', explode(
',', $include_roles)));
110 'cron_inactive_user_delete_period',
111 (
string) self::DEFAULT_INACTIVITY_PERIOD
113 $this->reminder_period = (
int) $this->
settings->get(
114 'cron_inactive_user_reminder_period',
115 (
string) self::DEFAULT_REMINDER_PERIOD
124 $number_as_string = (string) $number;
126 return strpos($number_as_string,
',') || strpos($number_as_string,
'.');
131 $time_difference = 0;
133 switch ($schedule_time) {
134 case CronJobScheduleType::SCHEDULE_TYPE_DAILY:
135 $time_difference = 86400;
137 case CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES:
138 $time_difference = 60 * $multiplier;
140 case CronJobScheduleType::SCHEDULE_TYPE_IN_HOURS:
141 $time_difference = 3600 * $multiplier;
143 case CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS:
144 $time_difference = 86400 * $multiplier;
146 case CronJobScheduleType::SCHEDULE_TYPE_WEEKLY:
147 $time_difference = 604800;
149 case CronJobScheduleType::SCHEDULE_TYPE_MONTHLY:
150 $time_difference = 2629743;
152 case CronJobScheduleType::SCHEDULE_TYPE_QUARTERLY:
153 $time_difference = 7889229;
156 $time_difference = 31556926;
160 return $time_difference;
165 return "user_inactive";
170 return $this->
lng->txt(
"delete_inactive_user_accounts");
175 return $this->
lng->txt(
"delete_inactive_user_accounts_desc");
180 return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
209 self::ACTION_USER_NONE => 0,
210 self::ACTION_USER_REMINDER_MAIL_SENT => 0,
211 self::ACTION_USER_DELETED => 0
213 foreach ($usr_ids as $usr_id) {
218 foreach ($this->include_roles as $role_id) {
219 if ($this->rbac_review->isAssigned($usr_id, $role_id)) {
221 $counters[$action_taken]++;
227 if ($counters[self::ACTION_USER_REMINDER_MAIL_SENT] > 0
228 || $counters[self::ACTION_USER_DELETED] > 0) {
232 $this->cron_delete_reminder_mail->removeEntriesFromTableIfLastLoginIsNewer();
234 'CRON - ilCronDeleteInactiveUserAccounts::run(), deleted ' 235 .
"=> {$counters[self::ACTION_USER_DELETED]} User(s), sent reminder " 236 .
"mail to {$counters[self::ACTION_USER_REMINDER_MAIL_SENT]} User(s)" 240 $result->setStatus($status);
248 $timestamp_last_login = strtotime($user->getLastLogin());
249 $grace_period_over = time() - ($this->delete_period * 24 * 60 * 60);
251 if ($timestamp_last_login < $grace_period_over) {
253 return self::ACTION_USER_DELETED;
256 if ($this->reminder_period > 0) {
257 $timestamp_for_deletion = $timestamp_last_login - $grace_period_over;
260 $this->cron_delete_reminder_mail->sendReminderMailIfNeeded(
262 $this->reminder_period,
263 $account_will_be_deleted_on
266 return self::ACTION_USER_REMINDER_MAIL_SENT;
270 return self::ACTION_USER_NONE;
275 $cron_timing = $this->cronRepository->getCronJobData($this->
getId());
276 $time_difference = 0;
279 if (!is_array($cron_timing) || !isset($cron_timing[0]) || !is_array($cron_timing[0])) {
280 return time() + $date_for_deletion + $time_difference;
283 if (array_key_exists(
'schedule_type', $cron_timing[0])) {
284 if ($cron_timing[0][
'schedule_value'] !== null) {
285 $multiplier = (
int) $cron_timing[0][
'schedule_value'];
292 return time() + $date_for_deletion + $time_difference;
297 $this->
lng->loadLanguageModule(
"user");
300 $schedule->setTitle($this->
lng->txt(
'delete_inactive_user_accounts_frequency'));
301 $schedule->setInfo($this->
lng->txt(
'delete_inactive_user_accounts_frequency_desc'));
304 $this->
lng->txt(
'delete_inactive_user_accounts_include_roles'),
305 'cron_inactive_user_delete_include_roles' 307 $sub_mlist->
setInfo($this->
lng->txt(
'delete_inactive_user_accounts_include_roles_desc'));
309 foreach ($this->rbac_review->getGlobalRoles() as $role_id) {
314 $sub_mlist->setOptions($roles);
315 $setting = $this->
settings->get(
'cron_inactive_user_delete_include_roles', null);
316 if ($setting === null) {
319 $setting = explode(
',', $setting);
321 $sub_mlist->setValue($setting);
322 $sub_mlist->setWidth(300);
325 $default_setting = (string) self::DEFAULT_INACTIVITY_PERIOD;
328 $this->
lng->txt(
'delete_inactive_user_accounts_period'),
329 'cron_inactive_user_delete_period' 331 $sub_text->allowDecimals(
false);
332 $sub_text->setInfo($this->
lng->txt(
'delete_inactive_user_accounts_period_desc'));
333 $sub_text->setValue($this->
settings->get(
"cron_inactive_user_delete_period", $default_setting));
334 $sub_text->setSize(4);
335 $sub_text->setMaxLength(4);
336 $sub_text->setRequired(
true);
340 $this->
lng->txt(
'send_mail_to_inactive_users'),
341 'cron_inactive_user_reminder_period' 343 $sub_period->allowDecimals(
false);
344 $sub_period->setInfo($this->
lng->txt(
"send_mail_to_inactive_users_desc"));
345 $sub_period->setValue($this->
settings->get(
"cron_inactive_user_reminder_period", $default_setting));
346 $sub_period->setSuffix($this->
lng->txt(
"send_mail_to_inactive_users_suffix"));
347 $sub_period->setSize(4);
348 $sub_period->setMaxLength(4);
349 $sub_period->setRequired(
false);
350 $sub_period->setMinValue(0);
356 $this->
lng->loadLanguageModule(
"user");
365 $cron_period_custom = 0;
367 $reminder_period =
'';
369 $empty_string_trafo = $this->
refinery->custom()->transformation(
static function ($value):
string {
374 throw new Exception(
'The value to be transformed is not an empty string');
377 if ($this->
http->wrapper()->post()->has(
'sdyi')) {
378 $cron_period_custom = $this->
http->wrapper()->post()->retrieve(
381 $this->refinery->kindlyTo()->int(),
387 if ($this->
http->wrapper()->post()->has(
'cron_inactive_user_delete_period')) {
388 $delete_period = $this->
http->wrapper()->post()->retrieve(
389 'cron_inactive_user_delete_period',
391 $this->refinery->kindlyTo()->int(),
393 $this->
refinery->kindlyTo()->float(),
400 if ($this->
http->wrapper()->post()->has(
'cron_inactive_user_reminder_period')) {
401 $reminder_period = $this->
http->wrapper()->post()->retrieve(
402 'cron_inactive_user_reminder_period',
405 $this->refinery->byTrying([
406 $this->refinery->kindlyTo()->int(),
408 $this->
refinery->kindlyTo()->float(),
419 $this->
lng->txt(
'send_mail_to_inactive_users_numbers_only')
423 if ($this->
isDecimal($reminder_period)) {
426 $this->
lng->txt(
'send_mail_to_inactive_users_numbers_only')
430 if ($reminder_period >= $delete_period) {
433 $this->
lng->txt(
'send_mail_to_inactive_users_must_be_smaller_than')
437 if ($cron_period->value >= CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS->value &&
441 if ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS) {
442 if ($check_window_logic < $cron_period_custom) {
445 } elseif ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_WEEKLY) {
446 if ($check_window_logic <= 7) {
449 } elseif ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_MONTHLY) {
450 if ($check_window_logic <= 31) {
453 } elseif ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_QUARTERLY) {
454 if ($check_window_logic <= 92) {
458 if ($check_window_logic <= 366) {
466 $this->
lng->txt(
'send_mail_reminder_window_too_small')
471 if ($delete_period > 0) {
472 $roles = implode(
',', $this->
http->wrapper()->post()->retrieve(
473 'cron_inactive_user_delete_include_roles',
475 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->int()),
480 $this->
settings->set(
'cron_inactive_user_delete_include_roles', $roles);
481 $this->
settings->set(
'cron_inactive_user_delete_period', (
string) $delete_period);
484 if ($this->reminder_period > $reminder_period) {
485 $this->cron_delete_reminder_mail->flushDataTable();
488 $this->
settings->set(
'cron_inactive_user_reminder_period', (
string) $reminder_period);
491 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"form_input_not_valid"));
const ACTION_USER_REMINDER_MAIL_SENT
ilGlobalTemplateInterface $main_tpl
ilCronJobRepository $cronRepository
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getUserIdsByInactivityPeriod(int $periodInDays)
Get ids of all users that have been inactive for at least the given period.
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
deleteUserOrSendReminderMail($usr_id)
Component logger with individual log levels by component id.
ilObjectDataCache $objectDataCache
ilCronDeleteInactiveUserReminderMail $cron_delete_reminder_mail
ILIAS Refinery Factory $refinery
static http()
Fetches the global http state from ILIAS.
final const STATUS_NO_ACTION
getTimeDifferenceBySchedule(CronJobScheduleType $schedule_time, int $multiplier)
const DEFAULT_REMINDER_PERIOD
getDefaultScheduleValue()
ilRbacReview $rbac_review
saveCustomSettings(ilPropertyFormGUI $a_form)
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
const ACTION_USER_DELETED
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
calculateDeletionData(int $date_for_deletion)
ILIAS HTTP GlobalHttpState $http
const DEFAULT_INACTIVITY_PERIOD