Skip to content

Commit

Permalink
TASK: Further phpstan adjustments
Browse files Browse the repository at this point in the history
(and use hash to index dimensions)
  • Loading branch information
mhsdesign committed Dec 12, 2024
1 parent 116de2a commit 64119e2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
46 changes: 30 additions & 16 deletions Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public function indexAction(): void
$workspaceListItems = $this->getWorkspaceListItems($contentRepository, $currentUser);

$this->view->assignMultiple([
'userWorkspaceName' => $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId())->workspaceName,
// todo remove userWorkspaceName field and add distinction to $workspaceListItems as $workspaceListItems->userWorkspace and $workspaceListItems->otherWorkspaces or something.
'userWorkspaceName' => $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId())->workspaceName->value,
'workspaceListItems' => $workspaceListItems,
'flashMessages' => $this->controllerContext->getFlashMessageContainer()->getMessagesAndFlush(),
]);
Expand Down Expand Up @@ -300,6 +301,10 @@ public function editAction(WorkspaceName $workspaceName): void
$this->throwStatus(404, 'Workspace does not exist');
}

if ($workspace->isRootWorkspace()) {
throw new \RuntimeException(sprintf('Workspace %s does not have a base-workspace.', $workspace->workspaceName->value), 1734019485);
}

$workspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $workspace->workspaceName);

$editWorkspaceDto = new EditWorkspaceFormData(
Expand Down Expand Up @@ -386,7 +391,7 @@ public function updateAction(
$workspaceListItems = $this->getWorkspaceListItems($contentRepository, $currentUser);

$this->view->assignMultiple([
'userWorkspaceName' => $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId())->workspaceName,
'userWorkspaceName' => $this->workspaceService->getPersonalWorkspaceForUser($contentRepositoryId, $currentUser->getId())->workspaceName->value,
'workspaceListItems' => $workspaceListItems,
]);
}
Expand Down Expand Up @@ -463,7 +468,7 @@ public function deleteAction(WorkspaceName $workspaceName): void
);
$this->addFlashMessage($message, '', Message::SEVERITY_WARNING);
$this->throwStatus(403, 'Workspace has unpublished nodes');
// delete workspace on POST
// delete workspace on POST -> todo make this more FLOW-ig by possibly having a DeleteController with post() and get() _or_ by having deleteAction_post and deleteAction_get?? Or a separate action?
} elseif ($this->request->getHttpRequest()->getMethod() === 'POST') {
$this->workspaceService->deleteWorkspace($contentRepositoryId, $workspaceName);

Expand Down Expand Up @@ -860,7 +865,7 @@ public function confirmPublishSelectedChangesAction(WorkspaceName $workspaceName
);
$this->throwStatus(404, 'Workspace does not exist');
}
$baseWorkspace = $this->getBaseWorkspaceWhenSureItExists($workspace, $contentRepository);
$baseWorkspace = $this->requireBaseWorkspace($workspace, $contentRepository);

