class DeletedWorkspaceQueue in Multiversion 8
Class DeletedWorkspaceQueue
Plugin annotation
@QueueWorker(
id = "deleted_workspace_queue",
title = @Translation("Queue of deleted workspaces"),
cron = {"time" = 60}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\multiversion\Plugin\QueueWorker\DeletedWorkspaceQueue implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of DeletedWorkspaceQueue
File
- src/
Plugin/ QueueWorker/ DeletedWorkspaceQueue.php, line 24
Namespace
Drupal\multiversion\Plugin\QueueWorkerView source
class DeletedWorkspaceQueue extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\multiversion\Workspace\WorkspaceManagerInterface
*/
private $workspaceManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, WorkspaceManagerInterface $workspace_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->workspaceManager = $workspace_manager;
}
/**
* {@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'), $container
->get('workspace.manager'));
}
/**
* @param mixed $data
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Exception
*/
public function processItem($data) {
$storage = $this->entityTypeManager
->getStorage($data['entity_type_id']);
if ($storage instanceof ContentEntityStorageInterface && !empty($data['workspace_id'])) {
$workspace = Workspace::load($data['workspace_id']);
if ($workspace) {
$this->workspaceManager
->setActiveWorkspace($workspace);
}
$original_storage = $storage
->getOriginalStorage();
$entity = $original_storage
->load($data['entity_id']);
if ($entity) {
$this
->deleteEntity($original_storage, $entity);
}
$default_workspace = Workspace::load(\Drupal::getContainer()
->getParameter('workspace.default'));
if ($default_workspace) {
$this->workspaceManager
->setActiveWorkspace($default_workspace);
}
}
elseif ($data['entity_type_id'] == 'workspace') {
$entity = $storage
->load($data['entity_id']);
if ($entity) {
$this
->deleteEntity($storage, $entity);
// Cleanup indexes.
$database = \Drupal::database();
$collections = [
'multiversion.entity_index.id.' . $data['entity_id'],
'multiversion.entity_index.uuid.' . $data['entity_id'],
'multiversion.entity_index.rev.' . $data['entity_id'],
];
$database
->delete('key_value')
->condition('collection', $collections, 'IN')
->execute();
// Delete sequence indexes.
$database
->delete('key_value_sorted')
->condition('collection', 'multiversion.entity_index.sequence.' . $data['entity_id'])
->execute();
// Delete revision tree indexes.
$database
->delete('key_value')
->condition('collection', 'multiversion.entity_index.rev.tree.' . $data['entity_id'] . '.%', 'LIKE')
->execute();
}
}
}
/**
* @param \Drupal\Core\Entity\ContentEntityStorageInterface $storage
* @param \Drupal\Core\Entity\ContentEntityStorageInterface $entity
*/
protected function deleteEntity($storage, $entity) {
try {
$storage
->delete([
$entity,
]);
} catch (Exception $e) {
$arguments = Error::decodeException($e) + [
'%uuid' => $entity
->uuid(),
];
$message = t('%type: @message in %function (line %line of %file). The error occurred while deleting the entity with the UUID: %uuid.', $arguments);
watchdog_exception('Multiversion', $e, $message);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeletedWorkspaceQueue:: |
protected | property | ||
DeletedWorkspaceQueue:: |
private | property | ||
DeletedWorkspaceQueue:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
DeletedWorkspaceQueue:: |
protected | function | ||
DeletedWorkspaceQueue:: |
public | function |
Overrides QueueWorkerInterface:: |
|
DeletedWorkspaceQueue:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. 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. |