Skip to content

Commit

Permalink
TASK: Centralise RebaseableCommand::enrichWithCommand
Browse files Browse the repository at this point in the history
neos#5301 (comment)

> Alright, at least according to the tests this works now. I also went through all Rebasable commands to check if the events get enriched. the Dimension ones were the only missing. IMHO we should centralize this behavior, I opted against doing it here though as I think we need to consider if there would have to be any more logic involved to decide what gets enriched with commands, in what way, when we override the command if there is already metadata and finally what the causation ids are. I guess we could ignore all these questions and centralize it, but it warrants a closer look and is therefore out of scope of this change.
  • Loading branch information
mhsdesign committed Nov 8, 2024
1 parent 352cd1a commit 76a975d
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\RebasableToOtherWorkspaceInterface;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;

/**
* Implementation Detail of {@see ContentRepository::handle}, which does the command dispatching to the different
Expand Down Expand Up @@ -59,7 +60,25 @@ public function handle(PublicCommandInterface|RebasableToOtherWorkspaceInterface
// multiple handlers must not handle the same command
foreach ($this->handlers as $handler) {
if ($handler->canHandle($possiblySerializedCommand)) {
return $handler->handle($possiblySerializedCommand, $this->commandHandlingDependencies);
$eventsToPublish = $handler->handle($possiblySerializedCommand, $this->commandHandlingDependencies);

if (!$eventsToPublish instanceof EventsToPublish) {
// generator todo?
return $eventsToPublish;
}

if ($possiblySerializedCommand instanceof RebasableToOtherWorkspaceInterface) {
return new EventsToPublish(
$eventsToPublish->streamName,
RebaseableCommand::enrichWithCommand(
$possiblySerializedCommand,
$eventsToPublish->events
),
$eventsToPublish->expectedVersion
);
}

return $eventsToPublish;
}
}
throw new \RuntimeException(sprintf('No handler found for Command "%s"', get_debug_type($possiblySerializedCommand)), 1649582778);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\Event\DimensionShineThroughWasAdded;
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\Event\DimensionSpacePointWasMoved;
use Neos\ContentRepository\Core\Feature\DimensionSpaceAdjustment\Exception\DimensionSpacePointAlreadyExists;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\EventStore\Model\EventStream\ExpectedVersion;
Expand Down Expand Up @@ -79,16 +78,13 @@ private function handleMoveDimensionSpacePoint(

return new EventsToPublish(
$streamName,
RebaseableCommand::enrichWithCommand(
$command,
Events::with(
new DimensionSpacePointWasMoved(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$command->source,
$command->target
),
)
Events::with(
new DimensionSpacePointWasMoved(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$command->source,
$command->target
),
),
ExpectedVersion::ANY()
);
Expand All @@ -112,15 +108,12 @@ private function handleAddDimensionShineThrough(

return new EventsToPublish(
$streamName,
RebaseableCommand::enrichWithCommand(
$command,
Events::with(
new DimensionShineThroughWasAdded(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$command->source,
$command->target
)
Events::with(
new DimensionShineThroughWasAdded(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$command->source,
$command->target
)
),
ExpectedVersion::ANY()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\SerializedNodeReferences;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyType;
use Neos\ContentRepository\Core\NodeType\NodeType;
Expand Down Expand Up @@ -225,7 +224,7 @@ private function handleCreateNodeAggregateWithNodeAndSerializedProperties(
return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())
->getEventStreamName(),
RebaseableCommand::enrichWithCommand($command, Events::fromArray($events)),
Events::fromArray($events),
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Neos\ContentRepository\Core\DimensionSpace\Exception\DimensionSpacePointNotFound;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Command\DisableNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Command\EnableNodeAggregate;
Expand Down Expand Up @@ -82,10 +81,7 @@ private function handleDisableNodeAggregate(
return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())
->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down Expand Up @@ -137,7 +133,7 @@ public function handleEnableNodeAggregate(

return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())->getEventStreamName(),
RebaseableCommand::enrichWithCommand($command, $events),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeDuplication\Command\CopyNodesRecursively;
use Neos\ContentRepository\Core\Feature\NodeDuplication\Dto\NodeSubtreeSnapshot;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeConstraintException;
Expand Down Expand Up @@ -160,10 +159,7 @@ private function handleCopyNodesRecursively(
ContentStreamEventStreamName::fromContentStreamId(
$contentGraph->getContentStreamId()
)->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
Events::fromArray($events)
),
Events::fromArray($events),
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyScope;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
Expand Down Expand Up @@ -132,10 +131,7 @@ private function handleSetSerializedNodeProperties(
return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())
->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
Events::fromArray($events)
),
Events::fromArray($events),
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSibling;
use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSiblings;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeMove\Command\MoveNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeMove\Dto\RelationDistributionStrategy;
Expand Down Expand Up @@ -207,10 +206,7 @@ private function handleMoveNodeAggregate(

return new EventsToPublish(
$contentStreamEventStreamName->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetSerializedNodeReferences;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Dto\SerializedNodeReferences;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Event\NodeReferencesWereSet;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
Expand Down Expand Up @@ -153,10 +152,7 @@ private function handleSetSerializedNodeReferences(
return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())
->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Neos\ContentRepository\Core\DimensionSpace\Exception\DimensionSpacePointNotFound;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Command\RemoveNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Event\NodeAggregateWasRemoved;
Expand Down Expand Up @@ -91,10 +90,7 @@ private function handleRemoveNodeAggregate(
return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())
->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\ConstraintChecks;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeRenaming\Command\ChangeNodeAggregateName;
use Neos\ContentRepository\Core\Feature\NodeRenaming\Event\NodeAggregateNameWasChanged;
Expand Down Expand Up @@ -61,10 +60,7 @@ private function handleChangeNodeAggregateName(ChangeNodeAggregateName $command,

return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePointSet;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\Common\NodeTypeChangeInternals;
use Neos\ContentRepository\Core\Feature\Common\TetheredNodeInternals;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
Expand Down Expand Up @@ -279,10 +278,7 @@ private function handleChangeNodeAggregateType(

return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
Events::fromArray($events),
),
Events::fromArray($events),
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Neos\ContentRepository\Core\DimensionSpace\Exception\DimensionSpacePointNotFound;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\ConstraintChecks;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\Common\NodeVariationInternals;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeVariation\Command\CreateNodeVariant;
Expand Down Expand Up @@ -84,10 +83,7 @@ private function handleCreateNodeVariant(

return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function extractFromEventMetaData(EventMetadata $eventMetadata, Se
);
}


/**
* Stores the command in the event's metadata for events on a content stream. This is an important prerequisite
* for the rebase functionality-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSiblings;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeCreation\Dto\NodeAggregateIdsByNodePaths;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
Expand Down Expand Up @@ -119,10 +118,7 @@ private function handleCreateRootNodeAggregateWithNode(
$contentStreamEventStream = ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId());
return new EventsToPublish(
$contentStreamEventStream->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
Events::fromArray($events)
),
Events::fromArray($events),
$expectedVersion
);
}
Expand Down Expand Up @@ -174,10 +170,7 @@ private function handleUpdateRootNodeAggregateDimensions(
);
return new EventsToPublish(
$contentStreamEventStream->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
$expectedVersion
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\Common\ConstraintChecks;
use Neos\ContentRepository\Core\Feature\RebaseableCommand;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Command\TagSubtree;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Command\UntagSubtree;
Expand Down Expand Up @@ -71,10 +70,7 @@ private function handleTagSubtree(TagSubtree $command, CommandHandlingDependenci
return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())
->getEventStreamName(),
RebaseableCommand::enrichWithCommand(
$command,
$events
),
$events,
ExpectedVersion::ANY()
);
}
Expand Down Expand Up @@ -116,7 +112,7 @@ public function handleUntagSubtree(UntagSubtree $command, CommandHandlingDepende

return new EventsToPublish(
ContentStreamEventStreamName::fromContentStreamId($contentGraph->getContentStreamId())->getEventStreamName(),
RebaseableCommand::enrichWithCommand($command, $events),
$events,
ExpectedVersion::ANY()
);
}
Expand Down

0 comments on commit 76a975d

Please sign in to comment.