You are here

BatchWorker.php in Auto Purge Users 8.2

File

src/Plugin/BatchWorker/BatchWorker.php
View source
<?php

namespace Drupal\purge_users\Plugin\BatchWorker;

use Drupal\user\Entity\User;

/**
 * Class BatchWorker.
 *
 * @package Drupal\purge_users\Plugin\BatchWorker
 */
class BatchWorker {

  /**
   * Process items in a batch.
   */
  public static function batchWorkerPurgeUsers($id, &$context) {
    $account = User::load($id);
    if (!isset($context['results']['purged'])) {
      $context['results']['purged'] = 0;
    }
    $config = \Drupal::config('purge_users.settings');
    $method = $config
      ->get('purge_user_cancel_method') != 'user_cancel_site_policy' ? $config
      ->get('purge_user_cancel_method') : \Drupal::config('user.settings')
      ->get('cancel_method');
    $name = $account
      ->get('name')->value;
    $userManagement = \Drupal::service('purge_users.user_management');
    $userManagement
      ->purgeUser($account, $method);
    $context['message'] = "Now processing {$name} ...";

    // Update our progress information.
    $context['results']['purged']++;
  }

}

Classes

Namesort descending Description
BatchWorker Class BatchWorker.