Skip to content

Commit

Permalink
TASK: Make ContentStreamWasForked implement EmbedsContentStreamId
Browse files Browse the repository at this point in the history
... and dont `updateContentStreamVersion` for it

https://neos-project.slack.com/archives/C04PYL8H3/p1730292774760689
  • Loading branch information
mhsdesign committed Oct 31, 2024
1 parent dda5d34 commit 82daa7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
/**
Expand All @@ -33,6 +34,11 @@ public function __construct(
) {
}

public function getContentStreamId(): ContentStreamId
{
return $this->newContentStreamId;
}

public static function fromArray(array $values): self
{
return new self(
Expand Down

0 comments on commit 82daa7c

Please sign in to comment.