diff --git a/Neos.Neos/Classes/PendingChangesProjection/Change.php b/Neos.Neos/Classes/PendingChangesProjection/Change.php index a39952d655c..4bbeeec0263 100644 --- a/Neos.Neos/Classes/PendingChangesProjection/Change.php +++ b/Neos.Neos/Classes/PendingChangesProjection/Change.php @@ -44,6 +44,11 @@ class Change */ public $originDimensionSpacePoint; + /** + * @var bool + */ + public $created; + /** * @var bool */ @@ -68,6 +73,7 @@ public function __construct( ContentStreamId $contentStreamId, NodeAggregateId $nodeAggregateId, OriginDimensionSpacePoint $originDimensionSpacePoint, + bool $created, bool $changed, bool $moved, bool $deleted, @@ -76,6 +82,7 @@ public function __construct( $this->contentStreamId = $contentStreamId; $this->nodeAggregateId = $nodeAggregateId; $this->originDimensionSpacePoint = $originDimensionSpacePoint; + $this->created = $created; $this->changed = $changed; $this->moved = $moved; $this->deleted = $deleted; @@ -93,6 +100,7 @@ public function addToDatabase(Connection $databaseConnection, string $tableName) 'nodeAggregateId' => $this->nodeAggregateId->value, 'originDimensionSpacePoint' => $this->originDimensionSpacePoint->toJson(), 'originDimensionSpacePointHash' => $this->originDimensionSpacePoint->hash, + 'created' => (int)$this->created, 'changed' => (int)$this->changed, 'moved' => (int)$this->moved, 'deleted' => (int)$this->deleted, @@ -105,6 +113,7 @@ public function updateToDatabase(Connection $databaseConnection, string $tableNa $databaseConnection->update( $tableName, [ + 'created' => (int)$this->created, 'changed' => (int)$this->changed, 'moved' => (int)$this->moved, 'deleted' => (int)$this->deleted, @@ -128,6 +137,7 @@ public static function fromDatabaseRow(array $databaseRow): self ContentStreamId::fromString($databaseRow['contentStreamId']), NodeAggregateId::fromString($databaseRow['nodeAggregateId']), OriginDimensionSpacePoint::fromJsonString($databaseRow['originDimensionSpacePoint']), + (bool)$databaseRow['created'], (bool)$databaseRow['changed'], (bool)$databaseRow['moved'], (bool)$databaseRow['deleted'], diff --git a/Neos.Neos/Classes/PendingChangesProjection/ChangeProjection.php b/Neos.Neos/Classes/PendingChangesProjection/ChangeProjection.php index 36537582f0f..b3fb8a84670 100644 --- a/Neos.Neos/Classes/PendingChangesProjection/ChangeProjection.php +++ b/Neos.Neos/Classes/PendingChangesProjection/ChangeProjection.php @@ -112,6 +112,8 @@ private function setupTables(): void $changeTable->addColumn('contentStreamId', Types::STRING) ->setLength(40) ->setNotnull(true); + $changeTable->addColumn('created', Types::BOOLEAN) + ->setNotnull(true); $changeTable->addColumn('changed', Types::BOOLEAN) ->setNotnull(true); $changeTable->addColumn('moved', Types::BOOLEAN) @@ -292,7 +294,7 @@ private function whenNodeReferencesWereSet(NodeReferencesWereSet $event): void private function whenNodeAggregateWithNodeWasCreated(NodeAggregateWithNodeWasCreated $event): void { - $this->markAsChanged( + $this->markAsCreated( $event->contentStreamId, $event->nodeAggregateId, $event->originDimensionSpacePoint @@ -350,12 +352,13 @@ private function whenNodeAggregateWasRemoved(NodeAggregateWasRemoved $event): vo $this->getDatabaseConnection()->executeUpdate( 'INSERT INTO ' . $this->tableNamePrefix . ' (contentStreamId, nodeAggregateId, originDimensionSpacePoint, - originDimensionSpacePointHash, deleted, changed, moved, removalAttachmentPoint) + originDimensionSpacePointHash, created, deleted, changed, moved, removalAttachmentPoint) VALUES ( :contentStreamId, :nodeAggregateId, :originDimensionSpacePoint, :originDimensionSpacePointHash, + 0, 1, 0, 0, @@ -400,7 +403,7 @@ private function whenDimensionSpacePointWasMoved(DimensionSpacePointWasMoved $ev private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVariantWasCreated $event): void { - $this->markAsChanged( + $this->markAsCreated( $event->contentStreamId, $event->nodeAggregateId, $event->specializationOrigin @@ -409,7 +412,7 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVariantWasCreated $event): void { - $this->markAsChanged( + $this->markAsCreated( $event->contentStreamId, $event->nodeAggregateId, $event->generalizationOrigin @@ -418,7 +421,7 @@ private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVaria private function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event): void { - $this->markAsChanged( + $this->markAsCreated( $event->contentStreamId, $event->nodeAggregateId, $event->peerOrigin @@ -430,66 +433,71 @@ private function markAsChanged( NodeAggregateId $nodeAggregateId, OriginDimensionSpacePoint $originDimensionSpacePoint, ): void { - $this->transactional(function () use ( + $this->modifyChange( $contentStreamId, $nodeAggregateId, - $originDimensionSpacePoint - ) { - if ($this->isLiveContentStream($contentStreamId)) { - return; + $originDimensionSpacePoint, + static function (Change $change) { + $change->changed = true; } - $change = $this->getChange( - $contentStreamId, - $nodeAggregateId, - $originDimensionSpacePoint - ); - if ($change === null) { - $change = new Change( - $contentStreamId, - $nodeAggregateId, - $originDimensionSpacePoint, - true, - false, - false - ); - $change->addToDatabase($this->getDatabaseConnection(), $this->tableNamePrefix); - } else { + ); + } + + private function markAsCreated( + ContentStreamId $contentStreamId, + NodeAggregateId $nodeAggregateId, + OriginDimensionSpacePoint $originDimensionSpacePoint, + ): void { + $this->modifyChange( + $contentStreamId, + $nodeAggregateId, + $originDimensionSpacePoint, + static function (Change $change) { + $change->created = true; $change->changed = true; - $change->updateToDatabase($this->getDatabaseConnection(), $this->tableNamePrefix); } - }); + ); } private function markAsMoved( ContentStreamId $contentStreamId, NodeAggregateId $nodeAggregateId, OriginDimensionSpacePoint $originDimensionSpacePoint, + ): void { + $this->modifyChange( + $contentStreamId, + $nodeAggregateId, + $originDimensionSpacePoint, + static function (Change $change) { + $change->moved = true; + } + ); + } + + private function modifyChange( + ContentStreamId $contentStreamId, + NodeAggregateId $nodeAggregateId, + OriginDimensionSpacePoint $originDimensionSpacePoint, + callable $modifyFn ): void { $this->transactional(function () use ( $contentStreamId, $nodeAggregateId, - $originDimensionSpacePoint + $originDimensionSpacePoint, + $modifyFn ) { if ($this->isLiveContentStream($contentStreamId)) { return; } - $change = $this->getChange( - $contentStreamId, - $nodeAggregateId, - $originDimensionSpacePoint - ); + + $change = $this->getChange($contentStreamId, $nodeAggregateId, $originDimensionSpacePoint); + if ($change === null) { - $change = new Change( - $contentStreamId, - $nodeAggregateId, - $originDimensionSpacePoint, - false, - true, - false - ); + $change = new Change($contentStreamId, $nodeAggregateId, $originDimensionSpacePoint, false, false, false, false); + $modifyFn($change); $change->addToDatabase($this->getDatabaseConnection(), $this->tableNamePrefix); } else { - $change->moved = true; + $modifyFn($change); $change->updateToDatabase($this->getDatabaseConnection(), $this->tableNamePrefix); } });