You are here

function purge_users_cron in Auto Purge Users 7

Same name and namespace in other branches
  1. 8.3 purge_users.module \purge_users_cron()
  2. 8 purge_users.module \purge_users_cron()
  3. 8.2 purge_users.module \purge_users_cron()
  4. 7.2 purge_users.module \purge_users_cron()

Implements hook_cron().

File

./purge_users.module, line 29
Purge users module file.

Code

function purge_users_cron() {
  if (variable_get('purge_users_purge_on_cron', '') == 1) {

    // Get form submissions.
    $user_roles = array_filter(variable_get('purge_users_roles', array()));
    $status = variable_get('user_status', '');
    $never_enable_loggedin = variable_get('purge_users_enabled_never_loggedin_users', '');
    $enable_loggedin = variable_get('purge_users_enabled_loggedin_users', '');
    $enable_inactive = variable_get('purge_users_enabled_inactive_users', '');
    $enable_blocked = variable_get('purge_users_enabled_blocked_users', '');
    $param = array(
      'never_login_value' => variable_get('purge_users_user_never_lastlogin_value', ''),
      'never_login_period' => variable_get('purge_users_user_never_lastlogin_period', ''),
      'login_value' => variable_get('purge_users_user_lastlogin_value', ''),
      'login_period' => variable_get('purge_users_user_lastlogin_period', ''),
      'inactive_value' => variable_get('purge_users_user_inactive_value', ''),
      'inactive_period' => variable_get('purge_users_user_inactive_period', ''),
      'blocked_value' => variable_get('purge_users_user_blocked_value', ''),
      'blocked_period' => variable_get('purge_users_user_blocked_period', ''),
    );

    // Get user ids to purge.
    $never_loggedin_users = array();
    $not_loggedin_users = array();
    $inactive_users = array();
    $blocked_users = array();

    // Get users who have never logged in at all.
    if ($never_enable_loggedin == 1) {
      $never_loggedin_users = purge_users_never_loggedin_user_ids($param, $user_roles, $status, $never_enable_loggedin);
    }

    // Get users who have not logged in at all.
    if ($enable_loggedin == 1) {
      $not_loggedin_users = purge_users_not_loggedin_user_ids($param, $user_roles, $status, $enable_loggedin);
    }

    // Get users who didn't activate their account.
    if ($enable_inactive == 1) {
      $inactive_users = purge_users_inactive_user_ids($param, $user_roles, $status, $enable_inactive);
    }

    // Get the users who are blocked.
    if ($enable_blocked == 1) {
      $blocked_users = purge_users_blocked_user_ids($param, $user_roles, $status, $enable_blocked);
    }

    // Merge results to create an array of user ids to purge.
    $result = array_merge($never_loggedin_users, $not_loggedin_users, $inactive_users, $blocked_users);
    $result = array_unique($result);

    // Add items to queue.
    $queue = DrupalQueue::get('purge_users');

    // Process the queue till it is empty.
    if ($queue
      ->numberOfItems() == 0) {
      foreach ($result as $user_id) {
        $queue
          ->createItem($user_id);
      }
    }
  }
}