Skip to content

Commit

Permalink
TASK: Simplify upcasting of legacy events to be in fromArray instea…
Browse files Browse the repository at this point in the history
…d spread around

This overhauls the `NodeAggregateWasDisabled` upcasting from

#4659
  • Loading branch information
mhsdesign committed Dec 10, 2024
1 parent 3412594 commit 135dc67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,7 @@ public function denormalize(Event $event): EventInterface
throw new \RuntimeException(sprintf('Expected array got %s', $eventDataAsArray));
}
/** {@see EventInterface::fromArray()} */
$eventInstance = $eventClassName::fromArray($eventDataAsArray);
return match ($eventInstance::class) {
// upcast disabled / enabled events to the corresponding SubtreeTag events
NodeAggregateWasDisabled::class => new SubtreeWasTagged($eventInstance->workspaceName, $eventInstance->contentStreamId, $eventInstance->nodeAggregateId, $eventInstance->affectedDimensionSpacePoints, SubtreeTag::disabled()),
NodeAggregateWasEnabled::class => new SubtreeWasUntagged($eventInstance->workspaceName, $eventInstance->contentStreamId, $eventInstance->nodeAggregateId, $eventInstance->affectedDimensionSpacePoints, SubtreeTag::disabled()),
default => $eventInstance,
};
return $eventClassName::fromArray($eventDataAsArray);
}

private function getEventData(EventInterface $event): EventData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,36 @@

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\Common\EmbedsContentStreamId;
use Neos\ContentRepository\Core\Feature\Common\EmbedsNodeAggregateId;
use Neos\ContentRepository\Core\Feature\Common\EmbedsWorkspaceName;
use Neos\ContentRepository\Core\Feature\Common\PublishableToWorkspaceInterface;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Dto\SubtreeTag;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasTagged;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* A node aggregate was disabled
*
* @deprecated This event will never be emitted, it is up-casted to a corresponding {@see SubtreeWasTagged} event instead in the {@see EventNormalizer}. This implementation is just kept for backwards-compatibility
* @deprecated This event will never be emitted, it is up-casted to a corresponding {@see SubtreeWasTagged} event instead. This implementation is just kept for backwards-compatibility
* @internal
*/
final readonly class NodeAggregateWasDisabled implements
EventInterface,
PublishableToWorkspaceInterface,
EmbedsContentStreamId,
EmbedsNodeAggregateId,
EmbedsWorkspaceName
final readonly class NodeAggregateWasDisabled implements EventInterface
{
public function __construct(
public WorkspaceName $workspaceName,
public ContentStreamId $contentStreamId,
public NodeAggregateId $nodeAggregateId,
/** The dimension space points the node aggregate was disabled in */
public DimensionSpacePointSet $affectedDimensionSpacePoints,
) {
}

public function getContentStreamId(): ContentStreamId
private function __construct()
{
return $this->contentStreamId;
}

public function getNodeAggregateId(): NodeAggregateId
{
return $this->nodeAggregateId;
}

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

public function withWorkspaceNameAndContentStreamId(WorkspaceName $targetWorkspaceName, ContentStreamId $contentStreamId): self
{
return new self(
$targetWorkspaceName,
$contentStreamId,
$this->nodeAggregateId,
$this->affectedDimensionSpacePoints,
);
// legacy event must not be instantiated
}

public static function fromArray(array $values): EventInterface
{
return new self(
return new SubtreeWasTagged(
WorkspaceName::fromString($values['workspaceName']),
ContentStreamId::fromString($values['contentStreamId']),
NodeAggregateId::fromString($values['nodeAggregateId']),
DimensionSpacePointSet::fromArray($values['affectedDimensionSpacePoints']),
SubtreeTag::disabled()
);
}

public function jsonSerialize(): array
{
return get_object_vars($this);
throw new \RuntimeException('Legacy event instance must not exist.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,36 @@

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\EventStore\EventNormalizer;
use Neos\ContentRepository\Core\Feature\Common\EmbedsContentStreamId;
use Neos\ContentRepository\Core\Feature\Common\EmbedsNodeAggregateId;
use Neos\ContentRepository\Core\Feature\Common\EmbedsWorkspaceName;
use Neos\ContentRepository\Core\Feature\Common\PublishableToWorkspaceInterface;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Dto\SubtreeTag;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;

/**
* A node aggregate was enabled
*
* @deprecated This event will never be emitted, it is up-casted to a corresponding {@see SubtreeWasUntagged} event instead in the {@see EventNormalizer}. This implementation is just kept for backwards-compatibility
* @deprecated This event will never be emitted, it is up-casted to a corresponding {@see SubtreeWasUntagged} event instead. This implementation is just kept for backwards-compatibility
* @internal
*/
final readonly class NodeAggregateWasEnabled implements
EventInterface,
PublishableToWorkspaceInterface,
EmbedsContentStreamId,
EmbedsNodeAggregateId,
EmbedsWorkspaceName
final readonly class NodeAggregateWasEnabled implements EventInterface
{
public function __construct(
public WorkspaceName $workspaceName,
public ContentStreamId $contentStreamId,
public NodeAggregateId $nodeAggregateId,
public DimensionSpacePointSet $affectedDimensionSpacePoints,
) {
}

public function getContentStreamId(): ContentStreamId
private function __construct()
{
return $this->contentStreamId;
}

public function getNodeAggregateId(): NodeAggregateId
{
return $this->nodeAggregateId;
}

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

public function withWorkspaceNameAndContentStreamId(WorkspaceName $targetWorkspaceName, ContentStreamId $contentStreamId): self
{
return new self(
$targetWorkspaceName,
$contentStreamId,
$this->nodeAggregateId,
$this->affectedDimensionSpacePoints,
);
// legacy event must not be instantiated
}

public static function fromArray(array $values): EventInterface
{
return new self(
return new SubtreeWasUntagged(
WorkspaceName::fromString($values['workspaceName']),
ContentStreamId::fromString($values['contentStreamId']),
NodeAggregateId::fromString($values['nodeAggregateId']),
DimensionSpacePointSet::fromArray($values['affectedDimensionSpacePoints']),
SubtreeTag::disabled()
);
}

public function jsonSerialize(): array
{
return get_object_vars($this);
throw new \RuntimeException('Legacy event instance must not exist.');
}
}

0 comments on commit 135dc67

Please sign in to comment.