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

TASK: Remove obsolete findContentStream(s) #5340

Open
wants to merge 4 commits into
base: 9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -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;
Expand Down Expand Up @@ -123,22 +122,6 @@ public function findContentStreamById(ContentStreamId $contentStreamId): ?Conten
return self::contentStreamFromDatabaseRow($row);
}

public function findContentStreams(): ContentStreams
{
$contentStreamsStatement = <<<SQL
SELECT
id, sourceContentStreamId, version, closed
FROM
{$this->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 = <<<SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use Doctrine\DBAL\Connection;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\ContentHypergraph;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
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\ContentStreams;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces;
Expand Down Expand Up @@ -60,12 +59,6 @@ public function findContentStreamById(ContentStreamId $contentStreamId): ?Conten
return null;
}

public function findContentStreams(): ContentStreams
{
// TODO: Implement getContentStreams() method.
return ContentStreams::createEmpty();
}

public function countNodes(): int
{
// TODO: Implement countNodes method.
Expand Down
14 changes: 0 additions & 14 deletions Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@
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\ContentStreams;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspaces;
use Neos\EventStore\EventStoreInterface;
use Neos\EventStore\Exception\ConcurrencyException;
use Neos\EventStore\Model\EventEnvelope;
use Neos\EventStore\Model\EventStream\VirtualStreamName;
use Psr\Clock\ClockInterface;
Expand Down Expand Up @@ -252,16 +248,6 @@ public function findWorkspaces(): Workspaces
return $this->contentGraphReadModel->findWorkspaces();
}

public function findContentStreamById(ContentStreamId $contentStreamId): ?ContentStream
{
return $this->contentGraphReadModel->findContentStreamById($contentStreamId);
}

public function findContentStreams(): ContentStreams
{
return $this->contentGraphReadModel->findContentStreams();
}

public function getNodeTypeManager(): NodeTypeManager
{
return $this->nodeTypeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,10 +37,11 @@ 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;

public function findContentStreams(): ContentStreams;

/**
* Provides the total number of projected nodes regardless of workspace or content stream.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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 . '.');
}

Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe, if we like it or not, we should just expose the ContentGraphReadModel ON the content repository directly as @internal method with note to be careful. We cannot avoid people ditching security (see $context->withoutAuthorisationChecks) and as this ContentGraphReadModel will soon to be exposed for catchup hooks as api already ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's not about preventing folks to intentionally circumvent security – they always can, as you pointed out.
But the API should make that cumbersome or at least very very explicit. And exposing a internal concept in an api-object is a code smell IMO (even if it is marked with warnings)

I think, we should just have some custom "accessor factory" in our CRTestSuiteTrait that is instantiated once and provides read-access to all required dependencies.

Copy link
Member Author

@mhsdesign mhsdesign Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is instantiated once

Okay agreed, but that escalated to a (possibly) bigger change: #5341 so lets have this optimisation separate for later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather merge many small changes than always having these huge refactor everyhting things...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oke so are you fine with the code now? @kitsunet

{
return $this->getContentRepositoryServiceFactoryDependencies()
->projectionsAndCatchUpHooks
->contentGraphProjection
->getState();
}

/**
* @When I replay the :projectionName projection
*/
Expand Down
Loading