You are here

function role_expire_cron in Role Expire 6

Same name and namespace in other branches
  1. 8 role_expire.module \role_expire_cron()
  2. 7 role_expire.module \role_expire_cron()
  3. 2.x role_expire.module \role_expire_cron()

Implementation of hook_cron().

File

./role_expire.module, line 361
Role Expire module

Code

function role_expire_cron() {
  if ($expires = role_expire_get_expired()) {
    $roles = _role_expire_get_role();
    foreach ($expires as $expire) {

      // Remove the role from the user.
      $account = user_load($expire['uid']);
      $edit = $account->roles;
      unset($edit[$expire['rid']]);

      // In the documentation for the role_expire implementation of hook_user we
      // state to use $category = 'account'.  We don't do that here because
      // that would cause the delete to occur twice.
      user_save($account, array(
        'roles' => $edit,
      ), NULL);

      // Remove the role expiration record.
      role_expire_delete_record($expire['uid'], $expire['rid']);
      watchdog('role expire', 'Remove role @role from user @account.', array(
        '@role' => $roles[$expire['rid']],
        '@account' => $account->name,
      ));
    }
  }
}