class GarbageCollector in Simple XML sitemap (Views integration) 8
Executes garbage collection in the simple_sitemap_views table.
Plugin annotation
@QueueWorker(
id = "simple_sitemap_views_garbage_collector",
title = @Translation("Garbage collection in the simple_sitemap_views table"),
cron = {"time" = 30}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\simple_sitemap_views\Plugin\QueueWorker\GarbageCollector implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of GarbageCollector
File
- src/
Plugin/ QueueWorker/ GarbageCollector.php, line 26 - Contains queue worker for garbage collection.
Namespace
Drupal\simple_sitemap_views\Plugin\QueueWorkerView source
class GarbageCollector extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* Views sitemap data.
*
* @var \Drupal\simple_sitemap_views\SimpleSitemapViews
*/
protected $simpleSitemapViews;
/**
* View entities storage.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $viewStorage;
/**
* GarbageCollector constructor.
*
* @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\simple_sitemap_views\SimpleSitemapViews $simple_sitemap_views
* Views sitemap data.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, SimpleSitemapViews $simple_sitemap_views, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->viewStorage = $entity_type_manager
->getStorage('view');
$this->simpleSitemapViews = $simple_sitemap_views;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('simple_sitemap_views'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
$view_id = $data['view_id'];
/** @var \Drupal\views\ViewEntityInterface $view_entity */
$view_entity = $this->viewStorage
->load($view_id);
$display_ids = [];
// Check that the view exists and it is enabled.
if ($view_entity && $view_entity
->status()) {
$view = $view_entity
->getExecutable();
$displays = array_filter($view_entity
->get('display'), [
$this->simpleSitemapViews,
'isValidDisplay',
]);
foreach ($displays as $display_id => $display) {
// Ensure the display was correctly set.
if (!$view
->setDisplay($display_id)) {
$view
->destroy();
continue;
}
// Check that the display is enabled and has indexable arguments.
if ($view->display_handler
->isEnabled() && ($args_ids = $this->simpleSitemapViews
->getIndexableArguments($view))) {
$display_ids[] = $display_id;
// Delete records about sets of arguments that are no longer indexed.
$args_ids = $this->simpleSitemapViews
->getArgumentsStringVariations($args_ids);
$condition = new Condition('AND');
$condition
->condition('view_id', $view_id);
$condition
->condition('display_id', $display_id);
$condition
->condition('arguments_ids', $args_ids, 'NOT IN');
$this->simpleSitemapViews
->removeArgumentsFromIndex($condition);
// Check if the records limit for display is exceeded.
$settings = $this->simpleSitemapViews
->getSitemapSettings($view);
$max_links = is_numeric($settings['max_links']) ? $settings['max_links'] : 0;
if ($max_links > 0) {
$condition = new Condition('AND');
$condition
->condition('view_id', $view_id);
$condition
->condition('display_id', $display_id);
// Delete records that exceed the limit.
if ($index_id = $this->simpleSitemapViews
->getIndexIdByPosition($max_links, $condition)) {
$condition
->condition('id', $index_id, '>');
$this->simpleSitemapViews
->removeArgumentsFromIndex($condition);
}
}
}
}
// Delete records about view displays that do not exist or are disabled.
if (!empty($display_ids)) {
$condition = new Condition('AND');
$condition
->condition('view_id', $view_id);
$condition
->condition('display_id', $display_ids, 'NOT IN');
$this->simpleSitemapViews
->removeArgumentsFromIndex($condition);
}
// Destroy a view instance.
$view
->destroy();
}
// Delete records about the view, if it does not exist, is disabled or it
// does not have a display whose arguments are indexed.
if (empty($display_ids)) {
$condition = new Condition('AND');
$condition
->condition('view_id', $view_id);
$this->simpleSitemapViews
->removeArgumentsFromIndex($condition);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GarbageCollector:: |
protected | property | Views sitemap data. | |
GarbageCollector:: |
protected | property | View entities storage. | |
GarbageCollector:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
GarbageCollector:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
GarbageCollector:: |
public | function |
GarbageCollector constructor. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |