Skip to content

Commit

Permalink
TASK: Make workspace role and metadata creation atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Dec 12, 2024
1 parent ddccba1 commit 08d01e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,13 @@ public function findWorkspaceNameByUser(ContentRepositoryId $contentRepositoryId
]);
return $workspaceName === false ? null : WorkspaceName::fromString($workspaceName);
}

/**
* @param \Closure(): void $fn
* @return void
*/
public function transactional(\Closure $fn): void
{
$this->dbal->transactional($fn);
}
}
22 changes: 14 additions & 8 deletions Neos.Neos/Classes/Domain/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ public function createRootWorkspace(ContentRepositoryId $contentRepositoryId, Wo
ContentStreamId::create()
)
);
$this->metadataAndRoleRepository->addWorkspaceMetadata($contentRepositoryId, $workspaceName, $title, $description, WorkspaceClassification::ROOT, ownerUserId: null);
foreach ($assignments as $assignment) {
$this->metadataAndRoleRepository->assignWorkspaceRole($contentRepositoryId, $workspaceName, $assignment);
}

$this->metadataAndRoleRepository->transactional(function () use ($contentRepositoryId, $workspaceName, $title, $description, $assignments) {
$this->metadataAndRoleRepository->addWorkspaceMetadata($contentRepositoryId, $workspaceName, $title, $description, WorkspaceClassification::ROOT, ownerUserId: null);
foreach ($assignments as $assignment) {
$this->metadataAndRoleRepository->assignWorkspaceRole($contentRepositoryId, $workspaceName, $assignment);
}
});
}

/**
Expand Down Expand Up @@ -182,10 +185,13 @@ public function createSharedWorkspace(ContentRepositoryId $contentRepositoryId,
ContentStreamId::create()
)
);
$this->metadataAndRoleRepository->addWorkspaceMetadata($contentRepositoryId, $workspaceName, $title, $description, WorkspaceClassification::SHARED, ownerUserId: null);
foreach ($assignments as $assignment) {
$this->metadataAndRoleRepository->assignWorkspaceRole($contentRepositoryId, $workspaceName, $assignment);
}

$this->metadataAndRoleRepository->transactional(function () use ($contentRepositoryId, $workspaceName, $title, $description, $assignments) {
$this->metadataAndRoleRepository->addWorkspaceMetadata($contentRepositoryId, $workspaceName, $title, $description, WorkspaceClassification::SHARED, ownerUserId: null);
foreach ($assignments as $assignment) {
$this->metadataAndRoleRepository->assignWorkspaceRole($contentRepositoryId, $workspaceName, $assignment);
}
});
}

/**
Expand Down

0 comments on commit 08d01e1

Please sign in to comment.