Skip to content

Commit

Permalink
Merge pull request #5340 from mhsdesign/task/remove-obsolete-findCont…
Browse files Browse the repository at this point in the history
…entStreams

TASK: Remove obsolete `findContentStream(s)`
  • Loading branch information
mhsdesign authored Jan 14, 2025
2 parents 36465ba + f3988cc commit 07bbe1b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 168 deletions.
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
13 changes: 0 additions & 13 deletions Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +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\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 @@ -192,16 +189,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 @@ -42,10 +41,11 @@ public function findWorkspaceByName(WorkspaceName $workspaceName): ?Workspace;

public function findWorkspaces(): Workspaces;

/**
* @internal only used for constraint checks and in testcases, the public API must only use workspaces {@see findWorkspaceByName}.
*/
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -31,9 +31,6 @@ private function __construct(
) {
}

/**
* @internal
*/
public static function create(
ContentStreamId $id,
?ContentStreamId $sourceContentStreamId,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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 @@ -116,7 +116,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 @@ -141,20 +141,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->contentGraphReadModel;
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 @@ -251,6 +238,22 @@ abstract protected function getContentRepositoryService(
ContentRepositoryServiceFactoryInterface $factory
): ContentRepositoryServiceInterface;

final protected function getContentGraphReadModel(): ContentGraphReadModelInterface
{
return $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;
}

/**
* @When I replay the :projectionName projection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 07bbe1b

Please sign in to comment.