Skip to content

Commit

Permalink
Code renaming and refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Apr 13, 2024
1 parent 1b1f386 commit 6d501b2
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\Projection\Workspace\WorkspaceStatus;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Exception\ContentStreamDoesNotExistYet;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Id\UuidFactory;
Expand All @@ -62,13 +63,14 @@
/**
* DBAL implementation of low level read query operations for the content graph
*
* @įnternal
* @internal
*/
class ContentGraphAdapter implements ContentGraphAdapterInterface
{
public function __construct(
private readonly Connection $dbalConnection,
private readonly string $tableNamePrefix,
private ContentRepositoryId $contentRepositoryId,
private readonly NodeFactory $nodeFactory,
private readonly NodeTypeManager $nodeTypeManager,
public ?WorkspaceName $workspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterFactoryInterface;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterInterface;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
*
* Factory for the ContentGraphAdapter implementation for doctrine DBAL
*
* @internal
*/
class ContentGraphAdapterFactory implements ContentGraphAdapterFactoryInterface
{
Expand All @@ -23,6 +26,8 @@ class ContentGraphAdapterFactory implements ContentGraphAdapterFactoryInterface

private string $tableNamePrefix;

private ContentRepositoryId $contentRepositoryId;

public function __construct(
private readonly Connection $dbalConnection,
ProjectionFactoryDependencies $projectionFactoryDependencies
Expand All @@ -31,6 +36,7 @@ public function __construct(
$projectionFactoryDependencies->contentRepositoryId
);
$this->tableNamePrefix = $tableNamePrefix;
$this->contentRepositoryId = $projectionFactoryDependencies->contentRepositoryId;

$dimensionSpacePointsRepository = new DimensionSpacePointsRepository($this->dbalConnection, $tableNamePrefix);
$this->nodeTypeManager = $projectionFactoryDependencies->nodeTypeManager;
Expand All @@ -44,16 +50,16 @@ public function __construct(

public function create(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphAdapterInterface
{
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $this->nodeFactory, $this->nodeTypeManager, $workspaceName, $contentStreamId);
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $this->contentRepositoryId, $this->nodeFactory, $this->nodeTypeManager, $workspaceName, $contentStreamId);
}

public function createFromContentStreamId(ContentStreamId $contentStreamId): ContentGraphAdapterInterface
{
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $this->nodeFactory, $this->nodeTypeManager, null, $contentStreamId);
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $this->contentRepositoryId, $this->nodeFactory, $this->nodeTypeManager, null, $contentStreamId);
}

public function createFromWorkspaceName(WorkspaceName $workspaceName): ContentGraphAdapterInterface
{
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $this->nodeFactory, $this->nodeTypeManager, $workspaceName, null);
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $this->contentRepositoryId, $this->nodeFactory, $this->nodeTypeManager, $workspaceName, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This is available on the write side of the ContentRepository.
*
* @see ContentGraphAdapterInterface
* @internal
* @api only for read access during write operations and in services
*/
class ContentGraphAdapterProvider
{
Expand All @@ -29,13 +29,13 @@ public function __construct(
/**
* TODO: We should not need this,
* TODO: after introducing the NodeIdentity we can change usages to
* TODO: ContentGraphAdapterProvider::resolveContentStreamIdAndGet() and remove this
* TODO: ContentGraphAdapterProvider::fromWorkspaceName() and remove this
*
* @throws ContentStreamDoesNotExistYet if there is no content stream with the provided id
* @deprecated
*
*/
public function resolveWorkspaceNameAndGet(ContentStreamId $contentStreamId): ContentGraphAdapterInterface
public function fromContentStreamId(ContentStreamId $contentStreamId): ContentGraphAdapterInterface
{
return $this->contentGraphAdapterFactory->createFromContentStreamId($contentStreamId);
}
Expand All @@ -44,7 +44,7 @@ public function resolveWorkspaceNameAndGet(ContentStreamId $contentStreamId): Co
* @throws WorkspaceDoesNotExist if there is no workspace with the provided name
* @throws ContentStreamDoesNotExistYet if the provided workspace does not resolve to an existing content stream
*/
public function resolveContentStreamIdAndGet(WorkspaceName $workspaceName): ContentGraphAdapterInterface
public function fromWorkspaceName(WorkspaceName $workspaceName): ContentGraphAdapterInterface
{
if (isset($this->adapterInstances[$workspaceName->value])) {
return $this->adapterInstances[$workspaceName->value];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function handleForkContentStream(
$this->requireContentStreamToNotBeClosed($command->sourceContentStreamId);

// TOOD: THis is not great
$sourceContentStreamVersion = $this->contentGraphAdapterProvider->resolveWorkspaceNameAndGet($command->sourceContentStreamId)
$sourceContentStreamVersion = $this->contentGraphAdapterProvider->fromContentStreamId($command->sourceContentStreamId)
->findVersionForContentStream();

$streamName = ContentStreamEventStreamName::fromContentStreamId($command->newContentStreamId)
Expand Down Expand Up @@ -184,7 +184,7 @@ private function handleRemoveContentStream(
protected function requireContentStreamToExist(
ContentStreamId $contentStreamId
): void {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveWorkspaceNameAndGet($contentStreamId);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromContentStreamId($contentStreamId);
if (!$contentGraphAdapter->contentStreamExists()) {
throw new ContentStreamDoesNotExistYet(
'Content stream "' . $contentStreamId->value . '" does not exist yet.',
Expand All @@ -196,7 +196,7 @@ protected function requireContentStreamToExist(
protected function requireContentStreamToNotBeClosed(
ContentStreamId $contentStreamId
): void {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveWorkspaceNameAndGet($contentStreamId);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromContentStreamId($contentStreamId);
if ($contentGraphAdapter->findStateForContentStream() === ContentStreamState::STATE_CLOSED) {
throw new ContentStreamIsClosed(
'Content stream "' . $contentStreamId->value . '" is closed.',
Expand All @@ -208,7 +208,7 @@ protected function requireContentStreamToNotBeClosed(
protected function requireContentStreamToBeClosed(
ContentStreamId $contentStreamId
): void {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveWorkspaceNameAndGet($contentStreamId);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromContentStreamId($contentStreamId);
if ($contentGraphAdapter->findStateForContentStream() !== ContentStreamState::STATE_CLOSED) {
throw new ContentStreamIsNotClosed(
'Content stream "' . $contentStreamId->value . '" is not closed.',
Expand All @@ -220,7 +220,7 @@ protected function requireContentStreamToBeClosed(
protected function getExpectedVersionOfContentStream(
ContentStreamId $contentStreamId
): ExpectedVersion {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveWorkspaceNameAndGet($contentStreamId);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromContentStreamId($contentStreamId);
return ExpectedVersion::fromVersion(
$contentGraphAdapter->findVersionForContentStream()
->unwrap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function handle(CommandInterface $command, ContentRepository $contentRepo
private function handleMoveDimensionSpacePoint(
MoveDimensionSpacePoint $command
): EventsToPublish {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentGraphAdapter->getContentStreamId())
->getEventStreamName();

Expand All @@ -90,7 +90,7 @@ private function handleMoveDimensionSpacePoint(
private function handleAddDimensionShineThrough(
AddDimensionShineThrough $command
): EventsToPublish {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentGraphAdapter->getContentStreamId())
->getEventStreamName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function getPropertyConverter(): PropertyConverter
*/
protected function getContentGraphAdapter(WorkspaceName $workspaceName): ContentGraphAdapterInterface
{
return $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($workspaceName);
return $this->contentGraphAdapterProvider->fromWorkspaceName($workspaceName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function handleDisableNodeAggregate(
DisableNodeAggregate $command
): EventsToPublish {
$this->requireContentStream($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$expectedVersion = $this->getExpectedVersionOfContentStream($contentGraphAdapter);
$this->requireDimensionSpacePointToExist($command->coveredDimensionSpacePoint);
$nodeAggregate = $this->requireProjectedNodeAggregate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(
*/
protected function getContentGraphAdapter(WorkspaceName $workspaceName): ContentGraphAdapterInterface
{
return $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($workspaceName);
return $this->contentGraphAdapterProvider->fromWorkspaceName($workspaceName);
}

protected function getNodeTypeManager(): NodeTypeManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private function handleCreateWorkspace(
ContentRepository $contentRepository,
): EventsToPublish {
try {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$contentStreamId = $contentGraphAdapter->getContentStreamId();
} catch (ContentStreamDoesNotExistYet $e) {
// Desired outcome
Expand All @@ -138,7 +138,7 @@ private function handleCreateWorkspace(
$command->workspaceName->value
), 1505830958921);

$baseWorkspaceContentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->baseWorkspaceName);
$baseWorkspaceContentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->baseWorkspaceName);
// if ($baseWorkspace === null) {
// throw new BaseWorkspaceDoesNotExist(sprintf(
// 'The workspace %s (base workspace of %s) does not exist',
Expand Down Expand Up @@ -206,7 +206,7 @@ private function handleCreateRootWorkspace(
ContentRepository $contentRepository,
): EventsToPublish {
try {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$contentStreamId = $contentGraphAdapter->getContentStreamId();
} catch (ContentStreamDoesNotExistYet $e) {
// Desired outcome
Expand Down Expand Up @@ -498,7 +498,7 @@ private function handlePublishIndividualNodesFromWorkspace(
PublishIndividualNodesFromWorkspace $command,
ContentRepository $contentRepository,
): EventsToPublish {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$workspace = $this->requireWorkspace($command->workspaceName);
$oldWorkspaceContentStreamId = $workspace->currentContentStreamId;
$oldWorkspaceContentStreamIdState = $contentGraphAdapter->findStateForContentStream();
Expand Down Expand Up @@ -637,7 +637,7 @@ private function handleDiscardIndividualNodesFromWorkspace(
DiscardIndividualNodesFromWorkspace $command,
ContentRepository $contentRepository,
): EventsToPublish {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($command->workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($command->workspaceName);
$workspace = $contentGraphAdapter->getWorkspace();
$oldWorkspaceContentStreamId = $contentGraphAdapter->getContentStreamId();
$oldWorkspaceContentStreamIdState = $contentGraphAdapter->findStateForContentStream();
Expand Down Expand Up @@ -912,7 +912,7 @@ private function handleChangeWorkspaceOwner(
*/
private function requireWorkspace(WorkspaceName $workspaceName): Workspace
{
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($workspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($workspaceName);
return $contentGraphAdapter->getWorkspace();
}

Expand All @@ -927,7 +927,7 @@ private function requireBaseWorkspace(Workspace $workspace): Workspace
}

try {
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($workspace->baseWorkspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($workspace->baseWorkspaceName);
$baseWorkspace = $contentGraphAdapter->getWorkspace();
} catch (WorkspaceDoesNotExist $_) {
throw BaseWorkspaceDoesNotExist::butWasSupposedTo($workspace->workspaceName);
Expand All @@ -951,7 +951,7 @@ private function requireNonCircularRelationBetweenWorkspaces(Workspace $workspac
if ($workspace->workspaceName->equals($nextBaseWorkspace->baseWorkspaceName)) {
throw new CircularRelationBetweenWorkspacesException(sprintf('The workspace "%s" is already on the path of the target workspace "%s".', $workspace->workspaceName->value, $baseWorkspace->workspaceName->value));
}
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($nextBaseWorkspace->baseWorkspaceName);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromWorkspaceName($nextBaseWorkspace->baseWorkspaceName);
$nextBaseWorkspace = $contentGraphAdapter->getWorkspace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ public function findNodeAggregateById(
NodeAggregateId $nodeAggregateId
): ?NodeAggregate;

/**
* @param ContentStreamId $contentStreamId
* @param NodeAggregateId $childNodeAggregateId
* @return iterable<NodeAggregate>
*/
public function findParentNodeAggregates(
ContentStreamId $contentStreamId,
NodeAggregateId $childNodeAggregateId
): iterable;

/**
* @param ContentStreamId $contentStreamId
* @param NodeAggregateId $parentNodeAggregateId
* @param NodeName $name
* @return iterable<NodeAggregate>
*/
public function findChildNodeAggregatesByName(
ContentStreamId $contentStreamId,
NodeAggregateId $parentNodeAggregateId,
NodeName $name
): iterable;

/**
* Returns all node types in use, from the graph projection
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat

foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) {
// TODO: We should use $nodeAggregate->workspaceName as soon as it's available
$contentGraphAdapter = $this->contentGraphAdapterProvider->resolveWorkspaceNameAndGet($nodeAggregate->contentStreamId);
$contentGraphAdapter = $this->contentGraphAdapterProvider->fromContentStreamId($nodeAggregate->contentStreamId);
// find missing tethered nodes
$foundMissingOrDisallowedTetheredNodes = false;
$originDimensionSpacePoints = $nodeType->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME)
Expand Down Expand Up @@ -270,6 +270,6 @@ private function reorderNodes(

protected function getContentGraphAdapter(WorkspaceName $workspaceName): ContentGraphAdapterInterface
{
return $this->contentGraphAdapterProvider->resolveContentStreamIdAndGet($workspaceName);
return $this->contentGraphAdapterProvider->fromWorkspaceName($workspaceName);
}
}

0 comments on commit 6d501b2

Please sign in to comment.