You are here

public function DeletedWorkspaceQueue::processItem in Multiversion 8

Parameters

mixed $data:

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Exception

Overrides QueueWorkerInterface::processItem

File

src/Plugin/QueueWorker/DeletedWorkspaceQueue.php, line 65

Class

DeletedWorkspaceQueue
Class DeletedWorkspaceQueue

Namespace

Drupal\multiversion\Plugin\QueueWorker

Code

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();
    }
  }
}