You are here

function purge_users_cron in Auto Purge Users 8

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

Implements hook_cron().

File

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

Code

function purge_users_cron() {
  $config = \Drupal::config('purge_users.settings');
  if ($config
    ->get('purge_on_cron') == 1) {
    $result = purge_users_get_user_ids();

    // Add items to queue.
    $queue_factory = \Drupal::service('queue');
    $queue = $queue_factory
      ->get('purge_users');
    $users = User::loadMultiple($result);

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