From 82daa7cd74dcd2bb819a31abadba1bfc6d3af276 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:02:33 +0100 Subject: [PATCH] TASK: Make `ContentStreamWasForked` implement `EmbedsContentStreamId` ... and dont `updateContentStreamVersion` for it https://neos-project.slack.com/archives/C04PYL8H3/p1730292774760689 --- .../src/DoctrineDbalContentGraphProjection.php | 13 +++++++++++-- .../src/Domain/Projection/Feature/ContentStream.php | 11 +++-------- .../Event/ContentStreamWasForked.php | 8 +++++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php index 6521cdddc86..b9d62d38da2 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/DoctrineDbalContentGraphProjection.php @@ -24,6 +24,7 @@ use Neos\ContentRepository\Core\EventStore\InitiatingEventMetadata; use Neos\ContentRepository\Core\Feature\Common\EmbedsContentStreamId; use Neos\ContentRepository\Core\Feature\Common\InterdimensionalSiblings; +use Neos\ContentRepository\Core\Feature\Common\PublishableToWorkspaceInterface; use Neos\ContentRepository\Core\Feature\ContentStreamClosing\Event\ContentStreamWasClosed; use Neos\ContentRepository\Core\Feature\ContentStreamClosing\Event\ContentStreamWasReopened; use Neos\ContentRepository\Core\Feature\ContentStreamCreation\Event\ContentStreamWasCreated; @@ -236,8 +237,16 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void WorkspaceWasRemoved::class => $this->whenWorkspaceWasRemoved($event), default => $event instanceof EmbedsContentStreamId || throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))), }; - if ($event instanceof EmbedsContentStreamId && ContentStreamEventStreamName::isContentStreamStreamName($eventEnvelope->streamName)) { - $this->updateContentStreamVersion($event, $eventEnvelope->version); + if ( + $event instanceof EmbedsContentStreamId + && ContentStreamEventStreamName::isContentStreamStreamName($eventEnvelope->streamName) + && !( + // special case as we dont need to update anything. The handling above takes care of setting the version to 0 + $event instanceof ContentStreamWasForked + || $event instanceof ContentStreamWasCreated + ) + ) { + $this->updateContentStreamVersion($event->getContentStreamId(), $eventEnvelope->version, $event instanceof PublishableToWorkspaceInterface); } } diff --git a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php index cc5abaf69a8..cbddc75ce2d 100644 --- a/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php +++ b/Neos.ContentGraph.DoctrineDbalAdapter/src/Domain/Projection/Feature/ContentStream.php @@ -4,9 +4,6 @@ namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature; -use Neos\ContentRepository\Core\EventStore\EventInterface; -use Neos\ContentRepository\Core\Feature\Common\EmbedsContentStreamId; -use Neos\ContentRepository\Core\Feature\Common\PublishableToWorkspaceInterface; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\EventStore\Model\Event\Version; @@ -54,18 +51,16 @@ private function removeContentStream(ContentStreamId $contentStreamId): void ]); } - private function updateContentStreamVersion(EventInterface&EmbedsContentStreamId $event, Version $version): void + private function updateContentStreamVersion(ContentStreamId $contentStreamId, Version $version, bool $markAsDirty): void { - // todo make fork content stream `EmbedsContentStreamId` but then just ignore it here because we set the version already - $isPublishableEvent = $event instanceof PublishableToWorkspaceInterface; $updatePayload = [ 'version' => $version->value, ]; - if ($isPublishableEvent) { + if ($markAsDirty) { $updatePayload['dirty'] = 1; } $this->dbal->update($this->tableNames->contentStream(), $updatePayload, [ - 'id' => $event->getContentStreamId()->value, + 'id' => $contentStreamId->value, ]); } } diff --git a/Neos.ContentRepository.Core/Classes/Feature/ContentStreamForking/Event/ContentStreamWasForked.php b/Neos.ContentRepository.Core/Classes/Feature/ContentStreamForking/Event/ContentStreamWasForked.php index 9c476787fc9..a2418445221 100644 --- a/Neos.ContentRepository.Core/Classes/Feature/ContentStreamForking/Event/ContentStreamWasForked.php +++ b/Neos.ContentRepository.Core/Classes/Feature/ContentStreamForking/Event/ContentStreamWasForked.php @@ -15,13 +15,14 @@ */ use Neos\ContentRepository\Core\EventStore\EventInterface; +use Neos\ContentRepository\Core\Feature\Common\EmbedsContentStreamId; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; use Neos\EventStore\Model\Event\Version; /** * @api events are the persistence-API of the content repository */ -final readonly class ContentStreamWasForked implements EventInterface +final readonly class ContentStreamWasForked implements EventInterface, EmbedsContentStreamId { public function __construct( /** @@ -33,6 +34,11 @@ public function __construct( ) { } + public function getContentStreamId(): ContentStreamId + { + return $this->newContentStreamId; + } + public static function fromArray(array $values): self { return new self(