Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Fix Workspace Metadata upsert #5397

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,30 @@ public function updateWorkspaceMetadata(ContentRepositoryId $contentRepositoryId
$data = array_filter([
'title' => $title,
'description' => $description,
], fn ($value) => $value !== null);
], static fn ($value) => $value !== null);

$table = self::TABLE_NAME_WORKSPACE_METADATA;
$query = <<<SQL
SELECT
content_repository_id
FROM
{$table}
WHERE
content_repository_id = :contentRepositoryId
AND workspace_name = :workspaceName
SQL;
try {
$affectedRows = $this->dbal->update(self::TABLE_NAME_WORKSPACE_METADATA, $data, [
'content_repository_id' => $contentRepositoryId->value,
'workspace_name' => $workspace->workspaceName->value,
]);
if ($affectedRows === 0) {
$this->dbal->insert(self::TABLE_NAME_WORKSPACE_METADATA, [
$rowExists = $this->dbal->fetchOne($query, [
'contentRepositoryId' => $contentRepositoryId->value,
'workspaceName' => $workspace->workspaceName->value,
]) !== false;
if ($rowExists) {
$this->dbal->update($table, $data, [
'content_repository_id' => $contentRepositoryId->value,
'workspace_name' => $workspace->workspaceName->value,
]);
} else {
$this->dbal->insert($table, [
'content_repository_id' => $contentRepositoryId->value,
'workspace_name' => $workspace->workspaceName->value,
'description' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ Feature: Neos WorkspaceService related features
| Title | Description | Classification | Owner user id |
| Some new workspace title | | ROOT | |

Scenario: Change title of root workspace to the same value
When the root workspace "some-root-workspace" with title "some title" and description "some description" is created
And the title of workspace "some-root-workspace" is set to "some title"
Then the workspace "some-root-workspace" should have the following metadata:
| Title | Description | Classification | Owner user id |
| some title | some description | ROOT | |

Scenario: Set title of root workspace without metadata
When a root workspace "some-root-workspace" exists without metadata
And the title of workspace "some-root-workspace" is set to "Some new workspace title"
Expand All @@ -66,6 +73,13 @@ Feature: Neos WorkspaceService related features
| Title | Description | Classification | Owner user id |
| some-root-workspace | Some new workspace description | ROOT | |

Scenario: Change description of root workspace to the same value
When the root workspace "some-root-workspace" with title "some title" and description "some description" is created
And the description of workspace "some-root-workspace" is set to "some description"
Then the workspace "some-root-workspace" should have the following metadata:
| Title | Description | Classification | Owner user id |
| some title | some description | ROOT | |

Scenario: Change description of root workspace without metadata
When a root workspace "some-root-workspace" exists without metadata
And the description of workspace "some-root-workspace" is set to "Some new workspace description"
Expand Down
Loading