You are here

class PurgeUsersQueueWorker in Auto Purge Users 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/QueueWorker/PurgeUsersQueueWorker.php \Drupal\purge_users\Plugin\QueueWorker\PurgeUsersQueueWorker
  2. 8.2 src/Plugin/QueueWorker/PurgeUsersQueueWorker.php \Drupal\purge_users\Plugin\QueueWorker\PurgeUsersQueueWorker

Processes cron queue.

Plugin annotation


@QueueWorker(
  id = "purge_users",
  title = @Translation("Purge Users Tasks Worker: Purge Users"),
  cron = {"time" = 15}
)

Hierarchy

Expanded class hierarchy of PurgeUsersQueueWorker

File

src/Plugin/QueueWorker/PurgeUsersQueueWorker.php, line 23

Namespace

Drupal\purge_users\Plugin\QueueWorker
View source
class PurgeUsersQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The purge user manager.
   *
   * @var \Drupal\purge_users\Services\UserManagementServiceInterface
   */
  protected $purgeUserManager;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a new PurgeUsersQueueWorker instance.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\purge_users\Services\UserManagementServiceInterface $purge_user
   *   The purge user manager service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, UserManagementServiceInterface $purge_user, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->purgeUserManager = $purge_user;
    $this->entityTypeManager = $entity_type_manager;
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : self {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('purge_users.user_management'), $container
      ->get('entity_type.manager'), $container
      ->get('config.factory'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($user_id) {
    $account = $this->entityTypeManager
      ->getStorage('user')
      ->load($user_id);
    if (!$account) {
      return;
    }
    $config = $this->configFactory
      ->get('purge_users.settings');
    $method = $config
      ->get('purge_user_cancel_method') !== 'user_cancel_site_policy' ? $config
      ->get('purge_user_cancel_method') : $this->configFactory
      ->get('user.settings')
      ->get('cancel_method');
    $this->purgeUserManager
      ->purgeUser($account, $method);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
PurgeUsersQueueWorker::$configFactory protected property The configuration factory.
PurgeUsersQueueWorker::$entityTypeManager protected property The entity type manager.
PurgeUsersQueueWorker::$purgeUserManager protected property The purge user manager.
PurgeUsersQueueWorker::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
PurgeUsersQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
PurgeUsersQueueWorker::__construct public function Constructs a new PurgeUsersQueueWorker instance. Overrides PluginBase::__construct