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 {
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} ...";
$context['results']['purged']++;
}
}