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 8052772
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function __construct(

public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraph
{
if ($workspaceName->isReferencingUnusedContentStream()) {
return $this->buildForWorkspaceAndContentStream($workspaceName, $workspaceName->getReferencingUnusedContentStreamId());
}

// FIXME: Should be part of this projection, this is forbidden
$tableName = strtolower(sprintf(
'cr_%s_p_%s',
Expand Down Expand Up @@ -71,7 +75,7 @@ public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraph
return $this->buildForWorkspaceAndContentStream($workspaceName, ContentStreamId::fromString($currentContentStreamId));
}

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraph
private function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraph
{
return new ContentGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNames, $workspaceName, $contentStreamId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public function __construct(

public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraphInterface
{
if ($workspaceName->isReferencingUnusedContentStream()) {
return $this->buildForWorkspaceAndContentStream($workspaceName, $workspaceName->getReferencingUnusedContentStreamId());
}

// FIXME: Should be part of this projection, this is forbidden
$tableName = strtolower(sprintf(
'cr_%s_p_%s',
Expand All @@ -55,7 +59,7 @@ public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraphInt
return $this->buildForWorkspaceAndContentStream($workspaceName, ContentStreamId::fromString($row['currentcontentstreamid']));
}

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface
private function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface
{
return new ContentHyperGraph($this->dbal, $this->nodeFactory, $this->contentRepositoryId, $this->nodeTypeManager, $this->tableNamePrefix, $workspaceName, $contentStreamId);
}
Expand Down
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 8052772

Please sign in to comment.