You are here

class MessageDeletionWorker in Message 8

Deletes a set of messages.

No more than MessagePurgeInterface::MESSAGE_DELETE_SIZE messages should be given to a single queue item to ensure that the worker can complete the task within PHP operating constraints.

Plugin annotation


@QueueWorker(
  id = "message_delete",
  title = @Translation("Delete messages"),
  cron = {"time" = 10}
)

Hierarchy

Expanded class hierarchy of MessageDeletionWorker

File

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

Namespace

Drupal\message\Plugin\QueueWorker
View source
class MessageDeletionWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The message storage handler.
   *
   * @var \Drupal\Core\Entity\ContentEntityStorageInterface
   */
  protected $messageStorage;

  /**
   * Constructs a new MessageDeletionWorker object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->messageStorage = $entity_type_manager
      ->getStorage('message');
  }

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

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    if (!empty($data)) {
      $messages = $this->messageStorage
        ->loadMultiple($data);
      $this->messageStorage
        ->delete($messages);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessageDeletionWorker::$messageStorage protected property The message storage handler.
MessageDeletionWorker::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
MessageDeletionWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
MessageDeletionWorker::__construct public function Constructs a new MessageDeletionWorker object. Overrides PluginBase::__construct
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.