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: Adjust to "serializable commands" #3881

Merged
merged 7 commits into from
Nov 12, 2024
145 changes: 55 additions & 90 deletions Classes/Infrastructure/ContentRepository/ConflictsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@

namespace Neos\Neos\Ui\Infrastructure\ContentRepository;

use Neos\ContentRepository\Core\CommandHandler\CommandInterface;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNodeAndSerializedProperties;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Command\DisableNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Command\EnableNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties;
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetSerializedNodeProperties;
use Neos\ContentRepository\Core\Feature\NodeMove\Command\MoveNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetNodeReferences;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Command\SetSerializedNodeReferences;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Command\RemoveNodeAggregate;
use Neos\ContentRepository\Core\Feature\NodeTypeChange\Command\ChangeNodeAggregateType;
use Neos\ContentRepository\Core\Feature\NodeVariation\Command\CreateNodeVariant;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Command\TagSubtree;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Command\UntagSubtree;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\CommandThatFailedDuringRebase;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeModification\Event\NodePropertiesWereSet;
use Neos\ContentRepository\Core\Feature\NodeMove\Event\NodeAggregateWasMoved;
use Neos\ContentRepository\Core\Feature\NodeReferencing\Event\NodeReferencesWereSet;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Event\NodeAggregateWasRemoved;
use Neos\ContentRepository\Core\Feature\NodeTypeChange\Event\NodeAggregateTypeWasChanged;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasTagged;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\ConflictingEvent;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Exception\WorkspaceRebaseFailed;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface;
Expand Down Expand Up @@ -80,8 +76,8 @@ public function fromWorkspaceRebaseFailed(
/** @var array<string,Conflict> */
$conflictsByKey = [];

foreach ($workspaceRebaseFailed->commandsThatFailedDuringRebase as $commandThatFailedDuringRebase) {
$conflict = $this->createConflictFromCommandThatFailedDuringRebase($commandThatFailedDuringRebase);
foreach ($workspaceRebaseFailed->conflictingEvents as $eventThatFailedDuringRebase) {
$conflict = $this->createConflictFromEventThatFailedDuringRebase($eventThatFailedDuringRebase);
if (array_key_exists($conflict->key, $conflictsByKey)) {
// deduplicate if the conflict affects the same node
$conflictsByKey[$conflict->key] = $conflict;
Expand All @@ -91,14 +87,12 @@ public function fromWorkspaceRebaseFailed(
return new Conflicts(...$conflictsByKey);
}

private function createConflictFromCommandThatFailedDuringRebase(
CommandThatFailedDuringRebase $commandThatFailedDuringRebase
private function createConflictFromEventThatFailedDuringRebase(
ConflictingEvent $eventThatFailedDuringRebase
): Conflict {
$nodeAggregateId = $this->extractNodeAggregateIdFromCommand(
$commandThatFailedDuringRebase->command
);
$subgraph = $this->acquireSubgraphFromCommand(
$commandThatFailedDuringRebase->command,
$nodeAggregateId = $eventThatFailedDuringRebase->getAffectedNodeAggregateId();
$subgraph = $this->acquireSubgraph(
$eventThatFailedDuringRebase->getEvent(),
$nodeAggregateId
);
$affectedSite = $nodeAggregateId
Expand Down Expand Up @@ -130,67 +124,42 @@ private function createConflictFromCommandThatFailedDuringRebase(
affectedNode: $affectedNode
? $this->createIconLabelForNode($affectedNode)
: null,
typeOfChange: $this->createTypeOfChangeFromCommand(
$commandThatFailedDuringRebase->command
typeOfChange: $this->createTypeOfChange(
$eventThatFailedDuringRebase->getEvent()
),
reasonForConflict: $this->createReasonForConflictFromException(
$commandThatFailedDuringRebase->exception
$eventThatFailedDuringRebase->getException()
)
);
}

private function extractNodeAggregateIdFromCommand(CommandInterface $command): ?NodeAggregateId
{
return match (true) {
$command instanceof MoveNodeAggregate,
$command instanceof SetNodeProperties,
$command instanceof SetSerializedNodeProperties,
$command instanceof CreateNodeAggregateWithNode,
$command instanceof CreateNodeAggregateWithNodeAndSerializedProperties,
$command instanceof TagSubtree,
$command instanceof DisableNodeAggregate,
$command instanceof UntagSubtree,
$command instanceof EnableNodeAggregate,
$command instanceof RemoveNodeAggregate,
$command instanceof ChangeNodeAggregateType,
$command instanceof CreateNodeVariant =>
$command->nodeAggregateId,
$command instanceof SetNodeReferences,
$command instanceof SetSerializedNodeReferences =>
$command->sourceNodeAggregateId,
default => null
};
}

private function acquireSubgraphFromCommand(
CommandInterface $command,
private function acquireSubgraph(
EventInterface $event,
?NodeAggregateId $nodeAggregateIdForDimensionFallback
): ?ContentSubgraphInterface {
if ($this->workspace === null) {
return null;
}

$dimensionSpacePoint = match (true) {
$command instanceof MoveNodeAggregate =>
$command->dimensionSpacePoint,
$command instanceof SetNodeProperties,
$command instanceof SetSerializedNodeProperties,
$command instanceof CreateNodeAggregateWithNode,
$command instanceof CreateNodeAggregateWithNodeAndSerializedProperties =>
$command->originDimensionSpacePoint->toDimensionSpacePoint(),
$command instanceof SetNodeReferences,
$command instanceof SetSerializedNodeReferences =>
$command->sourceOriginDimensionSpacePoint->toDimensionSpacePoint(),
$command instanceof TagSubtree,
$command instanceof DisableNodeAggregate,
$command instanceof UntagSubtree,
$command instanceof EnableNodeAggregate,
$command instanceof RemoveNodeAggregate =>
$command->coveredDimensionSpacePoint,
$command instanceof ChangeNodeAggregateType =>
$dimensionSpacePoint = match ($event::class) {
NodeAggregateWasMoved::class =>
$event->succeedingSiblingsForCoverage->toDimensionSpacePointSet()->getFirst(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo this is maybe cheesy? We look into the succeedingSiblingsForCoverage ???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nasty.. I created an issue for that neos/neos-development-collection#5360

NodePropertiesWereSet::class,
NodeAggregateWithNodeWasCreated::class =>
$event->originDimensionSpacePoint->toDimensionSpacePoint(),
NodeReferencesWereSet::class =>
$event->affectedSourceOriginDimensionSpacePoints->toDimensionSpacePointSet()->getFirst(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ideal that there is only a set here and not a originDimensionSpacePoint like in SetSerializedNodeProperties?

SubtreeWasTagged::class,
SubtreeWasUntagged::class =>
$event->affectedDimensionSpacePoints->getFirst(),
NodeAggregateWasRemoved::class =>
$event->affectedCoveredDimensionSpacePoints->getFirst(),
NodeAggregateTypeWasChanged::class =>
null,
$command instanceof CreateNodeVariant =>
$command->targetOrigin->toDimensionSpacePoint(),
NodePeerVariantWasCreated::class =>
$event->peerOrigin->toDimensionSpacePoint(),
NodeGeneralizationVariantWasCreated::class =>
$event->generalizationOrigin->toDimensionSpacePoint(),
default => null
};

Expand Down Expand Up @@ -247,27 +216,23 @@ private function createIconLabelForNode(Node $node): IconLabel
);
}

private function createTypeOfChangeFromCommand(
CommandInterface $command
private function createTypeOfChange(
EventInterface $event
): ?TypeOfChange {
return match (true) {
$command instanceof CreateNodeAggregateWithNode,
$command instanceof CreateNodeAggregateWithNodeAndSerializedProperties,
$command instanceof CreateNodeVariant =>
return match ($event::class) {
NodeAggregateWithNodeWasCreated::class,
NodePeerVariantWasCreated::class,
NodeGeneralizationVariantWasCreated::class =>
TypeOfChange::NODE_HAS_BEEN_CREATED,
$command instanceof SetNodeProperties,
$command instanceof SetSerializedNodeProperties,
$command instanceof SetNodeReferences,
$command instanceof SetSerializedNodeReferences,
$command instanceof TagSubtree,
$command instanceof DisableNodeAggregate,
$command instanceof UntagSubtree,
$command instanceof EnableNodeAggregate,
$command instanceof ChangeNodeAggregateType =>
NodePropertiesWereSet::class,
NodeReferencesWereSet::class,
SubtreeWasTagged::class,
SubtreeWasUntagged::class,
NodeAggregateTypeWasChanged::class =>
TypeOfChange::NODE_HAS_BEEN_CHANGED,
$command instanceof MoveNodeAggregate =>
NodeAggregateWasMoved::class =>
TypeOfChange::NODE_HAS_BEEN_MOVED,
$command instanceof RemoveNodeAggregate =>
NodeAggregateWasRemoved::class =>
TypeOfChange::NODE_HAS_BEEN_DELETED,
default => null
};
Expand Down
Loading