Skip to content

Commit

Permalink
Introduce ContentGraphAdapterProviderInterface
Browse files Browse the repository at this point in the history
This also replaces the ContentStreamIdOverride
  • Loading branch information
kitsunet committed Apr 7, 2024
1 parent 606a85b commit c7480fe
Show file tree
Hide file tree
Showing 29 changed files with 427 additions and 607 deletions.
Expand Up @@ -18,8 +18,19 @@ public function __construct(
) {
}

public function get(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphAdapterInterface
public function resolveWorkspaceNameAndGet(ContentStreamId $contentStreamId): ContentGraphAdapterInterface
{
return new ContentGraphAdapter($this->dbalConnection, $this->tableNamePrefix, $contentStreamId, $workspaceName);
// TODO: Implement resolveWorkspaceNameAndGet() method.
}

public function resolveContentStreamIdAndGet(WorkspaceName $workspaceName): ContentGraphAdapterInterface
{
// TODO: Implement resolveContentStreamIdAndGet() method.
}

public function overrideContentStreamId(WorkspaceName $workspaceName, ContentStreamId $contentStreamId, \Closure $fn): void
{
// TODO: Implement overrideContentStreamId() method.
}

}
Expand Up @@ -127,6 +127,7 @@ public function buildService(
$this->getOrBuild(),
$this->buildEventPersister(),
$this->projectionsAndCatchUpHooks->projections,
$this->contentGraphAdapterProvider
);
return $serviceFactory->build($serviceFactoryDependencies);
}
Expand Down Expand Up @@ -159,7 +160,8 @@ private function buildCommandBus(): CommandBus
new NodeDuplicationCommandHandler(
$this->projectionFactoryDependencies->nodeTypeManager,
$this->projectionFactoryDependencies->contentDimensionZookeeper,
$this->projectionFactoryDependencies->interDimensionalVariationGraph
$this->projectionFactoryDependencies->interDimensionalVariationGraph,
$this->contentGraphAdapterProvider
)
);
}
Expand Down
Expand Up @@ -20,6 +20,7 @@
use Neos\ContentRepository\Core\DimensionSpace\InterDimensionalVariationGraph;
use Neos\ContentRepository\Core\EventStore\EventNormalizer;
use Neos\ContentRepository\Core\EventStore\EventPersister;
use Neos\ContentRepository\Core\Feature\ContentGraphAdapterProviderInterface;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\Projections;
Expand Down Expand Up @@ -47,6 +48,7 @@ private function __construct(
// we don't need CommandBus, because this is included in ContentRepository->handle()
public EventPersister $eventPersister,
public Projections $projections,
public ContentGraphAdapterProviderInterface $contentGraphAdapterProvider
) {
}

Expand All @@ -58,6 +60,7 @@ public static function create(
ContentRepository $contentRepository,
EventPersister $eventPersister,
Projections $projections,
ContentGraphAdapterProviderInterface $contentGraphAdapterProvider
): self {
return new self(
$projectionFactoryDependencies->contentRepositoryId,
Expand All @@ -71,6 +74,7 @@ public static function create(
$contentRepository,
$eventPersister,
$projections,
$contentGraphAdapterProvider
);
}
}
Expand Up @@ -14,7 +14,6 @@

namespace Neos\ContentRepository\Core\Feature\Common;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\DimensionSpace\Exception\DimensionSpacePointNotFound;
Expand Down Expand Up @@ -67,30 +66,29 @@ abstract protected function getNodeTypeManager(): NodeTypeManager;

abstract protected function getAllowedDimensionSubspace(): DimensionSpacePointSet;

abstract protected function getContentGraphAdapter(): ContentGraphAdapterInterface;
abstract protected function getContentGraphAdapter(WorkspaceName $workspaceName): ContentGraphAdapterInterface;

