Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Workspace aware commands events migration #4890

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Feature: Constraint checks on SetNodeReferences
| sourceNodeAggregateId | "source-nodandaise" |
| referenceName | "referenceProperty" |
| references | [{"target":"anthony-destinode"}] |
Then the last command should have thrown an exception of type "ContentStreamDoesNotExistYet" with code 1521386692
Then the last command should have thrown an exception of type "ContentStreamDoesNotExistYet" with code 1710407870

# checks for sourceNodeAggregateId
Scenario: Try to reference nodes in a non-existent node aggregate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ protected function requireContentStream(
WorkspaceName $workspaceName,
ContentRepository $contentRepository
): ContentStreamId {
$contentStreamId = ContentStreamIdOverride::$contentStreamIdToUse
?: $contentRepository->getWorkspaceFinder()->findOneByName($workspaceName)?->currentContentStreamId;
if (!$contentStreamId || !$contentRepository->getContentStreamFinder()->hasContentStream($contentStreamId)) {
$contentStreamId = ContentStreamIdOverride::findContentStreamIdForWorkspace($contentRepository, $workspaceName);
if (!$contentRepository->getContentStreamFinder()->hasContentStream($contentStreamId)) {
throw new ContentStreamDoesNotExistYet(
'Content stream "' . $contentStreamId?->value . '" does not exist yet.',
'Content stream "' . $contentStreamId->value . '" does not exist yet.',
1521386692
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

namespace Neos\ContentRepository\Core\Feature\Common;

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\SharedModel\Exception\ContentStreamDoesNotExistYet;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* @internal (slightly hacky) implementation details for the workspace command handler
Expand All @@ -24,13 +27,41 @@ class ContentStreamIdOverride
/**
* A content stream id that to use instead of the workspace one's {@see ConstraintChecks::requireContentStream()}
*/
public static ?ContentStreamId $contentStreamIdToUse = null;
private static ?ContentStreamId $contentStreamIdToUse = null;

/**
* @internal
*/
public static function useContentStreamId(?ContentStreamId $contentStreamIdToUse): void
public static function withContentStreamIdToUse(ContentStreamId $contentStreamIdToUse, \Closure $fn): void
ahaeslich marked this conversation as resolved.
Show resolved Hide resolved
{
if (self::$contentStreamIdToUse !== null) {
throw new \Exception('Recursive content stream override is not supported', 1710426945);
}
self::$contentStreamIdToUse = $contentStreamIdToUse;
try {
$fn();
} catch (\Throwable $th) {
self::$contentStreamIdToUse = null;
throw $th;
}
nezaniel marked this conversation as resolved.
Show resolved Hide resolved
self::$contentStreamIdToUse = null;
ahaeslich marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @internal
*/
public static function findContentStreamIdForWorkspace(ContentRepository $contentRepository, WorkspaceName $workspaceName): ContentStreamId
ahaeslich marked this conversation as resolved.
Show resolved Hide resolved
{
$contentStreamId = self::$contentStreamIdToUse
?: $contentRepository->getWorkspaceFinder()->findOneByName($workspaceName)?->currentContentStreamId;

if (!$contentStreamId) {
throw new ContentStreamDoesNotExistYet(
'Content stream for workspace "' . $workspaceName->value . '" does not exist yet.',
1710407870
);
}

return $contentStreamId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
$this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->originDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
$this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
$this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
);
return (
!is_null($targetNodeAggregateId)
&& $this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->targetDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
&& $targetNodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->originDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
$this->originDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public function jsonSerialize(): array

public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return $this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->dimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ public function jsonSerialize(): array

public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->sourceOriginDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
return ($this->sourceOriginDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
&& $this->sourceNodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
$this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public function jsonSerialize(): array

public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->workspaceName->equals($nodeIdToPublish->workspaceName)
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId);
}

public function createCopyForWorkspace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public static function fromArray(array $array): self

public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return $this->workspaceName === $nodeIdToPublish->workspaceName
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId);
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public function jsonSerialize(): array

public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return $this->workspaceName->equals($nodeIdToPublish->workspaceName)
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->targetOrigin->equals($nodeIdToPublish->dimensionSpacePoint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private function handleRebaseWorkspace(
// - extract the commands from the to-be-rebased content stream; and applies them on the new content stream
$originalCommands = $this->extractCommandsFromContentStreamMetadata($workspaceContentStreamName);
$rebaseStatistics = new WorkspaceRebaseStatistics();
$this->withContentStreamIdToUse(
ContentStreamIdOverride::withContentStreamIdToUse(
$command->rebasedContentStreamId,
function () use ($originalCommands, $contentRepository, $rebaseStatistics, $workspaceContentStreamName, $baseWorkspace): void {
foreach ($originalCommands as $i => $originalCommand) {
Expand Down Expand Up @@ -531,7 +531,7 @@ private function handlePublishIndividualNodesFromWorkspace(

try {
// 4) using the new content stream, apply the matching commands
$this->withContentStreamIdToUse(
ContentStreamIdOverride::withContentStreamIdToUse(
$command->contentStreamIdForMatchingPart,
function () use ($matchingCommands, $contentRepository, $baseWorkspace, $command): void {
foreach ($matchingCommands as $matchingCommand) {
Expand Down Expand Up @@ -565,7 +565,7 @@ function () use ($matchingCommands, $contentRepository, $baseWorkspace, $command
)->block();

// 7) apply REMAINING commands to the workspace's new content stream
$this->withContentStreamIdToUse(
ContentStreamIdOverride::withContentStreamIdToUse(
$command->contentStreamIdForRemainingPart,
function () use ($contentRepository, $remainingCommands) {
foreach ($remainingCommands as $remainingCommand) {
Expand Down Expand Up @@ -668,7 +668,7 @@ private function handleDiscardIndividualNodesFromWorkspace(

// 4) using the new content stream, apply the commands to keep
try {
$this->withContentStreamIdToUse(
ContentStreamIdOverride::withContentStreamIdToUse(
$command->newContentStreamId,
function () use ($commandsToKeep, $contentRepository, $baseWorkspace, $command): void {
foreach ($commandsToKeep as $matchingCommand) {
Expand Down Expand Up @@ -990,19 +990,4 @@ private function hasEventsInContentStreamExceptForking(

return false;
}

private function withContentStreamIdToUse(ContentStreamId $contentStreamIdToUse, callable $function): void
{
if (ContentStreamIdOverride::$contentStreamIdToUse !== null) {
throw new \Exception('Recursive content stream override is not supported');
}
ContentStreamIdOverride::useContentStreamId($contentStreamIdToUse);
try {
$function();
} catch (\Exception $exception) {
ContentStreamIdOverride::useContentStreamId(null);
throw $exception;
}
ContentStreamIdOverride::useContentStreamId(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
final readonly class NodeIdToPublishOrDiscard implements \JsonSerializable
{
public function __construct(
/** @todo do we really need this? should be unique per command, not per node in the command */
public WorkspaceName $workspaceName,
public NodeAggregateId $nodeAggregateId,
public DimensionSpacePoint $dimensionSpacePoint,
) {
Expand All @@ -43,7 +41,6 @@ public function __construct(
public static function fromArray(array $array): self
{
return new self(
WorkspaceName::fromString($array['workspaceName']),
NodeAggregateId::fromString($array['nodeAggregateId']),
DimensionSpacePoint::fromArray($array['dimensionSpacePoint']),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
*
* Needed for #4322: https://github.com/neos/neos-development-collection/pull/4322
*
* Included in February 2023 - before final Neos 9.0 release
* Included in February 2024 - before final Neos 9.0 release
*
* @param string $contentRepository Identifier of the Content Repository to migrate
*/
Expand All @@ -32,4 +32,20 @@ public function migratePropertiesToUnsetCommand(string $contentRepository = 'def
$eventMigrationService = $this->contentRepositoryRegistry->buildService($contentRepositoryId, $this->eventMigrationServiceFactory);
$eventMigrationService->migratePropertiesToUnset($this->outputLine(...));
}

/**
* Adds a dummy workspace name to the events meta-data, so it can be rebased
*
* Needed for #4708: https://github.com/neos/neos-development-collection/pull/4708
*
* Included in March 2024 - before final Neos 9.0 release
*
* @param string $contentRepository Identifier of the Content Repository to migrate
*/
public function migrateMetaDataToWorkspaceNameCommand(string $contentRepository = 'default'): void
{
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$eventMigrationService = $this->contentRepositoryRegistry->buildService($contentRepositoryId, $this->eventMigrationServiceFactory);
$eventMigrationService->migrateMetaDataToWorkspaceName($this->outputLine(...));
}
}
Loading
Loading