Skip to content

Commit

Permalink
4942 - refactor global transformation commands to also work with work…
Browse files Browse the repository at this point in the history
…spaces
  • Loading branch information
Bernhard Schmitt committed Apr 4, 2024
1 parent 04fae33 commit 1dc8c01
Show file tree
Hide file tree
Showing 26 changed files with 49 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Neos\ContentRepository\Core\Feature\Common;

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

/**
Expand All @@ -30,7 +29,6 @@ interface RebasableToOtherWorkspaceInterface
{
public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): CommandInterface;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* basically making all content available not just in the source(original) DSP,
* but also in the target-DimensionSpacePoint.
*
* NOTE: the Source Dimension Space Point must be a parent of the target Dimension Space Point.
* NOTE: the Source Dimension Space Point must be a generalization of the target Dimension Space Point.
*
* This is needed if "de" exists, and you want to create a "de_CH" specialization.
*
Expand All @@ -39,27 +39,28 @@
RebasableToOtherWorkspaceInterface
{
/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in.
* This content stream is specifically created for this operation and thus not prone to conflicts,
* thus we don't need the workspace name
* @param WorkspaceName $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 ContentStreamId $contentStreamId,
public WorkspaceName $workspaceName,
public DimensionSpacePoint $source,
public DimensionSpacePoint $target
) {
}

/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in
* @param WorkspaceName $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(ContentStreamId $contentStreamId, DimensionSpacePoint $source, DimensionSpacePoint $target): self
{
return new self($contentStreamId, $source, $target);
public static function create(
WorkspaceName $workspaceName,
DimensionSpacePoint $source,
DimensionSpacePoint $target
): self {
return new self($workspaceName, $source, $target);
}

/**
Expand All @@ -68,16 +69,16 @@ public static function create(ContentStreamId $contentStreamId, DimensionSpacePo
public static function fromArray(array $array): self
{
return new self(
ContentStreamId::fromString($array['contentStreamId']),
WorkspaceName::fromString($array['workspaceName']),
DimensionSpacePoint::fromArray($array['source']),
DimensionSpacePoint::fromArray($array['target'])
);
}

public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName, ContentStreamId $targetContentStreamId): self
public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName): self
{
return new self(
$targetContentStreamId,
$targetWorkspaceName,
$this->source,
$this->target
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
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\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
Expand All @@ -35,27 +34,28 @@
RebasableToOtherWorkspaceInterface
{
/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in.
* This content stream is specifically created for this operation and thus not prone to conflicts,
* thus we don't need the workspace name
* @param WorkspaceName $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 ContentStreamId $contentStreamId,
public WorkspaceName $workspaceName,
public DimensionSpacePoint $source,
public DimensionSpacePoint $target
public DimensionSpacePoint $target,
) {
}

/**
* @param ContentStreamId $contentStreamId The id of the content stream to perform the operation in
* @param WorkspaceName $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(ContentStreamId $contentStreamId, DimensionSpacePoint $source, DimensionSpacePoint $target): self
{
return new self($contentStreamId, $source, $target);
public static function create(
WorkspaceName $workspaceName,
DimensionSpacePoint $source,
DimensionSpacePoint $target
): self {
return new self($workspaceName, $source, $target);
}

/**
Expand All @@ -64,18 +64,17 @@ public static function create(ContentStreamId $contentStreamId, DimensionSpacePo
public static function fromArray(array $array): self
{
return new self(
ContentStreamId::fromString($array['contentStreamId']),
WorkspaceName::fromString($array['workspaceName']),
DimensionSpacePoint::fromArray($array['source']),
DimensionSpacePoint::fromArray($array['target'])
);
}

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetContentStreamId,
$targetWorkspaceName,
$this->source,
$this->target
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ private function handleMoveDimensionSpacePoint(
MoveDimensionSpacePoint $command,
ContentRepository $contentRepository
): EventsToPublish {
$this->requireContentStream($command->contentStreamId, $contentRepository);
$streamName = ContentStreamEventStreamName::fromContentStreamId($command->contentStreamId)
$contentStreamId = $this->requireContentStreamForWorkspaceName($command->workspaceName, $contentRepository);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentStreamId)
->getEventStreamName();

self::requireDimensionSpacePointToBeEmptyInContentStream(
$command->target,
$command->contentStreamId,
$contentStreamId,
$contentRepository->getContentGraph()
);
$this->requireDimensionSpacePointToExistInConfiguration($command->target);
$this->requireDimensionSpacePointToExist($command->target);

return new EventsToPublish(
$streamName,
Events::with(
new DimensionSpacePointWasMoved(
$command->contentStreamId,
$contentStreamId,
$command->source,
$command->target
),
Expand All @@ -95,24 +95,24 @@ private function handleAddDimensionShineThrough(
AddDimensionShineThrough $command,
ContentRepository $contentRepository
): EventsToPublish {
$this->requireContentStream($command->contentStreamId, $contentRepository);
$streamName = ContentStreamEventStreamName::fromContentStreamId($command->contentStreamId)
$contentStreamId = $this->requireContentStreamForWorkspaceName($command->workspaceName, $contentRepository);
$streamName = ContentStreamEventStreamName::fromContentStreamId($contentStreamId)
->getEventStreamName();

self::requireDimensionSpacePointToBeEmptyInContentStream(
$command->target,
$command->contentStreamId,
$contentStreamId,
$contentRepository->getContentGraph()
);
$this->requireDimensionSpacePointToExistInConfiguration($command->target);
$this->requireDimensionSpacePointToExist($command->target);

$this->requireDimensionSpacePointToBeSpecialization($command->target, $command->source);

return new EventsToPublish(
$streamName,
Events::with(
new DimensionShineThroughWasAdded(
$command->contentStreamId,
$contentStreamId,
$command->source,
$command->target
)
Expand All @@ -124,7 +124,7 @@ private function handleAddDimensionShineThrough(
/**
* @throws DimensionSpacePointNotFound
*/
protected function requireDimensionSpacePointToExistInConfiguration(DimensionSpacePoint $dimensionSpacePoint): void
protected function requireDimensionSpacePointToExist(DimensionSpacePoint $dimensionSpacePoint): void
{
$allowedDimensionSubspace = $this->contentDimensionZookeeper->getAllowedDimensionSubspace();
if (!$allowedDimensionSubspace->contains($dimensionSpacePoint)) {
Expand Down Expand Up @@ -183,19 +183,4 @@ protected function requireContentStreamForWorkspaceName(

return $contentStreamId;
}

/**
* @throws ContentStreamDoesNotExistYet
*/
protected function requireContentStream(
ContentStreamId $contentStreamId,
ContentRepository $contentRepository
): void {
if (!$contentRepository->getContentStreamFinder()->hasContentStream($contentStreamId)) {
throw new ContentStreamDoesNotExistYet(
'Content stream "' . $contentStreamId->value . '" does not exist yet.',
1521386692
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public function withNodeAggregateIdMapping(

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public function withTetheredDescendantNodeAggregateIds(NodeAggregateIdsByNodePat

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public function jsonSerialize(): array

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public function jsonSerialize(): array

public function createCopyForWorkspace(
WorkspaceName $targetWorkspaceName,
ContentStreamId $targetContentStreamId
): self {
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function fromArray(array $array): self
);
}

public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName, ContentStreamId $targetContentStreamId): self
public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName): self
{
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function fromArray(array $array): self
);
}

public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName, ContentStreamId $targetContentStreamId): self
public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName): self
{
return new self(
$targetWorkspaceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private function handlePublishIndividualNodesFromWorkspace(
// 4) using the new content stream, apply the matching commands
ContentStreamIdOverride::applyContentStreamIdToClosure(
$command->contentStreamIdForMatchingPart,
function () use ($matchingCommands, $contentRepository, $baseWorkspace, $command): void {
function () use ($matchingCommands, $contentRepository, $baseWorkspace): void {
foreach ($matchingCommands as $matchingCommand) {
if (!($matchingCommand instanceof RebasableToOtherWorkspaceInterface)) {
throw new \RuntimeException(
Expand All @@ -530,7 +530,6 @@ function () use ($matchingCommands, $contentRepository, $baseWorkspace, $command

$contentRepository->handle($matchingCommand->createCopyForWorkspace(
$baseWorkspace->workspaceName,
$command->contentStreamIdForMatchingPart
))->block();
}
}
Expand Down Expand Up @@ -656,7 +655,7 @@ private function handleDiscardIndividualNodesFromWorkspace(
try {
ContentStreamIdOverride::applyContentStreamIdToClosure(
$command->newContentStreamId,
function () use ($commandsToKeep, $contentRepository, $baseWorkspace, $command): void {
function () use ($commandsToKeep, $contentRepository, $baseWorkspace): void {
foreach ($commandsToKeep as $matchingCommand) {
if (!($matchingCommand instanceof RebasableToOtherWorkspaceInterface)) {
throw new \RuntimeException(
Expand All @@ -667,7 +666,6 @@ function () use ($commandsToKeep, $contentRepository, $baseWorkspace, $command):

$contentRepository->handle($matchingCommand->createCopyForWorkspace(
$baseWorkspace->workspaceName,
$command->newContentStreamId
))->block();
}
}
Expand Down
Loading

0 comments on commit 1dc8c01

Please sign in to comment.