Skip to content

Commit

Permalink
FEATURE: WorkspaceName with reference for unused contentStream
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jun 28, 2024
1 parent f197380 commit b741580
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function overrideContentStreamId(WorkspaceName $workspaceName, ContentStr
throw new \RuntimeException('Contentstream override for this workspace already in effect, nesting not allowed.', 1715170938);
}

$contentGraph = $this->contentRepository->projectionState(ContentGraphFinder::class)->getByWorkspaceNameAndContentStreamId($workspaceName, $contentStreamId);
$contentGraph = $this->contentRepository->getContentGraph(WorkspaceName::createReferenceForUnusedContentStream($contentStreamId));
$this->overridenContentGraphInstances[$workspaceName->value] = $contentGraph;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -30,6 +29,4 @@ interface ContentGraphFactoryInterface
* @throws WorkspaceDoesNotExist if the workspace does not exist
*/
public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraphInterface;

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface;
}
12 changes: 0 additions & 12 deletions Neos.ContentRepository.Core/Classes/ContentGraphFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,4 @@ public function forgetInstances(): void
{
$this->contentGraphInstances = [];
}

/**
* For testing we allow getting an instance set by both parameters, effectively overriding the relationship at will
*
* @param WorkspaceName $workspaceName
* @param ContentStreamId $contentStreamId
* @internal Only for testing
*/
public function getByWorkspaceNameAndContentStreamId(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface
{
return $this->contentGraphFactory->buildForWorkspaceAndContentStream($workspaceName, $contentStreamId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public static function fromString(string $value): self
return self::instance($value);
}

public static function createReferenceForUnusedContentStream(ContentStreamId $contentStreamId): self
{
return self::instance('cs:' . $contentStreamId->value);
}

public static function forLive(): self
{
return self::instance(self::WORKSPACE_NAME_LIVE);
Expand Down Expand Up @@ -92,6 +97,19 @@ public function isLive(): bool
return $this->value === self::WORKSPACE_NAME_LIVE;
}

/**
* @phpstan-assert-if-true ContentStreamId $this->getReferencingUnusedContentStreamId()
*/
public function isReferencingUnusedContentStream(): bool
{
return str_starts_with($this->value, 'cs:');
}

public function getReferencingUnusedContentStreamId(): ?ContentStreamId
{
return $this->isReferencingUnusedContentStream() ? ContentStreamId::fromString(substr($this->value, 3)) : null;
}

public function jsonSerialize(): string
{
return $this->value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ trait CRTestSuiteRuntimeVariables
{
protected ?ContentRepository $currentContentRepository = null;

protected ?ContentStreamId $currentContentStreamId = null;

protected ?WorkspaceName $currentWorkspaceName = null;

protected ?DimensionSpacePoint $currentDimensionSpacePoint = null;
Expand Down Expand Up @@ -92,7 +90,7 @@ public function theCurrentDateAndTimeIs(string $timestamp): void
*/
public function iAmInContentStream(string $contentStreamId): void
{
$this->currentContentStreamId = ContentStreamId::fromString($contentStreamId);
$this->currentWorkspaceName = WorkspaceName::createReferenceForUnusedContentStream(ContentStreamId::fromString($contentStreamId));
}

/**
Expand All @@ -101,7 +99,6 @@ public function iAmInContentStream(string $contentStreamId): void
public function iAmInWorkspace(string $workspaceName): void
{
$this->currentWorkspaceName = WorkspaceName::fromString($workspaceName);
$this->currentContentStreamId = null;
}

/**
Expand Down Expand Up @@ -147,11 +144,6 @@ public function getCurrentSubgraph(): ContentSubgraphInterface
{
$contentGraphFinder = $this->currentContentRepository->projectionState(ContentGraphFinder::class);
$contentGraphFinder->forgetInstances();
if (isset($this->currentContentStreamId)) {
// This must still be supported for low level tests, e.g. for content stream forking
return $contentGraphFinder->getByWorkspaceNameAndContentStreamId($this->currentWorkspaceName, $this->currentContentStreamId)->getSubgraph($this->currentDimensionSpacePoint, $this->currentVisibilityConstraints);
}

return $contentGraphFinder->getByWorkspaceName($this->currentWorkspaceName)->getSubgraph(
$this->currentDimensionSpacePoint,
$this->currentVisibilityConstraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function beforeEventSourcedScenarioDispatcher(BeforeScenarioScope $scope)
$this->currentVisibilityConstraints = VisibilityConstraints::frontend();
$this->currentDimensionSpacePoint = null;
$this->currentRootNodeAggregateId = null;
$this->currentContentStreamId = null;
$this->currentWorkspaceName = null;
$this->currentNodeAggregate = null;
$this->currentNode = null;
Expand Down

0 comments on commit b741580

Please sign in to comment.