From 6249a98b56e1bf34fa8b5495aea8709f92a897ec Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 2 Nov 2024 14:50:23 +0100 Subject: [PATCH 1/5] TASK: Remove obsolete `findContentStreams` --- .../src/ContentGraphReadModelAdapter.php | 17 ---- .../src/ContentHyperGraphReadModelAdapter.php | 9 +- .../Classes/ContentRepository.php | 7 -- .../ContentGraphReadModelInterface.php | 3 - .../SharedModel/Workspace/ContentStreams.php | 95 ------------------- 5 files changed, 1 insertion(+), 130 deletions(-) delete mode 100644 Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStreams.php diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphReadModelAdapter.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphReadModelAdapter.php index 7e5e2051a5f..8a0f6de9359 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphReadModelAdapter.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/ContentGraphReadModelAdapter.php @@ -25,7 +25,6 @@ use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreams; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces; @@ -123,22 +122,6 @@ public function findContentStreamById(ContentStreamId $contentStreamId): ?Conten return self::contentStreamFromDatabaseRow($row); } - public function findContentStreams(): ContentStreams - { - $contentStreamsStatement = <<tableNames->contentStream()} - SQL; - try { - $rows = $this->dbal->fetchAllAssociative($contentStreamsStatement); - } catch (Exception $e) { - throw new \RuntimeException(sprintf('Failed to load content streams from database: %s', $e->getMessage()), 1716903042, $e); - } - return ContentStreams::fromArray(array_map(self::contentStreamFromDatabaseRow(...), $rows)); - } - public function countNodes(): int { $countNodesStatement = <<contentGraphReadModel->findContentStreamById($contentStreamId); } - public function findContentStreams(): ContentStreams - { - return $this->contentGraphReadModel->findContentStreams(); - } - public function getNodeTypeManager(): NodeTypeManager { return $this->nodeTypeManager; diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php index e1298bc151e..c44dc7379aa 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php @@ -18,7 +18,6 @@ use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreams; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces; @@ -40,8 +39,6 @@ public function findWorkspaces(): Workspaces; public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream; - public function findContentStreams(): ContentStreams; - /** * Provides the total number of projected nodes regardless of workspace or content stream. * diff --git a/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStreams.php b/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStreams.php deleted file mode 100644 index 75fea156bd8..00000000000 --- a/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStreams.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * @api - */ -final class ContentStreams implements \IteratorAggregate, \Countable -{ - /** - * @var array - */ - private array $contentStreams; - - /** - * @param iterable $collection - */ - private function __construct(iterable $collection) - { - $contentStreams = []; - foreach ($collection as $item) { - if (!$item instanceof ContentStream) { - throw new \InvalidArgumentException(sprintf('ContentStreams must only consist of %s objects, got: %s', ContentStream::class, get_debug_type($item)), 1716900709); - } - $contentStreams[$item->id->value] = $item; - } - - $this->contentStreams = $contentStreams; - } - - /** - * @param array $contentStreams - */ - public static function fromArray(array $contentStreams): self - { - return new self($contentStreams); - } - - public static function createEmpty(): self - { - return new self([]); - } - - public function getIterator(): \Traversable - { - yield from array_values($this->contentStreams); - } - - /** - * @param \Closure(ContentStream): bool $callback - */ - public function filter(\Closure $callback): self - { - return new self(array_filter($this->contentStreams, $callback)); - } - - /** - * @param \Closure(ContentStream): bool $callback - */ - public function find(\Closure $callback): ?ContentStream - { - foreach ($this->contentStreams as $contentStream) { - if ($callback($contentStream)) { - return $contentStream; - } - } - return null; - } - - public function count(): int - { - return count($this->contentStreams); - } - - public function isEmpty(): bool - { - return $this->contentStreams === []; - } -} From 9375fd92cead9601e868b31de8254ba6ee98713a Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sat, 2 Nov 2024 15:01:57 +0100 Subject: [PATCH 2/5] TASK: Make `findContentStreamById` fully internal (like `countNodes`) --- .../Classes/ContentRepository.php | 7 --- .../ContentGraphReadModelInterface.php | 3 ++ .../Features/Bootstrap/CRTestSuiteTrait.php | 44 ++++++++++++------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index 7f12b3c8be1..b6e0708ed01 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -38,8 +38,6 @@ use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryStatus; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; use Neos\ContentRepository\Core\SharedModel\User\UserIdProviderInterface; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces; @@ -250,11 +248,6 @@ public function findWorkspaces(): Workspaces return $this->contentGraphReadModel->findWorkspaces(); } - public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream - { - return $this->contentGraphReadModel->findContentStreamById($contentStreamId); - } - public function getNodeTypeManager(): NodeTypeManager { return $this->nodeTypeManager; diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php index c44dc7379aa..58232977141 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php @@ -37,6 +37,9 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace; public function findWorkspaces(): Workspaces; + /** + * @internal only used for constraint checks and in testcases + */ public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream; /** diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php index 18fddc56f68..f0e71b8027e 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php @@ -132,7 +132,7 @@ protected function readPayloadTable(TableNode $payloadTable): array */ public function iExpectTheContentStreamToExist(string $rawContentStreamId): void { - $contentStream = $this->currentContentRepository->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); + $contentStream = $this->getContentGraphReadModel()->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); Assert::assertNotNull($contentStream, sprintf('Content stream "%s" was expected to exist, but it does not', $rawContentStreamId)); } @@ -141,7 +141,7 @@ public function iExpectTheContentStreamToExist(string $rawContentStreamId): void */ public function iExpectTheContentStreamToNotExist(string $rawContentStreamId, string $not = ''): void { - $contentStream = $this->currentContentRepository->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); + $contentStream = $this->getContentGraphReadModel()->findContentStreamById(ContentStreamId::fromString($rawContentStreamId)); Assert::assertNull($contentStream, sprintf('Content stream "%s" was not expected to exist, but it does', $rawContentStreamId)); } @@ -166,20 +166,7 @@ public function workspaceStatusMatchesExpected(string $rawWorkspaceNames, string */ public function iExpectTheGraphProjectionToConsistOfExactlyNodes(int $expectedNumberOfNodes): void { - // HACK to access - $contentGraphReadModelAccess = new class implements ContentRepositoryServiceFactoryInterface { - public ContentGraphReadModelInterface|null $instance; - public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface - { - $this->instance = $serviceFactoryDependencies->projectionsAndCatchUpHooks->contentGraphProjection->getState(); - return new class implements ContentRepositoryServiceInterface - { - }; - } - }; - $this->getContentRepositoryService($contentGraphReadModelAccess); - - $actualNumberOfNodes = $contentGraphReadModelAccess->instance->countNodes(); + $actualNumberOfNodes = $this->getContentGraphReadModel()->countNodes(); Assert::assertSame($expectedNumberOfNodes, $actualNumberOfNodes, 'Content graph consists of ' . $actualNumberOfNodes . ' nodes, expected were ' . $expectedNumberOfNodes . '.'); } @@ -276,6 +263,31 @@ abstract protected function getContentRepositoryService( ContentRepositoryServiceFactoryInterface $factory ): ContentRepositoryServiceInterface; + final protected function getContentRepositoryServiceFactoryDependencies(): ContentRepositoryServiceFactoryDependencies + { + $accessorFactory = new class implements ContentRepositoryServiceFactoryInterface { + public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface + { + return new class ($serviceFactoryDependencies) implements ContentRepositoryServiceInterface + { + public function __construct( + public readonly ContentRepositoryServiceFactoryDependencies $dependencies + ) { + } + }; + } + }; + return $this->getContentRepositoryService($accessorFactory)->dependencies; + } + + final protected function getContentGraphReadModel(): ContentGraphReadModelInterface + { + return $this->getContentRepositoryServiceFactoryDependencies() + ->projectionsAndCatchUpHooks + ->contentGraphProjection + ->getState(); + } + /** * @When I replay the :projectionName projection */ From e66da9446f0e6780c1526208c5c8f61960652685 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:08:06 +0100 Subject: [PATCH 3/5] TASK: Declare `ContentStream` read model internal --- .../ContentGraph/ContentGraphReadModelInterface.php | 2 +- .../Classes/SharedModel/Workspace/ContentStream.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php index 090d3320196..58833404882 100644 --- a/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php +++ b/Neos.ContentRepository.Core/Classes/Projection/ContentGraph/ContentGraphReadModelInterface.php @@ -42,7 +42,7 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace; public function findWorkspaces(): Workspaces; /** - * @internal only used for constraint checks and in testcases + * @internal only used for constraint checks and in testcases, the public API must only use workspaces {@see findWorkspaceByName}. */ public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream; diff --git a/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStream.php b/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStream.php index c52109de269..3de05a5103d 100644 --- a/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStream.php +++ b/Neos.ContentRepository.Core/Classes/SharedModel/Workspace/ContentStream.php @@ -19,7 +19,7 @@ /** * Content Stream Read Model * - * @api Note: The constructor is not part of the public API + * @internal the public API is limited to the {@see Workspace} read model */ final readonly class ContentStream { @@ -31,9 +31,6 @@ private function __construct( ) { } - /** - * @internal - */ public static function create( ContentStreamId $id, ?ContentStreamId $sourceContentStreamId, From 0c8162bc11425a7c22b798b0fed8c06df8d8b91b Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Tue, 14 Jan 2025 10:39:40 +0100 Subject: [PATCH 4/5] TASK: Fix and simplify getContentGraphReadModel for testing --- .../Features/Bootstrap/CRTestSuiteTrait.php | 21 ++++++------------- .../ContentRepositorySecurityTrait.php | 13 +----------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php index 911d27b9d86..0bde052fc71 100644 --- a/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php +++ b/Neos.ContentRepository.TestSuite/Classes/Behavior/Features/Bootstrap/CRTestSuiteTrait.php @@ -238,29 +238,20 @@ abstract protected function getContentRepositoryService( ContentRepositoryServiceFactoryInterface $factory ): ContentRepositoryServiceInterface; - final protected function getContentRepositoryServiceFactoryDependencies(): ContentRepositoryServiceFactoryDependencies + final protected function getContentGraphReadModel(): ContentGraphReadModelInterface { - $accessorFactory = new class implements ContentRepositoryServiceFactoryInterface { + return $this->getContentRepositoryService(new class implements ContentRepositoryServiceFactoryInterface { public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface { - return new class ($serviceFactoryDependencies) implements ContentRepositoryServiceInterface - { + $contentGraphReadModel = $serviceFactoryDependencies->contentGraphReadModel; + return new class ($contentGraphReadModel) implements ContentRepositoryServiceInterface { public function __construct( - public readonly ContentRepositoryServiceFactoryDependencies $dependencies + public ContentGraphReadModelInterface $contentGraphReadModel, ) { } }; } - }; - return $this->getContentRepositoryService($accessorFactory)->dependencies; - } - - final protected function getContentGraphReadModel(): ContentGraphReadModelInterface - { - return $this->getContentRepositoryServiceFactoryDependencies() - ->projectionsAndCatchUpHooks - ->contentGraphProjection - ->getState(); + })->contentGraphReadModel; } /** diff --git a/Neos.Neos/Tests/Behavior/Features/Bootstrap/ContentRepositorySecurityTrait.php b/Neos.Neos/Tests/Behavior/Features/Bootstrap/ContentRepositorySecurityTrait.php index 5b0a2d46eb7..0755b5f4458 100644 --- a/Neos.Neos/Tests/Behavior/Features/Bootstrap/ContentRepositorySecurityTrait.php +++ b/Neos.Neos/Tests/Behavior/Features/Bootstrap/ContentRepositorySecurityTrait.php @@ -67,18 +67,7 @@ private function enableContentRepositorySecurity(): void return; } $contentRepositoryAuthProviderFactory = $this->getObject(ContentRepositoryAuthProviderFactory::class); - $contentGraphReadModel = $this->getContentRepositoryService(new class implements ContentRepositoryServiceFactoryInterface { - public function build(ContentRepositoryServiceFactoryDependencies $serviceFactoryDependencies): ContentRepositoryServiceInterface - { - $contentGraphReadModel = $serviceFactoryDependencies->contentGraphReadModel; - return new class ($contentGraphReadModel) implements ContentRepositoryServiceInterface { - public function __construct( - public ContentGraphReadModelInterface $contentGraphReadModel, - ) { - } - }; - } - })->contentGraphReadModel; + $contentGraphReadModel = $this->getContentGraphReadModel(); $contentRepositoryAuthProvider = $contentRepositoryAuthProviderFactory->build($this->currentContentRepository->id, $contentGraphReadModel); FakeAuthProvider::replaceAuthProvider($contentRepositoryAuthProvider); From f3988cc61cdefd7f1de5924eb7116379888416f9 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Tue, 14 Jan 2025 11:24:21 +0100 Subject: [PATCH 5/5] TASK: Cleanup obsolete imports --- Neos.ContentRepository.Core/Classes/ContentRepository.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/ContentRepository.php b/Neos.ContentRepository.Core/Classes/ContentRepository.php index f0869774326..1658d1d045f 100644 --- a/Neos.ContentRepository.Core/Classes/ContentRepository.php +++ b/Neos.ContentRepository.Core/Classes/ContentRepository.php @@ -34,8 +34,6 @@ use Neos\ContentRepository\Core\Projection\ProjectionStates; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStream; -use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces;