19 declare(strict_types=1);
49 private \ILIAS\HTTP\GlobalHttpState
$http;
59 if (isset($DIC[
'ilDB'])) {
63 if (isset($DIC[
'tpl'])) {
64 $this->main_tpl = $DIC[
'tpl'];
66 if (isset($DIC[
'http'])) {
67 $this->
http = $DIC[
'http'];
70 if (isset($DIC[
'lng'])) {
71 $this->
lng = $DIC[
'lng'];
74 if (isset($DIC[
'ilLog'])) {
75 $this->log = $DIC[
'ilLog'];
78 if (isset($DIC[
'refinery'])) {
82 if (isset($DIC[
'ilObjDataCache'])) {
86 if (isset($DIC[
'rbacreview'])) {
87 $this->rbac_review = $DIC[
'rbacreview'];
90 if (isset($DIC[
'cron.repository'])) {
91 $this->cronRepository = $DIC[
'cron.repository'];
94 if (isset($DIC[
'ilSetting'])) {
102 $include_roles = $this->
settings->get(
103 'cron_inactive_user_delete_include_roles',
106 if ($include_roles === null) {
107 $this->include_roles = [];
109 $this->include_roles = array_filter(
array_map(
'intval', explode(
',', $include_roles)));
113 'cron_inactive_user_delete_period',
114 (
string) self::DEFAULT_INACTIVITY_PERIOD
116 $this->reminder_period = (
int) $this->
settings->get(
117 'cron_inactive_user_reminder_period',
118 (
string) self::DEFAULT_REMINDER_PERIOD
127 $number_as_string = (string) $number;
129 return strpos($number_as_string,
',') || strpos($number_as_string,
'.');
134 $time_difference = 0;
136 switch ($schedule_time) {
137 case CronJobScheduleType::SCHEDULE_TYPE_DAILY:
138 $time_difference = 86400;
140 case CronJobScheduleType::SCHEDULE_TYPE_IN_MINUTES:
141 $time_difference = 60 * $multiplier;
143 case CronJobScheduleType::SCHEDULE_TYPE_IN_HOURS:
144 $time_difference = 3600 * $multiplier;
146 case CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS:
147 $time_difference = 86400 * $multiplier;
149 case CronJobScheduleType::SCHEDULE_TYPE_WEEKLY:
150 $time_difference = 604800;
152 case CronJobScheduleType::SCHEDULE_TYPE_MONTHLY:
153 $time_difference = 2629743;
155 case CronJobScheduleType::SCHEDULE_TYPE_QUARTERLY:
156 $time_difference = 7889229;
159 $time_difference = 31556926;
163 return $time_difference;
168 return "user_inactive";
173 return $this->
lng->txt(
"delete_inactive_user_accounts");
178 return $this->
lng->txt(
"delete_inactive_user_accounts_desc");
183 return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
212 self::ACTION_USER_NONE => 0,
213 self::ACTION_USER_REMINDER_MAIL_SENT => 0,
214 self::ACTION_USER_DELETED => 0
216 foreach ($usr_ids as $usr_id) {
221 foreach ($this->include_roles as $role_id) {
222 if ($this->rbac_review->isAssigned($usr_id, $role_id)) {
224 $counters[$action_taken]++;
230 if ($counters[self::ACTION_USER_REMINDER_MAIL_SENT] > 0
231 || $counters[self::ACTION_USER_DELETED] > 0) {
235 $this->cron_delete_reminder_mail->removeEntriesFromTableIfLastLoginIsNewer();
237 'CRON - ilCronDeleteInactiveUserAccounts::run(), deleted ' 238 .
"=> {$counters[self::ACTION_USER_DELETED]} User(s), sent reminder " 239 .
"mail to {$counters[self::ACTION_USER_REMINDER_MAIL_SENT]} User(s)" 243 $result->setStatus($status);
251 $timestamp_last_login = strtotime($user->getLastLogin());
252 $grace_period_over = time() - ($this->delete_period * 24 * 60 * 60);
254 if ($timestamp_last_login < $grace_period_over) {
256 return self::ACTION_USER_DELETED;
259 if ($this->reminder_period > 0) {
260 $timestamp_for_deletion = $timestamp_last_login - $grace_period_over;
263 $this->cron_delete_reminder_mail->sendReminderMailIfNeeded(
265 $this->reminder_period,
266 $account_will_be_deleted_on
269 return self::ACTION_USER_REMINDER_MAIL_SENT;
273 return self::ACTION_USER_NONE;
278 $cron_timing = $this->cronRepository->getCronJobData($this->
getId());
279 $time_difference = 0;
282 if (!is_array($cron_timing) || !isset($cron_timing[0]) || !is_array($cron_timing[0])) {
283 return time() + $date_for_deletion + $time_difference;
286 if (array_key_exists(
'schedule_type', $cron_timing[0])) {
287 if ($cron_timing[0][
'schedule_value'] !== null) {
288 $multiplier = (
int) $cron_timing[0][
'schedule_value'];
295 return time() + $date_for_deletion + $time_difference;
300 $this->
lng->loadLanguageModule(
"user");
303 $schedule->setTitle($this->
lng->txt(
'delete_inactive_user_accounts_frequency'));
304 $schedule->setInfo($this->
lng->txt(
'delete_inactive_user_accounts_frequency_desc'));
307 $this->
lng->txt(
'delete_inactive_user_accounts_include_roles'),
308 'cron_inactive_user_delete_include_roles' 310 $sub_mlist->
setInfo($this->
lng->txt(
'delete_inactive_user_accounts_include_roles_desc'));
312 foreach ($this->rbac_review->getGlobalRoles() as $role_id) {
317 $sub_mlist->setOptions($roles);
318 $setting = $this->
settings->get(
'cron_inactive_user_delete_include_roles', null);
319 if ($setting === null) {
322 $setting = explode(
',', $setting);
324 $sub_mlist->setValue($setting);
325 $sub_mlist->setWidth(300);
328 $default_setting = (string) self::DEFAULT_INACTIVITY_PERIOD;
331 $this->
lng->txt(
'delete_inactive_user_accounts_period'),
332 'cron_inactive_user_delete_period' 334 $sub_text->allowDecimals(
false);
335 $sub_text->setInfo($this->
lng->txt(
'delete_inactive_user_accounts_period_desc'));
336 $sub_text->setValue($this->
settings->get(
"cron_inactive_user_delete_period", $default_setting));
337 $sub_text->setSize(4);
338 $sub_text->setMaxLength(4);
339 $sub_text->setRequired(
true);
343 $this->
lng->txt(
'send_mail_to_inactive_users'),
344 'cron_inactive_user_reminder_period' 346 $sub_period->allowDecimals(
false);
347 $sub_period->setInfo($this->
lng->txt(
"send_mail_to_inactive_users_desc"));
348 $sub_period->setValue($this->
settings->get(
"cron_inactive_user_reminder_period", $default_setting));
349 $sub_period->setSuffix($this->
lng->txt(
"send_mail_to_inactive_users_suffix"));
350 $sub_period->setSize(4);
351 $sub_period->setMaxLength(4);
352 $sub_period->setRequired(
false);
353 $sub_period->setMinValue(0);
359 $this->
lng->loadLanguageModule(
"user");
368 $cron_period_custom = 0;
370 $reminder_period =
'';
372 $empty_string_trafo = $this->
refinery->custom()->transformation(
static function ($value):
string {
377 throw new Exception(
'The value to be transformed is not an empty string');
380 if ($this->
http->wrapper()->post()->has(
'sdyi')) {
381 $cron_period_custom = $this->
http->wrapper()->post()->retrieve(
384 $this->refinery->kindlyTo()->int(),
390 if ($this->
http->wrapper()->post()->has(
'cron_inactive_user_delete_period')) {
391 $delete_period = $this->
http->wrapper()->post()->retrieve(
392 'cron_inactive_user_delete_period',
394 $this->refinery->kindlyTo()->int(),
396 $this->
refinery->kindlyTo()->float(),
403 if ($this->
http->wrapper()->post()->has(
'cron_inactive_user_reminder_period')) {
404 $reminder_period = $this->
http->wrapper()->post()->retrieve(
405 'cron_inactive_user_reminder_period',
408 $this->refinery->byTrying([
409 $this->refinery->kindlyTo()->int(),
411 $this->
refinery->kindlyTo()->float(),
422 $this->
lng->txt(
'send_mail_to_inactive_users_numbers_only')
426 if ($this->
isDecimal($reminder_period)) {
429 $this->
lng->txt(
'send_mail_to_inactive_users_numbers_only')
433 if ($reminder_period >= $delete_period) {
436 $this->
lng->txt(
'send_mail_to_inactive_users_must_be_smaller_than')
440 if ($cron_period->value >= CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS->value &&
444 if ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_IN_DAYS) {
445 if ($check_window_logic < $cron_period_custom) {
448 } elseif ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_WEEKLY) {
449 if ($check_window_logic <= 7) {
452 } elseif ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_MONTHLY) {
453 if ($check_window_logic <= 31) {
456 } elseif ($cron_period === CronJobScheduleType::SCHEDULE_TYPE_QUARTERLY) {
457 if ($check_window_logic <= 92) {
461 if ($check_window_logic <= 366) {
469 $this->
lng->txt(
'send_mail_reminder_window_too_small')
474 if ($delete_period > 0) {
475 $roles = implode(
',', $this->
http->wrapper()->post()->retrieve(
476 'cron_inactive_user_delete_include_roles',
478 $this->refinery->kindlyTo()->listOf($this->
refinery->kindlyTo()->int()),
483 $this->
settings->set(
'cron_inactive_user_delete_include_roles', $roles);
484 $this->
settings->set(
'cron_inactive_user_delete_period', (
string) $delete_period);
487 if ($this->reminder_period > $reminder_period) {
488 $this->cron_delete_reminder_mail->flushDataTable();
491 $this->
settings->set(
'cron_inactive_user_reminder_period', (
string) $reminder_period);
494 $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
__construct(Container $dic, ilPlugin $plugin)
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