4 include_once
"Services/Cron/classes/class.ilCronJob.php";
5 include_once
'Services/Mail/classes/class.ilMimeMail.php';
6 include_once
'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
34 'cron_inactive_user_delete_include_roles',
37 if ($this->include_roles === null) {
38 $this->include_roles = array();
40 $this->include_roles = explode(
',', $this->include_roles);
44 'cron_inactive_user_delete_period',
45 self::DEFAULT_INACTIVITY_PERIOD
48 'cron_inactive_user_reminder_period',
49 self::DEFAULT_REMINDER_PERIOD
62 switch ($schedule_time) {
64 $time_difference = 86400;
67 $time_difference = 60 * $multiplier;
70 $time_difference = 3600 * $multiplier;
73 $time_difference = 86400 * $multiplier;
76 $time_difference = 604800;
79 $time_difference = 2629743;
82 $time_difference = 7889229;
85 $time_difference = 31556926;
88 return $time_difference;
93 return "user_inactive";
102 return $lng->txt(
"delete_inactive_user_accounts");
111 return $lng->txt(
"delete_inactive_user_accounts_desc");
116 return self::SCHEDULE_TYPE_DAILY;
139 public function run()
143 $rbacreview = $DIC[
'rbacreview'];
147 $reminder_time = (int) $this->reminderTimer;
148 $checkMail = (int) $this->period - $reminder_time;
152 $userMailsDelivered = 0;
153 foreach ($usr_ids as $usr_id) {
154 if ($usr_id == ANONYMOUS_USER_ID || $usr_id == SYSTEM_USER_ID) {
159 foreach ($this->include_roles as $role_id) {
160 if ($rbacreview->isAssigned($usr_id, $role_id)) {
174 $timestamp_last_login = strtotime(
$user->getLastLogin());
175 $grace_period_over = time() - ((int) $this->period * 24 * 60 * 60);
176 if ($timestamp_last_login < $grace_period_over) {
179 } elseif ($reminder_time > 0) {
180 $timestamp_for_deletion = $timestamp_last_login - $grace_period_over;
184 $userMailsDelivered++;
194 $ilLog->write(
"CRON - ilCronDeleteInactiveUserAccounts::run(), deleted => $userDeleted User(s), sent reminder mail to $userMailsDelivered User(s)");
203 $time_difference = 0;
206 if (!is_array($cron_timing) || !is_array($cron_timing[0])) {
207 return time() + $date_for_deletion + $time_difference;
210 if (array_key_exists(
'schedule_type', $cron_timing[0])) {
211 if ((array_key_exists(
'schedule_type', $cron_timing[0]) && $cron_timing[0][
'schedule_value'] != null)) {
212 $multiplier = $cron_timing[0][
'schedule_value'];
216 return time() + $date_for_deletion + $time_difference;
224 $rbacreview = $DIC[
'rbacreview'];
225 $ilObjDataCache = $DIC[
'ilObjDataCache'];
227 $lng->loadLanguageModule(
"user");
231 $lng->txt(
'delete_inactive_user_accounts_frequency'),
232 'delete_inactive_user_accounts_frequency' 235 $lng->txt(
'delete_inactive_user_accounts_frequency_desc'),
236 'delete_inactive_user_accounts_frequency_desc' 239 include_once(
'Services/Form/classes/class.ilMultiSelectInputGUI.php');
241 $lng->txt(
'delete_inactive_user_accounts_include_roles'),
242 'cron_inactive_user_delete_include_roles' 244 $sub_mlist->
setInfo(
$lng->txt(
'delete_inactive_user_accounts_include_roles_desc'));
246 foreach ($rbacreview->getGlobalRoles() as $role_id) {
247 if ($role_id != ANONYMOUS_ROLE_ID) {
248 $roles[$role_id] = $ilObjDataCache->lookupTitle($role_id);
251 $sub_mlist->setOptions($roles);
252 $setting =
$ilSetting->get(
'cron_inactive_user_delete_include_roles', null);
253 if ($setting === null) {
256 $setting = explode(
',', $setting);
258 $sub_mlist->setValue($setting);
259 $sub_mlist->setWidth(300);
260 #$sub_mlist->setHeight(100); 263 $default_setting = self::DEFAULT_INACTIVITY_PERIOD;
265 $lng->txt(
'delete_inactive_user_accounts_period'),
266 'cron_inactive_user_delete_period' 268 $sub_text->
setInfo(
$lng->txt(
'delete_inactive_user_accounts_period_desc'));
269 $sub_text->setValue(
$ilSetting->get(
"cron_inactive_user_delete_period", $default_setting));
270 $sub_text->setSize(4);
271 $sub_text->setMaxLength(4);
272 $sub_text->setRequired(
true);
276 $lng->txt(
'send_mail_to_inactive_users'),
277 'cron_inactive_user_reminder_period' 279 $sub_period->
setInfo(
$lng->txt(
"send_mail_to_inactive_users_desc"));
280 $sub_period->setValue(
$ilSetting->get(
"cron_inactive_user_reminder_period", $default_setting));
281 $sub_period->setSuffix(
$lng->txt(
"send_mail_to_inactive_users_suffix"));
282 $sub_period->setSize(4);
283 $sub_period->setMaxLength(4);
284 $sub_period->setRequired(
false);
285 $sub_period->setMinValue(0);
303 $lng->loadLanguageModule(
"user");
304 $setting = implode(
',',
$_POST[
'cron_inactive_user_delete_include_roles']);
305 if (!strlen($setting)) {
317 $a_form->
getItemByPostVar(
'cron_inactive_user_delete_period')->setAlert(
$lng->txt(
'send_mail_to_inactive_users_numbers_only'),
'send_mail_to_inactive_users_numbers_only');
319 if ($this->
isDecimal($reminder_period)) {
321 $a_form->
getItemByPostVar(
'cron_inactive_user_reminder_period')->setAlert(
$lng->txt(
'send_mail_to_inactive_users_numbers_only'),
'send_mail_to_inactive_users_numbers_only');
323 if ($reminder_period >= $delete_period) {
325 $a_form->
getItemByPostVar(
'cron_inactive_user_reminder_period')->setAlert(
$lng->txt(
'send_mail_to_inactive_users_must_be_smaller_than'),
'send_mail_to_inactive_users_must_be_smaller_than');
329 $check_window_logic = $delete_period - $reminder_period;
331 if ($check_window_logic < $cron_period_custom) {
335 if ($check_window_logic <= 7) {
339 if ($check_window_logic <= 31) {
343 if ($check_window_logic <= 92) {
347 if ($check_window_logic <= 366) {
353 $a_form->
getItemByPostVar(
'cron_inactive_user_reminder_period')->setAlert(
$lng->txt(
'send_mail_reminder_window_too_small'),
'send_mail_reminder_window_too_small');
356 if (
$_POST[
'cron_inactive_user_delete_period']) {
357 $ilSetting->set(
'cron_inactive_user_delete_include_roles', $setting);
358 $ilSetting->set(
'cron_inactive_user_delete_period',
$_POST[
'cron_inactive_user_delete_period']);
360 if ($this->reminderTimer > $reminder_period) {
363 $ilSetting->set(
'cron_inactive_user_reminder_period', $reminder_period);
375 if (strpos($number,
',') || strpos($number,
'.')) {
static removeEntriesFromTableIfLastLoginIsNewer()
Cron job application base class.
getTimeDifferenceBySchedule($schedule_time, $multiplier)
const SCHEDULE_TYPE_IN_MINUTES
static _getUserIdsByInactivityPeriod($period)
get ids of all users that have been inactive for at least the given period
const SCHEDULE_TYPE_MONTHLY
const SCHEDULE_TYPE_WEEKLY
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
static checkIfReminderMailShouldBeSend(ilObjUser $user, $reminderTime, $time_frame_for_deletion)
const DEFAULT_REMINDER_PERIOD
const SCHEDULE_TYPE_IN_DAYS
getDefaultScheduleValue()
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
saveCustomSettings(ilPropertyFormGUI $a_form)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
const SCHEDULE_TYPE_YEARLY
calculateDeletionData($date_for_deletion)
const SCHEDULE_TYPE_DAILY
const SCHEDULE_TYPE_QUARTERLY
Cron job result data container.
const DEFAULT_INACTIVITY_PERIOD
const SCHEDULE_TYPE_IN_HOURS