You are here

protected function Workspace::deleteWorkspaceActiveSessions in Multiversion 8

Deletes from users private store entries where the workspace is active.

This will lead to using the default active workspace as the active workspace for users that had as active the deleted workspace.

Parameters

$workspace_id:

1 call to Workspace::deleteWorkspaceActiveSessions()
Workspace::delete in src/Entity/Workspace.php
Deletes an entity permanently.

File

src/Entity/Workspace.php, line 274

Class

Workspace
The workspace entity class.

Namespace

Drupal\multiversion\Entity

Code

protected function deleteWorkspaceActiveSessions($workspace_id) {

  // Get all collections for the workspace session negotiator and delete those
  // that have as active workspace the currently deleted workspace.
  // Manipulate directly with the database here becase for private tempstore
  // the access is restricted per current user.
  $session_negociator_collection = 'user.private_tempstore.workspace.negotiator.session';
  $values = \Drupal::database()
    ->select('key_value_expire', 'kve')
    ->fields('kve', [
    'name',
    'value',
  ])
    ->condition('collection', $session_negociator_collection)
    ->execute()
    ->fetchAll();
  foreach ($values as $value) {
    if (!empty($value->value) && !empty($value->name)) {
      $data = PhpSerialize::decode($value->value);
      if (!empty($data->data) && $data->data == $workspace_id) {
        \Drupal::database()
          ->delete('key_value_expire')
          ->condition('name', $value->name)
          ->execute();
      }
    }
  }
}