You are here

public static function BatchWorker::batchworkerpurgeusers in Auto Purge Users 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/BatchWorker/BatchWorker.php \Drupal\purge_users\Plugin\BatchWorker\BatchWorker::batchWorkerPurgeUsers()
  2. 8.2 src/Plugin/BatchWorker/BatchWorker.php \Drupal\purge_users\Plugin\BatchWorker\BatchWorker::batchWorkerPurgeUsers()

Process items in a batch.

File

src/Plugin/BatchWorker/BatchWorker.php, line 15

Class

BatchWorker
Class BatchWorker.

Namespace

Drupal\purge_users\Plugin\BatchWorker

Code

public static function batchworkerpurgeusers($account, &$context) {
  if (!isset($context['results']['purged'])) {
    $context['results']['purged'] = 0;
  }

  // Perform user deletion operation.
  $name = $account
    ->get('name')->value;
  $mail = $account
    ->get('mail')->value;
  $uid = $account
    ->get('uid')->value;
  $config = \Drupal::config('purge_users.settings');
  $send_notification = $config
    ->get('send_email_notification');
  $method = $config
    ->get('purge_user_cancel_method');
  if ($method != 'user_cancel_delete') {

    // Allow modules to add further sets to this batch.
    $handler = \Drupal::moduleHandler();
    $handler
      ->invokeAll('user_cancel', array(
      array(),
      $account,
      $method,
    ));
  }
  if ($send_notification == 1) {
    purge_users_send_notification_email($account);
  }
  user_delete($uid);

  // Log purged user.
  $message = t('Purged user: %name < %mail >', array(
    '%name' => $name,
    '%mail' => $mail,
  ));
  \Drupal::logger('purge_users')
    ->notice($message);

  // Display a progress message...
  $context['message'] = "Now processing {$name} ...";

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