You are here

function purge_users_get_user_ids in Auto Purge Users 8

Same name and namespace in other branches
  1. 8.3 purge_users.module \purge_users_get_user_ids()
  2. 8.2 purge_users.module \purge_users_get_user_ids()

Get user ids to purge.

4 calls to purge_users_get_user_ids()
ConfirmationForm::buildForm in src/Form/ConfirmationForm.php
Form constructor.
ConfirmationForm::submitForm in src/Form/ConfirmationForm.php
Form submission handler.
purge_users_cron in ./purge_users.module
Implements hook_cron().
SettingsForm::purgeUsersNowSubmit in src/Form/SettingsForm.php
Submit handler for mass-account cancellation form.

File

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

Code

function purge_users_get_user_ids() {

  // Get form submissions.
  $result = array();
  $config = \Drupal::config('purge_users.settings');
  $user_roles = array_filter($config
    ->get('purge_users_roles'));
  $enable_never_loggedin = $config
    ->get('enabled_never_loggedin_users');
  $enable_loggedin = $config
    ->get('enabled_loggedin_users');
  $enable_inactive = $config
    ->get('enabled_inactive_users');
  $enable_blocked = $config
    ->get('enabled_blocked_users');
  $param = array(
    'never_login_value' => $config
      ->get('user_never_lastlogin_value'),
    'never_login_period' => $config
      ->get('user_never_lastlogin_period'),
    'login_value' => $config
      ->get('user_lastlogin_value'),
    'login_period' => $config
      ->get('user_lastlogin_period'),
    'inactive_value' => $config
      ->get('user_inactive_value'),
    'inactive_period' => $config
      ->get('user_inactive_period'),
    'blocked_value' => $config
      ->get('user_blocked_value'),
    'blocked_period' => $config
      ->get('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 ($enable_never_loggedin == 1) {
    $never_loggedin_users = purge_users_never_loggedin_user_ids($param, $user_roles);
  }

  // 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);
  }

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

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

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