$baseWorkspaceMetadata = $this->workspaceService->getWorkspaceMetadata($contentRepositoryId, $baseWorkspace->workspaceName);
$this->view->assignMultiple([
Expand Down Expand Up @@ -939,14 +944,18 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
$siteChanges = [];
$changes = $this->getChangesFromWorkspace($selectedWorkspace, $contentRepository);
foreach ($changes as $change) {
if ($change->originDimensionSpacePoint === null) {
// todo implement support for change node type!!! Because originDimensionSpacePoint is null currently for that case.
continue;
}
$workspaceName = $selectedWorkspace->workspaceName;
if ($change->deleted) {
// If we deleted a node, there is no way for us to anymore find the deleted node in the ContentStream
// where the node was deleted.
// Thus, to figure out the rootline for display, we check the *base workspace* Content Stream.
//
// This is safe because the UI basically shows what would be removed once the deletion is published.
$baseWorkspace = $this->getBaseWorkspaceWhenSureItExists($selectedWorkspace, $contentRepository);
$baseWorkspace = $this->requireBaseWorkspace($selectedWorkspace, $contentRepository);
$workspaceName = $baseWorkspace->workspaceName;
}
$subgraph = $contentRepository->getContentGraph($workspaceName)->getSubgraph(
Expand Down Expand Up @@ -1027,7 +1036,7 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
documentBreadCrumb: array_reverse($documentPathSegmentsNames),
aggregateId: $documentNodeAddress->aggregateId->value,
documentNodeAddress: $documentNodeAddress->toJson(),
documentIcon: $documentType->getFullConfiguration()['ui']['icon']
documentIcon: $documentType?->getFullConfiguration()['ui']['icon'] ?? null
);
}

Expand All @@ -1053,10 +1062,12 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
$dimensions = [];
foreach ($node->dimensionSpacePoint->coordinates as $id => $coordinate) {
$contentDimension = new ContentDimensionId($id);
$dimensions[] = $contentRepository->getContentDimensionSource()->getDimension($contentDimension)->getValue($coordinate)->configuration['label'];
$dimensions[] = $contentRepository->getContentDimensionSource()
->getDimension($contentDimension)
?->getValue($coordinate)
?->configuration['label'] ?? $coordinate;
}
$dimensionString = implode('_', $dimensions);
$siteChanges[$siteNodeName]['documents'][$documentPath]['changes'][$dimensionString][$relativePath] = new ChangeItem(
$siteChanges[$siteNodeName]['documents'][$documentPath]['changes'][$node->dimensionSpacePoint->hash][$relativePath] = new ChangeItem(
serializedNodeAddress: $nodeAddress->toJson(),
hidden: $node->tags->contain(SubtreeTag::disabled()),
isRemoved: $change->deleted,
Expand Down Expand Up @@ -1118,7 +1129,7 @@ protected function renderContentChanges(
);
$originalNode = null;
if ($currentWorkspace !== null) {
$baseWorkspace = $this->getBaseWorkspaceWhenSureItExists($currentWorkspace, $contentRepository);
$baseWorkspace = $this->requireBaseWorkspace($currentWorkspace, $contentRepository);
$originalNode = $this->getOriginalNode($changedNode, $baseWorkspace->workspaceName, $contentRepository);
}

Expand Down Expand Up @@ -1393,6 +1404,7 @@ protected function prepareBaseWorkspaceOptions(
}

/**
* Todo remove?
* Creates an array of user names and their respective labels which are possible owners for a workspace.
*
* @return array<int|string,string>
Expand All @@ -1408,15 +1420,17 @@ protected function prepareOwnerOptions(): array
return $ownerOptions;
}

private function getBaseWorkspaceWhenSureItExists(
private function requireBaseWorkspace(
Workspace $workspace,
ContentRepository $contentRepository,
): Workspace {
/** @var WorkspaceName $baseWorkspaceName We expect this to exist */
$baseWorkspaceName = $workspace->baseWorkspaceName;
/** @var Workspace $baseWorkspace We expect this to exist */
$baseWorkspace = $contentRepository->findWorkspaceByName($baseWorkspaceName);

if ($workspace->isRootWorkspace()) {
throw new \RuntimeException(sprintf('Workspace %s does not have a base-workspace.', $workspace->workspaceName->value), 1734019485);
}
$baseWorkspace = $contentRepository->findWorkspaceByName($workspace->baseWorkspaceName);
if ($baseWorkspace === null) {
throw new \RuntimeException(sprintf('Base-workspace %s of %s does not exist.', $workspace->baseWorkspaceName->value, $workspace->workspaceName->value), 1734019720);
}
return $baseWorkspace;
}

Expand Down
2 changes: 1 addition & 1 deletion Neos.Workspace.Ui/Classes/ViewModel/DocumentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
public array $documentBreadCrumb,
public string $aggregateId,
public string $documentNodeAddress,
public string $documentIcon
public ?string $documentIcon
) {
}
}

0 comments on commit 64119e2

Please sign in to comment.