Skip to content

Commit

Permalink
Merge pull request #5397 from neos/bugfix/fix-workspace-metadata-upsert
Browse files Browse the repository at this point in the history
BUGFIX: Fix Workspace Metadata upsert
  • Loading branch information
bwaidelich authored Dec 5, 2024
2 parents 2d735b2 + 72cefb1 commit 30867ac
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
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

0 comments on commit 30867ac

Please sign in to comment.