You are here

class CleanupRevisionsQueueWorker in Node Revisions Autoclean 8

Class NotifyQueueWorker.

Plugin annotation


@QueueWorker(
 id = "cleanup_revisions_worker",
 title = @Translation("Cleanup revisions"),
 cron = {"time" = 120}
)

Hierarchy

Expanded class hierarchy of CleanupRevisionsQueueWorker

File

src/Plugin/QueueWorker/CleanupRevisionsQueueWorker.php, line 20

Namespace

Drupal\node_revisions_autoclean\Plugin\QueueWorker
View source
class CleanupRevisionsQueueWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
  use StringTranslationTrait;

  /**
   * Drupal\node_revisions_autoclean\Services\RevisionsManager.
   *
   * @var Drupal\node_revisions_autoclean\Services\RevisionsManager
   */
  protected $revisionsManager;

  /**
   * CleanupRevisionsQueueWorker constructor.
   *
   * @param array $configuration
   *   Configuration.
   * @param string $plugin_id
   *   Pugin id.
   * @param mixed $plugin_definition
   *   Plugin definition.
   * @param Drupal\node_revisions_autoclean\Services\RevisionsManager $revisionsManager
   *   RevisionsManager.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RevisionsManager $revisionsManager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->revisionsManager = $revisionsManager;
  }

  /**
   * Creates an instance of the plugin.
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The container to pull out services used in the plugin.
   * @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.
   *
   * @return static
   *   Returns an instance of this plugin.
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('node_revisions_autoclean.revisions_manager'));
  }

  /**
   * Works on a single queue item.
   *
   * @param mixed $data
   *   The data that was passed to
   *   \Drupal\Core\Queue\QueueInterface::createItem() when the item was queued.
   *
   * @throws \Drupal\Core\Queue\RequeueException
   *   Processing is not yet finished. This will allow another process to claim
   *   the item immediately.
   * @throws \Exception
   *   A QueueWorker plugin may throw an exception to indicate there was a
   *   problem. The cron process will log the exception, and leave the item in
   *   the queue to be processed again later.
   * @throws \Drupal\Core\Queue\SuspendQueueException
   *   More specifically, a SuspendQueueException should be thrown when a
   *   QueueWorker plugin is aware that the problem will affect all subsequent
   *   workers of its queue. For example, a callback that makes HTTP requests
   *   may find that the remote server is not responding. The cron process will
   *   behave as with a normal Exception, and in addition will not attempt to
   *   process further items from the current item's queue during the current
   *   cron run.
   *
   * @see \Drupal\Core\Cron::processQueues()
   */
  public function processItem($data) {
    $revisions = $this->revisionsManager
      ->revisionsToDelete($data->node);
    \Drupal::logger('node_revisions_autoclean')
      ->info($this
      ->t("Deleting @count old(s) revision(s) for node @nid : @label", [
      '@count' => count($revisions),
      '@nid' => $data->node
        ->id(),
      '@label' => $data->node
        ->label(),
    ]));
    $this->revisionsManager
      ->deleteRevisions($revisions);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CleanupRevisionsQueueWorker::$revisionsManager protected property Drupal\node_revisions_autoclean\Services\RevisionsManager.
CleanupRevisionsQueueWorker::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
CleanupRevisionsQueueWorker::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
CleanupRevisionsQueueWorker::__construct public function CleanupRevisionsQueueWorker constructor. 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.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.