You are here

function user_expire_expire_by_role in User Expire 7

Same name and namespace in other branches
  1. 8 user_expire.module \user_expire_expire_by_role()

Expires user by roles according to rules in the database.

2 calls to user_expire_expire_by_role()
UserExpireTestCase::testUserExpire in ./user_expire.test
user_expire_cron in ./user_expire.module
Implements hook_cron().

File

./user_expire.module, line 381
Main module file for User expire module.

Code

function user_expire_expire_by_role() {
  $rules = user_expire_get_role_rules();
  foreach ($rules as $rid => $rule) {
    $uids_to_expire = user_expire_find_users_to_expire_by_role($rule->rid, $rule->inactivity_period);
    if ($uids_to_expire) {
      foreach ($uids_to_expire as $uid) {
        $account = user_load($uid->uid);
        if (empty($account->uid)) {
          watchdog('user_expire', 'Skipping @uid as it failed to load a valid user', array(
            '@uid' => $uid,
          ), WATCHDOG_WARNING);
        }
        else {
          watchdog('user_expire', 'Expiring account @name by role', array(
            '@name' => $account->name,
          ));
          user_expire_expire_user($account);
        }
      }
    }
  }
}