/**
* @throws ContentStreamDoesNotExistYet
*/
protected function requireContentStream(
WorkspaceName $workspaceName
): ContentStreamId {
$contentGraphAdapter = $this->getContentGraphAdapter();
$contentStreamId = ContentStreamIdOverride::resolveContentStreamIdForWorkspace($contentGraphAdapter, $workspaceName);
if (!$contentGraphAdapter->hasContentStream($contentStreamId)) {
$contentGraphAdapter = $this->getContentGraphAdapter($workspaceName);
if (!$contentGraphAdapter->hasContentStream()) {
throw new ContentStreamDoesNotExistYet(
'Content stream "' . $contentStreamId->value . '" does not exist yet.',
'Content stream "' . $contentGraphAdapter->getContentStreamId()->value . '" does not exist yet.',
1521386692
);
}
if ($contentGraphAdapter->findStateForContentStream($contentStreamId) === ContentStreamState::STATE_CLOSED) {
if ($contentGraphAdapter->findStateForContentStream() === ContentStreamState::STATE_CLOSED) {
throw new ContentStreamIsClosed(
'Content stream "' . $contentStreamId->value . '" is closed.',
'Content stream "' . $contentGraphAdapter->getContentStreamId()->value . '" is closed.',
1710260081
);
}

return $contentStreamId;
return $contentGraphAdapter->getContentStreamId();
}

/**
Expand Down Expand Up @@ -150,11 +148,10 @@ protected function requireNodeTypeToNotBeOfTypeRoot(NodeType $nodeType): void
}

protected function requireRootNodeTypeToBeUnoccupied(
NodeTypeName $nodeTypeName,
ContentStreamId $contentStreamId
ContentGraphAdapterInterface $contentGraphAdapter,
NodeTypeName $nodeTypeName
): void {
$rootNodeAggregateExists = $this->getContentGraphAdapter()->rootNodeAggregateWithTypeExists(
$contentStreamId,
$rootNodeAggregateExists = $contentGraphAdapter->rootNodeAggregateWithTypeExists(
$nodeTypeName
);

Expand Down Expand Up @@ -237,21 +234,21 @@ protected function requireNodeTypeToAllowNodesOfTypeInReference(
/**
* NodeType and NodeName must belong together to the same node, which is the to-be-checked one.
*
* @param ContentStreamId $contentStreamId
* @param ContentGraphAdapterInterface $contentGraphAdapter
* @param NodeType $nodeType
* @param NodeName|null $nodeName
* @param array|NodeAggregateId[] $parentNodeAggregateIds
* @throws NodeConstraintException
*/
protected function requireConstraintsImposedByAncestorsAreMet(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
NodeType $nodeType,
?NodeName $nodeName,
array $parentNodeAggregateIds
): void {
foreach ($parentNodeAggregateIds as $parentNodeAggregateId) {
$parentAggregate = $this->requireProjectedNodeAggregate(
$contentStreamId,
$contentGraphAdapter,
$parentNodeAggregateId
);
if (!$parentAggregate->classification->isTethered()) {
Expand All @@ -264,11 +261,8 @@ protected function requireConstraintsImposedByAncestorsAreMet(
}
}

$workspace = $this->getContentGraphAdapter()->findWorkspaceByCurrentContentStreamId($contentStreamId);
foreach (
$this->getContentGraphAdapter()->findParentNodeAggregates(
$contentStreamId,
$workspace?->workspaceName,
$contentGraphAdapter->findParentNodeAggregates(
$parentNodeAggregateId
) as $grandParentNodeAggregate
) {
Expand Down Expand Up @@ -382,13 +376,10 @@ protected function areNodeTypeConstraintsImposedByGrandparentValid(
* @throws NodeAggregateCurrentlyDoesNotExist
*/
protected function requireProjectedNodeAggregate(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
NodeAggregateId $nodeAggregateId
): NodeAggregate {
$workspace = $this->getContentGraphAdapter()->findWorkspaceByCurrentContentStreamId($contentStreamId);
$nodeAggregate = $this->getContentGraphAdapter()->findNodeAggregateById(
$contentStreamId,
$workspace?->workspaceName,
$nodeAggregate = $contentGraphAdapter->findNodeAggregateById(
$nodeAggregateId
);

Expand All @@ -407,13 +398,10 @@ protected function requireProjectedNodeAggregate(
* @throws NodeAggregateCurrentlyExists
*/
protected function requireProjectedNodeAggregateToNotExist(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
NodeAggregateId $nodeAggregateId
): void {
$workspace = $this->getContentGraphAdapter()->findWorkspaceByCurrentContentStreamId($contentStreamId);
$nodeAggregate = $this->getContentGraphAdapter()->findNodeAggregateById(
$contentStreamId,
$workspace?->workspaceName,
$nodeAggregate = $contentGraphAdapter->findNodeAggregateById(
$nodeAggregateId
);

Expand All @@ -429,15 +417,12 @@ protected function requireProjectedNodeAggregateToNotExist(
* @throws NodeAggregateCurrentlyDoesNotExist
*/
public function requireProjectedParentNodeAggregate(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
NodeAggregateId $childNodeAggregateId,
OriginDimensionSpacePoint $childOriginDimensionSpacePoint
): NodeAggregate {
$workspace = $this->getContentGraphAdapter()->findWorkspaceByCurrentContentStreamId($contentStreamId);
$parentNodeAggregate = $this->getContentGraphAdapter()
$parentNodeAggregate = $contentGraphAdapter
->findParentNodeAggregateByChildOriginDimensionSpacePoint(
$contentStreamId,
$workspace?->workspaceName,
$childNodeAggregateId,
$childOriginDimensionSpacePoint
);
Expand All @@ -446,7 +431,7 @@ public function requireProjectedParentNodeAggregate(
throw new NodeAggregateCurrentlyDoesNotExist(
'Parent node aggregate for ' . $childNodeAggregateId->value
. ' does currently not exist in origin dimension space point ' . $childOriginDimensionSpacePoint->toJson()
. ' and content stream ' . $contentStreamId->value,
. ' and workspace ' . $contentGraphAdapter->getWorkspaceName()->value,
1645368685
);
}
Expand All @@ -465,7 +450,7 @@ protected function requireNodeAggregateToCoverDimensionSpacePoint(
throw new NodeAggregateDoesCurrentlyNotCoverDimensionSpacePoint(
'Node aggregate "' . $nodeAggregate->nodeAggregateId->value
. '" does currently not cover dimension space point '
. json_encode($dimensionSpacePoint) . '.',
. json_encode($dimensionSpacePoint, JSON_THROW_ON_ERROR) . '.',
1541678877
);
}
Expand Down Expand Up @@ -517,7 +502,7 @@ protected function requireNodeAggregateToBeUntethered(NodeAggregate $nodeAggrega
* @throws NodeAggregateIsDescendant
*/
protected function requireNodeAggregateToNotBeDescendant(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
NodeAggregate $nodeAggregate,
NodeAggregate $referenceNodeAggregate
): void {
Expand All @@ -528,16 +513,13 @@ protected function requireNodeAggregateToNotBeDescendant(
1554971124
);
}
$workspace = $this->getContentGraphAdapter()->findWorkspaceByCurrentContentStreamId($contentStreamId);
foreach (
$this->getContentGraphAdapter()->findChildNodeAggregates(
$contentStreamId,
$workspace?->workspaceName,
$contentGraphAdapter->findChildNodeAggregates(
$referenceNodeAggregate->nodeAggregateId
) as $childReferenceNodeAggregate
) {
$this->requireNodeAggregateToNotBeDescendant(
$contentStreamId,
$contentGraphAdapter,
$nodeAggregate,
$childReferenceNodeAggregate
);
Expand All @@ -548,7 +530,7 @@ protected function requireNodeAggregateToNotBeDescendant(
* @throws NodeNameIsAlreadyOccupied
*/
protected function requireNodeNameToBeUnoccupied(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
?NodeName $nodeName,
NodeAggregateId $parentNodeAggregateId,
OriginDimensionSpacePoint $parentOriginDimensionSpacePoint,
Expand All @@ -557,9 +539,8 @@ protected function requireNodeNameToBeUnoccupied(
if ($nodeName === null) {
return;
}
$dimensionSpacePointsOccupiedByChildNodeName = $this->getContentGraphAdapter()
$dimensionSpacePointsOccupiedByChildNodeName = $contentGraphAdapter
->getDimensionSpacePointsOccupiedByChildNodeName(
$contentStreamId,
$nodeName,
$parentNodeAggregateId,
$parentOriginDimensionSpacePoint,
Expand All @@ -578,19 +559,16 @@ protected function requireNodeNameToBeUnoccupied(
* @throws NodeNameIsAlreadyCovered
*/
protected function requireNodeNameToBeUncovered(
ContentStreamId $contentStreamId,
ContentGraphAdapterInterface $contentGraphAdapter,
?NodeName $nodeName,
NodeAggregateId $parentNodeAggregateId,
DimensionSpacePointSet $dimensionSpacePointsToBeCovered
): void {
if ($nodeName === null) {
return;
}
$workspace = $this->getContentGraphAdapter()->findWorkspaceByCurrentContentStreamId($contentStreamId);

$childNodeAggregates = $this->getContentGraphAdapter()->findChildNodeAggregatesByName(
$contentStreamId,
$workspace?->workspaceName,
$childNodeAggregates = $contentGraphAdapter->findChildNodeAggregatesByName(
$parentNodeAggregateId,
$nodeName
);
Expand All @@ -617,7 +595,7 @@ protected function requireNodeAggregateToOccupyDimensionSpacePoint(
): void {
if (!$nodeAggregate->occupiesDimensionSpacePoint($originDimensionSpacePoint)) {
throw new DimensionSpacePointIsNotYetOccupied(
'Dimension space point ' . json_encode($originDimensionSpacePoint)
'Dimension space point ' . json_encode($originDimensionSpacePoint, JSON_THROW_ON_ERROR)
. ' is not yet occupied by node aggregate "' . $nodeAggregate->nodeAggregateId->value . '"',
1552595396
);
Expand All @@ -633,7 +611,7 @@ protected function requireNodeAggregateToNotOccupyDimensionSpacePoint(
): void {
if ($nodeAggregate->occupiesDimensionSpacePoint($originDimensionSpacePoint)) {
throw new DimensionSpacePointIsAlreadyOccupied(
'Dimension space point ' . json_encode($originDimensionSpacePoint)
'Dimension space point ' . json_encode($originDimensionSpacePoint, JSON_THROW_ON_ERROR)
. ' is already occupied by node aggregate "' . $nodeAggregate->nodeAggregateId->value . '"',
1552595441
);
Expand Down Expand Up @@ -676,10 +654,10 @@ protected function validateReferenceProperties(
}

protected function getExpectedVersionOfContentStream(
ContentStreamId $contentStreamId
ContentGraphAdapterInterface $contentGraphAdapter
): ExpectedVersion {
return ExpectedVersion::fromVersion(
$this->getContentGraphAdapter()->findVersionForContentStream($contentStreamId)->unwrap()
$contentGraphAdapter->findVersionForContentStream()->unwrap()
);
}
}

0 comments on commit c7480fe

Please sign in to comment.