Skip to content
Snippets Groups Projects
Commit b71ccf50 authored by catch's avatar catch
Browse files

Issue #3093879 by amateescu, catch: Ensure that there's no active workspace...

Issue #3093879 by amateescu, catch: Ensure that there's no active workspace while running database updates

(cherry picked from commit 528ab050)
parent e7e8017a
No related branches found
No related tags found
9 merge requests!1445Issue #2920039: Views' User Name exposed group filter validation,!1298Issue #3240993: Let layout builder render inline block translations,!774Issue #3174569: Example node template file name is incorrect,!497Issue #2463967: Use .user.ini file for PHP settings,!433Resolve #3163663 "Too many open files",!233Resolve #2693787 "Taxonomy term name",!133Resolve #2666286 "Clean up menuui",!112Resolve #3187004 "Drupaldatetime serialization issue",!53Resolve #3181870: Correct typo "the the" in "core/classList" deprecation message.
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase; use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\Core\Update\UpdateKernel;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
/** /**
...@@ -24,6 +25,16 @@ public function alter(ContainerBuilder $container) { ...@@ -24,6 +25,16 @@ public function alter(ContainerBuilder $container) {
$container->getDefinition('path_alias.repository') $container->getDefinition('path_alias.repository')
->setClass(WorkspacesAliasRepository::class) ->setClass(WorkspacesAliasRepository::class)
->addMethodCall('setWorkspacesManager', [new Reference('workspaces.manager')]); ->addMethodCall('setWorkspacesManager', [new Reference('workspaces.manager')]);
// Ensure that there's no active workspace while running database updates by
// removing the relevant tag from all workspace negotiator services.
if ($container->get('kernel') instanceof UpdateKernel) {
foreach ($container->getDefinitions() as $id => $definition) {
if ($definition->hasTag('workspace_negotiator')) {
$definition->clearTag('workspace_negotiator');
}
}
}
} }
} }
No preview for this file type
<?php
namespace Drupal\workspace_update_test\Negotiator;
use Drupal\workspaces\Entity\Workspace;
use Drupal\workspaces\Negotiator\WorkspaceNegotiatorInterface;
use Drupal\workspaces\WorkspaceInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines a workspace negotiator used for testing.
*/
class TestWorkspaceNegotiator implements WorkspaceNegotiatorInterface {
/**
* {@inheritdoc}
*/
public function applies(Request $request) {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getActiveWorkspace(Request $request) {
return Workspace::create(['id' => 'test', 'label' => 'Test']);
}
/**
* {@inheritdoc}
*/
public function setActiveWorkspace(WorkspaceInterface $workspace) {
// Nothing to do here.
}
/**
* {@inheritdoc}
*/
public function unsetActiveWorkspace() {
// Nothing to do here.
}
}
name: 'Workspace Update Test'
type: module
description: 'Provides supporting code for testing workspaces during database updates.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:workspaces
<?php
/**
* @file
* Post update functions for the Workspace Update Test module.
*/
/**
* Checks the active workspace during database updates.
*/
function workspace_update_test_post_update_check_active_workspace() {
\Drupal::state()->set('workspace_update_test.has_active_workspace', \Drupal::service('workspaces.manager')->hasActiveWorkspace());
}
services:
workspace_update_test.negotiator.test:
class: Drupal\workspace_update_test\Negotiator\TestWorkspaceNegotiator
tags:
- { name: workspace_negotiator, priority: 0 }
...@@ -18,7 +18,7 @@ class WorkspacesUpdateTest extends UpdatePathTestBase { ...@@ -18,7 +18,7 @@ class WorkspacesUpdateTest extends UpdatePathTestBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected static $modules = ['workspaces']; protected static $modules = ['workspaces', 'workspace_update_test'];
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -127,4 +127,33 @@ public function testWorkspaceParentField() { ...@@ -127,4 +127,33 @@ public function testWorkspaceParentField() {
$this->assertNull($form_display->getComponent('parent')); $this->assertNull($form_display->getComponent('parent'));
} }
/**
* Tests that there is no active workspace during database updates.
*/
public function testActiveWorkspaceDuringUpdate() {
/** @var \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager */
$workspace_manager = \Drupal::service('workspaces.manager');
// Check that we have an active workspace before running the updates.
$this->assertTrue($workspace_manager->hasActiveWorkspace());
$this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
$this->runUpdates();
// Check that we didn't have an active workspace while running the updates.
// @see workspace_update_test_post_update_check_active_workspace()
$this->assertFalse(\Drupal::state()->get('workspace_update_test.has_active_workspace'));
// Check that we have an active workspace after running the updates.
$this->assertTrue($workspace_manager->hasActiveWorkspace());
$this->assertEquals('test', $workspace_manager->getActiveWorkspace()->id());
}
/**
* {@inheritdoc}
*/
protected function replaceUser1() {
// Do not replace the user from our dump.
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment