Issue #3366257 by amateescu: The active workspace is not deactivated when it's deleted

merge-requests/4505/head
Lauri Eskola 2023-07-29 11:11:33 +03:00
parent 917678cf43
commit 96939a6ba0
No known key found for this signature in database
GPG Key ID: 382FC0F5B0DF53F8
2 changed files with 23 additions and 9 deletions

View File

@ -174,6 +174,16 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface {
public static function postDelete(EntityStorageInterface $storage, array $entities) { public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities); parent::postDelete($storage, $entities);
/** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
$workspace_manager = \Drupal::service('workspaces.manager');
// Disable the currently active workspace if it has been deleted.
if ($workspace_manager->hasActiveWorkspace()
&& in_array($workspace_manager->getActiveWorkspace()->id(), array_keys($entities), TRUE)) {
$workspace_manager->switchToLive();
}
// Ensure that workspace batch purging does not happen inside a workspace.
$workspace_manager->executeOutsideWorkspace(function () use ($workspace_manager, $entities) {
// Add the IDs of the deleted workspaces to the list of workspaces that will // Add the IDs of the deleted workspaces to the list of workspaces that will
// be purged on cron. // be purged on cron.
$state = \Drupal::state(); $state = \Drupal::state();
@ -183,7 +193,8 @@ class Workspace extends ContentEntityBase implements WorkspaceInterface {
// Trigger a batch purge to allow empty workspaces to be deleted // Trigger a batch purge to allow empty workspaces to be deleted
// immediately. // immediately.
\Drupal::service('workspaces.manager')->purgeDeletedWorkspacesBatch(); $workspace_manager->purgeDeletedWorkspacesBatch();
});
} }
} }

View File

@ -201,6 +201,9 @@ class WorkspaceCRUDTest extends KernelTestBase {
$workspace_deleted = \Drupal::state()->get('workspace.deleted'); $workspace_deleted = \Drupal::state()->get('workspace.deleted');
$this->assertCount(0, $workspace_deleted); $this->assertCount(0, $workspace_deleted);
// Check that the deleted workspace is no longer active.
$this->assertFalse($this->workspaceManager->hasActiveWorkspace());
} }
/** /**