function user_expire_expire_by_role_warning in User Expire 7
Same name and namespace in other branches
- 8 user_expire.module \user_expire_expire_by_role_warning()
Warns users with an upcoming expiration by roles.
1 call to user_expire_expire_by_role_warning()
- user_expire_cron in ./
user_expire.module - Implements hook_cron().
File
- ./
user_expire.module, line 341 - Main module file for User expire module.
Code
function user_expire_expire_by_role_warning() {
$last_run = variable_get('user_expire_warning_last_run', 0);
$warning_frequency = variable_get('user_expire_warning_frequency', 60 * 60 * 24 * 2);
// Warn people every 2 days.
if ($last_run && $last_run > REQUEST_TIME - $warning_frequency) {
watchdog('user_expire', 'Skipping warning as it was run within the last @hours hours', array(
'@hours' => $warning_frequency / (60 * 60),
), WATCHDOG_DEBUG);
return;
}
// Find people to warn.
$rules = user_expire_get_role_rules();
$warning_offset = variable_get('user_expire_warning_offset', 60 * 60 * 24 * 7);
foreach ($rules as $rid => $rule) {
$uids_to_warn = user_expire_find_users_to_expire_by_role($rule->rid, $rule->inactivity_period - $warning_offset);
if ($uids_to_warn) {
foreach ($uids_to_warn as $uid) {
$account = user_load($uid->uid);
if (empty($account->uid)) {
watchdog('user_expire', 'Skipping warning @uid as it failed to load a valid user', array(
'@uid' => $uid->uid,
), WATCHDOG_WARNING);
}
else {
watchdog('user_expire', 'Warning about expiring account @name by role', array(
'@name' => $account->name,
), WATCHDOG_INFO);
drupal_mail('user_expire', 'expiration_warning', $account->mail, $account->language, array(
'account' => $account,
));
}
}
}
}
variable_set('user_expire_warning_last_run', REQUEST_TIME);
}