You are here

class BatchWorker 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
  2. 8.2 src/Plugin/BatchWorker/BatchWorker.php \Drupal\purge_users\Plugin\BatchWorker\BatchWorker

Class BatchWorker.

@package Drupal\purge_users\Plugin\BatchWorker

Hierarchy

  • class \Drupal\purge_users\Plugin\BatchWorker\BatchWorker

Expanded class hierarchy of BatchWorker

File

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

Namespace

Drupal\purge_users\Plugin\BatchWorker
View source
class BatchWorker {

  /**
   * Process items in a batch.
   */
  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']++;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatchWorker::batchworkerpurgeusers public static function Process items in a batch.