From f15eabc2bffe7a4d52abba9b05339cc5f13237f6 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:00:14 +0200 Subject: [PATCH 1/3] TASK: Deprecate `WorkspaceFinder` and introduce forward-compatible API Based on https://github.com/neos/neos-development-collection/pull/5146 Required to ease migration to https://github.com/neos/neos-development-collection/pull/5096 --- .../Classes/ContentRepository.php | 25 ++++++++++++--- .../Projection/Workspace/Workspace.php | 5 +++ .../Projection/Workspace/WorkspaceFinder.php | 31 +++++++++++++++++-- .../Projection/Workspace/Workspaces.php | 26 ++++++++++++++++ 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index 955cf80fe26..e824402d322 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -36,7 +36,9 @@ use Neos\ContentRepository\Core\Projection\ProjectionStateInterface; use Neos\ContentRepository\Core\Projection\ProjectionStatuses; use Neos\ContentRepository\Core\Projection\WithMarkStaleInterface; +use Neos\ContentRepository\Core\Projection\Workspace\Workspace; use Neos\ContentRepository\Core\Projection\Workspace\WorkspaceFinder; +use Neos\ContentRepository\Core\Projection\Workspace\Workspaces; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryStatus; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; @@ -234,11 +236,6 @@ public function resetProjectionState(string $projectionClassName): void $projection->reset(); } - public function getNodeTypeManager(): NodeTypeManager - { - return $this->nodeTypeManager; - } - /** * @throws WorkspaceDoesNotExist if the workspace does not exist */ @@ -247,6 +244,19 @@ public function getContentGraph(WorkspaceName $workspaceName): ContentGraphInter return $this->projectionState(ContentGraphFinder::class)->getByWorkspaceName($workspaceName); } + public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace + { + return $this->getWorkspaceFinder()->findOneByName($workspaceName); + } + + public function getWorkspaces(): Workspaces + { + return $this->getWorkspaceFinder()->findAll(); + } + + /** + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. + */ public function getWorkspaceFinder(): WorkspaceFinder { return $this->projectionState(WorkspaceFinder::class); @@ -257,6 +267,11 @@ public function getContentStreamFinder(): ContentStreamFinder return $this->projectionState(ContentStreamFinder::class); } + public function getNodeTypeManager(): NodeTypeManager + { + return $this->nodeTypeManager; + } + public function getVariationGraph(): InterDimensionalVariationGraph { return $this->variationGraph; diff --git a/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspace.php b/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspace.php index ddb826aff52..ff339ca5acc 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspace.php +++ b/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspace.php @@ -129,4 +129,9 @@ public function isPublicWorkspace(): bool { return $this->baseWorkspaceName === null && $this->workspaceOwner === null; } + + public function isRootWorkspace(): bool + { + return $this->baseWorkspaceName !== null; + } } diff --git a/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php b/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php index bd87127f8d7..664d18a2bb0 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php +++ b/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php @@ -23,9 +23,10 @@ use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle; /** - * Workspace Finder + * The legacy Workspace Finder * - * @api + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. + * @internal */ final class WorkspaceFinder implements ProjectionStateInterface { @@ -36,7 +37,9 @@ public function __construct( ) { } - + /** + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::findWorkspaceByName()} instead + */ public function findOneByName(WorkspaceName $name): ?Workspace { $workspace = $this->workspaceRuntimeCache->getWorkspaceByName($name); @@ -63,6 +66,15 @@ public function findOneByName(WorkspaceName $name): ?Workspace return $workspace; } + /** + * @deprecated with 9.0.0-beta14 discouraged. You should just operate on workspace names instead. + * To still archive the functionality please use {@see ContentRepository::getWorkspaces()} instead and filter the result: + * + * $this->contentRepository->getWorkspaces()->find( + * fn (Workspace $workspace) => $workspace->currentContentStreamId->equals($contentStreamId) + * ) + * + */ public function findOneByCurrentContentStreamId( ContentStreamId $contentStreamId ): ?Workspace { @@ -91,6 +103,7 @@ public function findOneByCurrentContentStreamId( } /** + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see Workspaces::getBaseWorkspaces()} instead. * @return array * @throws DBALException */ @@ -116,6 +129,9 @@ public function findByBaseWorkspace(WorkspaceName $baseWorkspace): array return $result; } + /** + * @deprecated with 9.0.0-beta14 owners/collaborators should be assigned to workspaces outside the Content Repository core + */ public function findOneByWorkspaceOwner(string $owner): ?Workspace { $workspaceRow = $this->dbal->executeQuery( @@ -135,6 +151,9 @@ public function findOneByWorkspaceOwner(string $owner): ?Workspace return $this->createWorkspaceFromDatabaseRow($workspaceRow); } + /** + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} instead + */ public function findAll(): Workspaces { $result = []; @@ -154,6 +173,12 @@ public function findAll(): Workspaces } /** + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} instead and filter the result: + * + * $this->contentRepository->getWorkspaces()->filter( + * fn (Workspace $workspace) => $workspace->status === WorkspaceStatus::OUTDATED + * ) + * * @return array * @throws \Doctrine\DBAL\Driver\Exception * @throws DBALException diff --git a/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php b/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php index f8fea6db6db..816de4847d8 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php +++ b/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php @@ -100,8 +100,34 @@ public function getIterator(): \Traversable yield from array_values($this->workspaces); } + /** + * @param \Closure(Workspace): bool $callback + */ + public function filter(\Closure $callback): self + { + return new self(array_filter($this->workspaces, $callback)); + } + + /** + * @param \Closure(Workspace): bool $callback + */ + public function find(\Closure $callback): ?Workspace + { + foreach ($this->workspaces as $workspace) { + if ($callback($workspace)) { + return $workspace; + } + } + return null; + } + public function count(): int { return count($this->workspaces); } + + public function isEmpty(): bool + { + return $this->workspaces === []; + } } From c0528e781014c149dcf275e40dcf21581c254ca4 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:28:33 +0200 Subject: [PATCH 2/3] TASK: Update `Workspaces` utilities according to #5096 https://github.com/neos/neos-development-collection/pull/5096/commits/db7861f683f7e308f8515d4be955ccc57dc04fd1 --- .../Projection/Workspace/WorkspaceFinder.php | 5 +++-- .../Projection/Workspace/Workspaces.php | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php b/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php index 664d18a2bb0..f05b5e676b7 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php +++ b/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php @@ -26,7 +26,7 @@ * The legacy Workspace Finder * * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. - * @internal + * @api */ final class WorkspaceFinder implements ProjectionStateInterface { @@ -103,7 +103,7 @@ public function findOneByCurrentContentStreamId( } /** - * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see Workspaces::getBaseWorkspaces()} instead. + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see Workspaces::getDependantWorkspaces()} instead. * @return array * @throws DBALException */ @@ -131,6 +131,7 @@ public function findByBaseWorkspace(WorkspaceName $baseWorkspace): array /** * @deprecated with 9.0.0-beta14 owners/collaborators should be assigned to workspaces outside the Content Repository core + * For Neos.Neos please use {@see \Neos\Neos\Domain\Service\WorkspaceService::getPersonalWorkspaceForUser()} */ public function findOneByWorkspaceOwner(string $owner): ?Workspace { diff --git a/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php b/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php index 816de4847d8..af32c2634d0 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php +++ b/Neos.ContentRepository.Core/Classes/Projection/Workspace/Workspaces.php @@ -92,6 +92,16 @@ public function getBaseWorkspaces(WorkspaceName $workspaceName): Workspaces return Workspaces::fromArray($baseWorkspaces); } + /** + * Get all dependent workspaces (if they are included in this result set). + */ + public function getDependantWorkspaces(WorkspaceName $workspaceName): Workspaces + { + return $this->filter( + static fn (Workspace $potentiallyDependentWorkspace) => $potentiallyDependentWorkspace->baseWorkspaceName?->equals($workspaceName) ?? false + ); + } + /** * @return \Traversable */ @@ -121,6 +131,16 @@ public function find(\Closure $callback): ?Workspace return null; } + /** + * @template T + * @param \Closure(Workspace): T $callback + * @return list + */ + public function map(\Closure $callback): array + { + return array_map($callback, array_values($this->workspaces)); + } + public function count(): int { return count($this->workspaces); From 6a84332c0ac08dffe3778ed654290f62ee165abd Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:08:37 +0200 Subject: [PATCH 3/3] TASK: Adjust to `find*` vs `get*` convention > "all operations which are slow should be named find*", vs. "all operations which operate on already-loaded data should be named get*". --- .../Classes/ContentRepository.php | 4 ++-- .../Classes/Projection/Workspace/WorkspaceFinder.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index e824402d322..96b3025f57a 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -249,13 +249,13 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace return $this->getWorkspaceFinder()->findOneByName($workspaceName); } - public function getWorkspaces(): Workspaces + public function findWorkspaces(): Workspaces { return $this->getWorkspaceFinder()->findAll(); } /** - * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::findWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. */ public function getWorkspaceFinder(): WorkspaceFinder { diff --git a/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php b/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php index f05b5e676b7..61e18df5fc7 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php +++ b/Neos.ContentRepository.Core/Classes/Projection/Workspace/WorkspaceFinder.php @@ -25,7 +25,7 @@ /** * The legacy Workspace Finder * - * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::findWorkspaces()} and {@see ContentRepository::findWorkspaceByName()} instead. * @api */ final class WorkspaceFinder implements ProjectionStateInterface @@ -68,7 +68,7 @@ public function findOneByName(WorkspaceName $name): ?Workspace /** * @deprecated with 9.0.0-beta14 discouraged. You should just operate on workspace names instead. - * To still archive the functionality please use {@see ContentRepository::getWorkspaces()} instead and filter the result: + * To still archive the functionality please use {@see ContentRepository::findWorkspaces()} instead and filter the result: * * $this->contentRepository->getWorkspaces()->find( * fn (Workspace $workspace) => $workspace->currentContentStreamId->equals($contentStreamId) @@ -103,9 +103,9 @@ public function findOneByCurrentContentStreamId( } /** - * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} and {@see Workspaces::getDependantWorkspaces()} instead. * @return array * @throws DBALException + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::findWorkspaces()} and {@see Workspaces::getDependantWorkspaces()} instead. */ public function findByBaseWorkspace(WorkspaceName $baseWorkspace): array { @@ -153,7 +153,7 @@ public function findOneByWorkspaceOwner(string $owner): ?Workspace } /** - * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} instead + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::findWorkspaces()} instead */ public function findAll(): Workspaces { @@ -174,7 +174,7 @@ public function findAll(): Workspaces } /** - * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::getWorkspaces()} instead and filter the result: + * @deprecated with 9.0.0-beta14 please use {@see ContentRepository::findWorkspaces()} instead and filter the result: * * $this->contentRepository->getWorkspaces()->filter( * fn (Workspace $workspace) => $workspace->status === WorkspaceStatus::OUTDATED