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

!!!FEATURE: (Neos.Neos) Track created nodes in PendingChangesProjection #4393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Neos.Neos/Classes/PendingChangesProjection/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Change
*/
public $originDimensionSpacePoint;

/**
* @var bool
*/
public $created;

/**
* @var bool
*/
Expand All @@ -68,6 +73,7 @@ public function __construct(
ContentStreamId $contentStreamId,
NodeAggregateId $nodeAggregateId,
OriginDimensionSpacePoint $originDimensionSpacePoint,
bool $created,
bool $changed,
bool $moved,
bool $deleted,
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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'],
Expand Down
94 changes: 51 additions & 43 deletions Neos.Neos/Classes/PendingChangesProjection/ChangeProjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -409,7 +412,7 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria

private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVariantWasCreated $event): void
{
$this->markAsChanged(
$this->markAsCreated(
$event->contentStreamId,
$event->nodeAggregateId,
$event->generalizationOrigin
Expand All @@ -418,7 +421,7 @@ private function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVaria

private function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event): void
{
$this->markAsChanged(
$this->markAsCreated(
$event->contentStreamId,
$event->nodeAggregateId,
$event->peerOrigin
Expand All @@ -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);
}
});
Expand Down