Skip to content

Commit

Permalink
WIP: VirtualWorkspaceName
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Oct 19, 2024
1 parent ef2d459 commit a13da1f
Show file tree
Hide file tree
Showing 55 changed files with 320 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand Down Expand Up @@ -73,7 +74,7 @@ public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraph
return $this->buildForWorkspaceAndContentStream($workspaceName, ContentStreamId::fromString($currentContentStreamId));
}

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraph
public function buildForWorkspaceAndContentStream(WorkspaceName|VirtualWorkspaceName $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 @@ -37,6 +37,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ public function __construct(
private readonly ContentRepositoryId $contentRepositoryId,
private readonly NodeTypeManager $nodeTypeManager,
private readonly ContentGraphTableNames $tableNames,
public readonly WorkspaceName $workspaceName,
public readonly WorkspaceName|VirtualWorkspaceName $workspaceName,
public readonly ContentStreamId $contentStreamId
) {
$this->nodeQueryBuilder = new NodeQueryBuilder($this->dbal, $this->tableNames);
Expand All @@ -81,7 +82,7 @@ public function getContentRepositoryId(): ContentRepositoryId
return $this->contentRepositoryId;
}

public function getWorkspaceName(): WorkspaceName
public function getWorkspaceName(): WorkspaceName|VirtualWorkspaceName
{
return $this->workspaceName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand Down Expand Up @@ -90,7 +91,7 @@ final class ContentSubgraph implements ContentSubgraphInterface

public function __construct(
private readonly ContentRepositoryId $contentRepositoryId,
private readonly WorkspaceName $workspaceName,
private readonly WorkspaceName|VirtualWorkspaceName $workspaceName,
private readonly ContentStreamId $contentStreamId,
private readonly DimensionSpacePoint $dimensionSpacePoint,
private readonly VisibilityConstraints $visibilityConstraints,
Expand All @@ -107,7 +108,7 @@ public function getContentRepositoryId(): ContentRepositoryId
return $this->contentRepositoryId;
}

public function getWorkspaceName(): WorkspaceName
public function getWorkspaceName(): WorkspaceName|VirtualWorkspaceName
{
return $this->workspaceName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Traversable;

Expand All @@ -63,7 +64,7 @@ public function __construct(
*/
public function mapNodeRowToNode(
array $nodeRow,
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): Node {
Expand Down Expand Up @@ -93,7 +94,7 @@ public function mapNodeRowToNode(
*/
public function mapNodeRowsToNodes(
array $nodeRows,
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): Nodes {
Expand All @@ -120,7 +121,7 @@ public function createPropertyCollectionFromJsonString(string $jsonString): Prop
*/
public function mapReferenceRowsToReferences(
array $nodeRows,
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
DimensionSpacePoint $dimensionSpacePoint,
VisibilityConstraints $visibilityConstraints
): References {
Expand Down Expand Up @@ -150,7 +151,7 @@ public function mapReferenceRowsToReferences(
*/
public function mapNodeRowsToNodeAggregate(
array $nodeRows,
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
VisibilityConstraints $visibilityConstraints
): ?NodeAggregate {
if (empty($nodeRows)) {
Expand Down Expand Up @@ -231,7 +232,7 @@ public function mapNodeRowsToNodeAggregate(
*/
public function mapNodeRowsToNodeAggregates(
array $nodeRows,
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
VisibilityConstraints $visibilityConstraints
): NodeAggregates {
if (empty($nodeRows)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Neos\ContentRepository\Core\Projection\Workspace\WorkspaceFinder;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand Down Expand Up @@ -59,8 +60,12 @@ public function getContentStreamFinder(): ContentStreamFinder
/**
* @throws WorkspaceDoesNotExist if the workspace does not exist
*/
public function getContentGraph(WorkspaceName $workspaceName): ContentGraphInterface
public function getContentGraph(WorkspaceName|VirtualWorkspaceName $workspaceName): ContentGraphInterface
{
if ($workspaceName instanceof VirtualWorkspaceName) {
return $this->contentRepository->projectionState(ContentGraphFinder::class)->getByWorkspaceNameAndContentStreamId($workspaceName, $workspaceName->contentStreamId);
}

if (isset($this->overridenContentGraphInstances[$workspaceName->value])) {
return $this->overridenContentGraphInstances[$workspaceName->value];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -31,5 +32,5 @@ interface ContentGraphFactoryInterface
*/
public function buildForWorkspace(WorkspaceName $workspaceName): ContentGraphInterface;

public function buildForWorkspaceAndContentStream(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface;
public function buildForWorkspaceAndContentStream(WorkspaceName|VirtualWorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface;
}
10 changes: 7 additions & 3 deletions Neos.ContentRepository.Core/Classes/ContentGraphFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\ContentRepository\Core\Projection\ProjectionStateInterface;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -42,19 +43,22 @@ public function __construct(
* @throws WorkspaceDoesNotExist if the provided workspace does not resolve to an existing content stream
* @see ContentRepository::getContentGraph()
*/
public function getByWorkspaceName(WorkspaceName $workspaceName): ContentGraphInterface
public function getByWorkspaceName(WorkspaceName|VirtualWorkspaceName $workspaceName): ContentGraphInterface
{
if ($workspaceName instanceof VirtualWorkspaceName) {
return $this->getByWorkspaceNameAndContentStreamId($workspaceName, $workspaceName->contentStreamId);
}
return $this->contentGraphFactory->buildForWorkspace($workspaceName);
}

/**
* For testing we allow getting an instance set by both parameters, effectively overriding the relationship at will
*
* @param WorkspaceName $workspaceName
* @param WorkspaceName|VirtualWorkspaceName $workspaceName
* @param ContentStreamId $contentStreamId
* @internal Only for the write side during publishing {@see \Neos\ContentRepository\Core\CommandHandlingDependencies::overrideContentStreamId}
*/
public function getByWorkspaceNameAndContentStreamId(WorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface
public function getByWorkspaceNameAndContentStreamId(WorkspaceName|VirtualWorkspaceName $workspaceName, ContentStreamId $contentStreamId): ContentGraphInterface
{
return $this->contentGraphFactory->buildForWorkspaceAndContentStream($workspaceName, $contentStreamId);
}
Expand Down
3 changes: 2 additions & 1 deletion Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryStatus;
use Neos\ContentRepository\Core\SharedModel\Exception\WorkspaceDoesNotExist;
use Neos\ContentRepository\Core\SharedModel\User\UserIdProviderInterface;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\EventStore\EventStoreInterface;
use Neos\EventStore\Model\Event\EventMetadata;
Expand Down Expand Up @@ -239,7 +240,7 @@ public function resetProjectionState(string $projectionClassName): void
/**
* @throws WorkspaceDoesNotExist if the workspace does not exist
*/
public function getContentGraph(WorkspaceName $workspaceName): ContentGraphInterface
public function getContentGraph(WorkspaceName|VirtualWorkspaceName $workspaceName): ContentGraphInterface
{
return $this->projectionState(ContentGraphFinder::class)->getByWorkspaceName($workspaceName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamState;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\EventStore\Model\EventStream\ExpectedVersion;

Expand All @@ -77,9 +78,15 @@ abstract protected function getAllowedDimensionSubspace(): DimensionSpacePointSe
* @throws ContentStreamDoesNotExistYet
*/
protected function requireContentStream(
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
CommandHandlingDependencies $commandHandlingDependencies
): ContentStreamId {
if ($workspaceName instanceof VirtualWorkspaceName) {
$state = $commandHandlingDependencies->getContentStreamFinder()->findStateForContentStream($workspaceName->contentStreamId);
if ($state !== null) {
return $workspaceName->contentStreamId;
}
}
$contentStreamId = $commandHandlingDependencies->getContentGraph($workspaceName)->getContentStreamId();
$state = $commandHandlingDependencies->getContentStreamFinder()->findStateForContentStream($contentStreamId);
if ($state === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\ContentRepository\Core\Feature\Common;

use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -25,5 +26,5 @@
*/
interface EmbedsWorkspaceName
{
public function getWorkspaceName(): WorkspaceName;
public function getWorkspaceName(): WorkspaceName|VirtualWorkspaceName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Neos\ContentRepository\Core\Feature\Common;

use Neos\ContentRepository\Core\CommandHandler\CommandInterface;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -28,7 +29,7 @@
interface RebasableToOtherWorkspaceInterface
{
public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
WorkspaceName|VirtualWorkspaceName $targetWorkspaceName,
): CommandInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\Common\RebasableToOtherWorkspaceInterface;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -39,24 +40,24 @@
RebasableToOtherWorkspaceInterface
{
/**
* @param WorkspaceName $workspaceName The name of the workspace to perform the operation in.
* @param WorkspaceName|VirtualWorkspaceName $workspaceName The name of the workspace to perform the operation in.
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
private function __construct(
public WorkspaceName $workspaceName,
public WorkspaceName|VirtualWorkspaceName $workspaceName,
public DimensionSpacePoint $source,
public DimensionSpacePoint $target
) {
}

/**
* @param WorkspaceName $workspaceName The name of the workspace to perform the operation in
* @param WorkspaceName|VirtualWorkspaceName $workspaceName The name of the workspace to perform the operation in
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
public static function create(
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
DimensionSpacePoint $source,
DimensionSpacePoint $target
): self {
Expand All @@ -75,7 +76,7 @@ public static function fromArray(array $array): self
);
}

public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName): self
public function createCopyForWorkspace(WorkspaceName|VirtualWorkspaceName $targetWorkspaceName): self
{
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\ContentRepository\Core\CommandHandler\CommandInterface;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\Common\RebasableToOtherWorkspaceInterface;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -34,24 +35,24 @@
RebasableToOtherWorkspaceInterface
{
/**
* @param WorkspaceName $workspaceName The name of the workspace to perform the operation in.
* @param WorkspaceName|VirtualWorkspaceName $workspaceName The name of the workspace to perform the operation in.
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
private function __construct(
public WorkspaceName $workspaceName,
public WorkspaceName|VirtualWorkspaceName $workspaceName,
public DimensionSpacePoint $source,
public DimensionSpacePoint $target,
) {
}

/**
* @param WorkspaceName $workspaceName The name of the workspace to perform the operation in
* @param WorkspaceName|VirtualWorkspaceName $workspaceName The name of the workspace to perform the operation in
* @param DimensionSpacePoint $source source dimension space point
* @param DimensionSpacePoint $target target dimension space point
*/
public static function create(
WorkspaceName $workspaceName,
WorkspaceName|VirtualWorkspaceName $workspaceName,
DimensionSpacePoint $source,
DimensionSpacePoint $target
): self {
Expand All @@ -71,7 +72,7 @@ public static function fromArray(array $array): self
}

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
WorkspaceName|VirtualWorkspaceName $targetWorkspaceName,
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Neos\ContentRepository\Core\Feature\Common\EmbedsWorkspaceName;
use Neos\ContentRepository\Core\Feature\Common\PublishableToWorkspaceInterface;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\VirtualWorkspaceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -38,7 +39,7 @@
final readonly class DimensionShineThroughWasAdded implements EventInterface, PublishableToWorkspaceInterface, EmbedsContentStreamId, EmbedsWorkspaceName
{
public function __construct(
public WorkspaceName $workspaceName,
public WorkspaceName|VirtualWorkspaceName $workspaceName,
public ContentStreamId $contentStreamId,
public DimensionSpacePoint $source,
public DimensionSpacePoint $target
Expand All @@ -50,12 +51,12 @@ public function getContentStreamId(): ContentStreamId
return $this->contentStreamId;
}

public function getWorkspaceName(): WorkspaceName
public function getWorkspaceName(): WorkspaceName|VirtualWorkspaceName
{
return $this->workspaceName;
}

public function withWorkspaceNameAndContentStreamId(WorkspaceName $targetWorkspaceName, ContentStreamId $contentStreamId): self
public function withWorkspaceNameAndContentStreamId(WorkspaceName|VirtualWorkspaceName $targetWorkspaceName, ContentStreamId $contentStreamId): self
{
return new self(
$targetWorkspaceName,
Expand Down
Loading

0 comments on commit a13da1f

Please sign in to comment.