You are here

function user_expire_expire_users in User Expire 7

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

Expire a group of users.

Parameters

array $accounts: A set of user objects to expire.

3 calls to user_expire_expire_users()
UserExpireTestCase::testUserExpire in ./user_expire.test
user_expire_expire_user in ./user_expire.module
Expire a single user.
user_expire_process_per_user_expiration in ./user_expire.module
Expires users who have an expiration that has passed.

File

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

Code

function user_expire_expire_users(array $accounts) {
  foreach ($accounts as $account) {
    if ($account) {

      // Block user's account.
      if (user_save($account, array(
        'status' => 0,
      )) !== FALSE) {

        // User account has expired, status set to '0'.
        // Send email to notify user about it.
        drupal_mail('user_expire', 'account_expired', $account->mail, $account->language, array(
          'account' => $account,
        ));

        // Remove current expiration time.
        user_expire_set_expiration($account);

        // Log notification to watchdog.
        watchdog('user_expire', 'User %name has expired.', array(
          '%name' => $account->name,
        ));
      }
      else {

        // User account has not been updated.
        watchdog('user_expire', 'Cannot update status for user %name.', array(
          '%name' => $account->name,
        ), WATCHDOG_ERROR);
        drupal_set_message(t('Cannot update status for user %name.', array(
          '%name' => $account->name,
        )), 'error');
      }
    }
  }
}