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

Issue #2998414 by Sam152, amateescu: Workspaces fails to deploy content in...

Issue #2998414 by Sam152, amateescu: Workspaces fails to deploy content in fields that required dedicated table storage
parent 31f251b4
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -29,6 +29,13 @@ class WorkspaceOperationFactory {
*/
protected $database;
/**
* The workspace manager.
*
* @var \Drupal\workspaces\WorkspaceManagerInterface
*/
protected $workspaceManager;
/**
* Constructs a new WorkspacePublisher.
*
......@@ -37,9 +44,10 @@ class WorkspaceOperationFactory {
* @param \Drupal\Core\Database\Connection $database
* Database connection.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceManagerInterface $workspace_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->database = $database;
$this->workspaceManager = $workspace_manager;
}
/**
......@@ -52,7 +60,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Con
* A workspace publisher object.
*/
public function getPublisher(WorkspaceInterface $source) {
return new WorkspacePublisher($this->entityTypeManager, $this->database, $source);
return new WorkspacePublisher($this->entityTypeManager, $this->database, $this->workspaceManager, $source);
}
}
......@@ -47,6 +47,13 @@ class WorkspacePublisher implements WorkspacePublisherInterface {
*/
protected $workspaceAssociationStorage;
/**
* The workspace manager.
*
* @var \Drupal\workspaces\WorkspaceManagerInterface
*/
protected $workspaceManager;
/**
* Constructs a new WorkspacePublisher.
*
......@@ -54,11 +61,14 @@ class WorkspacePublisher implements WorkspacePublisherInterface {
* The entity type manager.
* @param \Drupal\Core\Database\Connection $database
* Database connection.
* @param \Drupal\workspaces\WorkspaceManagerInterface $workspace_manager
* The workspace manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceInterface $source) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, Connection $database, WorkspaceManagerInterface $workspace_manager, WorkspaceInterface $source) {
$this->entityTypeManager = $entity_type_manager;
$this->database = $database;
$this->workspaceAssociationStorage = $entity_type_manager->getStorage('workspace_association');
$this->workspaceManager = $workspace_manager;
$this->sourceWorkspace = $source;
$this->targetWorkspace = $this->entityTypeManager->getStorage('workspace')->load(WorkspaceInterface::DEFAULT_WORKSPACE);
}
......@@ -75,18 +85,26 @@ public function publish() {
try {
// @todo Handle the publishing of a workspace with a batch operation in
// https://www.drupal.org/node/2958752.
foreach ($this->getDifferringRevisionIdsOnSource() as $entity_type_id => $revision_difference) {
$entity_revisions = $this->entityTypeManager->getStorage($entity_type_id)
->loadMultipleRevisions(array_keys($revision_difference));
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
foreach ($entity_revisions as $entity) {
// When pushing workspace-specific revisions to the default workspace
// (Live), we simply need to mark them as default revisions.
$entity->setSyncing(TRUE);
$entity->isDefaultRevision(TRUE);
$entity->save();
$this->workspaceManager->executeInWorkspace($this->targetWorkspace->id(), function () {
foreach ($this->getDifferringRevisionIdsOnSource() as $entity_type_id => $revision_difference) {
$entity_revisions = $this->entityTypeManager->getStorage($entity_type_id)
->loadMultipleRevisions(array_keys($revision_difference));
$default_revisions = $this->entityTypeManager->getStorage($entity_type_id)
->loadMultiple(array_values($revision_difference));
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
foreach ($entity_revisions as $entity) {
// When pushing workspace-specific revisions to the default
// workspace (Live), we simply need to mark them as default
// revisions.
$entity->setSyncing(TRUE);
$entity->isDefaultRevision(TRUE);
$entity->original = $default_revisions[$entity->id()];
$entity->save();
}
}
}
});
}
catch (\Exception $e) {
$transaction->rollBack();
......
......@@ -755,4 +755,34 @@ public function testFormCacheForRegularForms() {
$form_builder->setCache($built_form['#build_id'], $built_form, $form_state);
}
/**
* Test a deployment with fields in dedicated table storage.
*/
public function testPublishWorkspaceDedicatedTableStorage() {
$this->initializeWorkspacesModule();
$node_storage = $this->entityTypeManager->getStorage('node');
$this->switchToWorkspace('live');
$node = $node_storage->create([
'title' => 'Foo title',
// Use the body field on node as a test case because it requires dedicated
// table storage.
'body' => 'Foo body',
'type' => 'page',
]);
$node->save();
$this->switchToWorkspace('stage');
$node->title = 'Bar title';
$node->body = 'Bar body';
$node->save();
$this->workspaces['stage']->publish();
$this->switchToWorkspace('live');
$reloaded = $node_storage->load($node->id());
$this->assertEquals('Bar title', $reloaded->title->value);
$this->assertEquals('Bar body', $reloaded->body->value);
}
}
......@@ -6,7 +6,7 @@ services:
- { name: service_id_collector, tag: workspace_negotiator }
workspaces.operation_factory:
class: Drupal\workspaces\WorkspaceOperationFactory
arguments: ['@entity_type.manager', '@database']
arguments: ['@entity_type.manager', '@database', '@workspaces.manager']
workspaces.negotiator.default:
class: Drupal\workspaces\Negotiator\DefaultWorkspaceNegotiator
......
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