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: Add creation and modification timestamps to nodes #4102

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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/Features/WorkspacePublishing.php');
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/CurrentSubgraphTrait.php');
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/CurrentUserTrait.php');
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/CurrentDateTimeTrait.php');
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php');
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/NodeTraversalTrait.php');
require_once(__DIR__ . '/../../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/ProjectedNodeAggregateTrait.php');
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ private function createNodeTable(Schema $schema): void
$table->addColumn('classification', Types::STRING)
->setLength(255)
->setNotnull(true);
$table->addColumn('created', Types::DATETIME_IMMUTABLE)
->setNotnull(true);
$table->addColumn('originalcreated', Types::DATETIME_IMMUTABLE)
->setNotnull(true);
$table->addColumn('lastmodified', Types::DATETIME_IMMUTABLE)
->setNotnull(false)
->setDefault(null);
$table->addColumn('originallastmodified', Types::DATETIME_IMMUTABLE)
->setNotnull(false)
->setDefault(null);
$table
->setPrimaryKey(['relationanchorpoint'])
->addIndex(['nodeaggregateid'], 'NODE_AGGREGATE_ID')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\Feature;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection\NodeRecord;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\Feature\NodeDisabling\Event\NodeAggregateWasDisabled;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\EventStore\Model\EventEnvelope;

/**
* The NodeDisabling projection feature trait
Expand All @@ -22,6 +28,8 @@ abstract protected function getTableNamePrefix(): string;
private function whenNodeAggregateWasDisabled(NodeAggregateWasDisabled $event): void
{
$this->transactional(function () use ($event) {


// TODO: still unsure why we need an "INSERT IGNORE" here;
// normal "INSERT" can trigger a duplicate key constraint exception
$this->getDatabaseConnection()->executeStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Neos\ContentRepository\Core\Feature\NodeMove\Event\NodeAggregateWasMoved;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\EventStore\Model\EventEnvelope;

/**
* The NodeMove projection feature trait
Expand Down Expand Up @@ -57,13 +58,15 @@ private function whenNodeAggregateWasMoved(NodeAggregateWasMoved $event): void
foreach ($moveNodeMapping->newLocations as $newLocation) {
assert($newLocation instanceof CoverageNodeMoveMapping);

$affectedDimensionSpacePoints = new DimensionSpacePointSet([
$newLocation->coveredDimensionSpacePoint
]);

// remove restriction relations by ancestors. We will reconnect them back after the move.
$this->removeAllRestrictionRelationsInSubtreeImposedByAncestors(
$event->contentStreamId,
$event->nodeAggregateId,
new DimensionSpacePointSet([
$newLocation->coveredDimensionSpacePoint
])
$affectedDimensionSpacePoints
);

// do the move (depending on how the move target is specified)
Expand Down Expand Up @@ -94,9 +97,7 @@ private function whenNodeAggregateWasMoved(NodeAggregateWasMoved $event): void
$event->contentStreamId,
$newParentNodeAggregateId,
$event->nodeAggregateId,
new DimensionSpacePointSet([
$newLocation->coveredDimensionSpacePoint
])
$affectedDimensionSpacePoints
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeSpecializationVariantWasCreated;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\EventStore\Model\EventEnvelope;

/**
* The NodeVariation projection feature trait
Expand All @@ -35,9 +36,9 @@ abstract protected function getTableNamePrefix(): string;
* @throws \Exception
* @throws \Throwable
*/
private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVariantWasCreated $event): void
private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVariantWasCreated $event, EventEnvelope $eventEnvelope): void
{
$this->transactional(function () use ($event) {
$this->transactional(function () use ($event, $eventEnvelope) {
// Do the actual specialization
$sourceNode = $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
Expand All @@ -50,7 +51,8 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria

$specializedNode = $this->copyNodeToDimensionSpacePoint(
$sourceNode,
$event->specializationOrigin
$event->specializationOrigin,
$eventEnvelope
);

$uncoveredDimensionSpacePoints = $event->specializationCoverage->points;
Expand Down Expand Up @@ -136,9 +138,9 @@ private function whenNodeSpecializationVariantWasCreated(NodeSpecializationVaria
* @throws \Exception
* @throws \Throwable
*/
public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVariantWasCreated $event): void
public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVariantWasCreated $event, EventEnvelope $eventEnvelope): void
{
$this->transactional(function () use ($event) {
$this->transactional(function () use ($event, $eventEnvelope) {
// do the generalization
$sourceNode = $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
Expand All @@ -158,7 +160,8 @@ public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVarian
}
$generalizedNode = $this->copyNodeToDimensionSpacePoint(
$sourceNode,
$event->generalizationOrigin
$event->generalizationOrigin,
$eventEnvelope
);

$unassignedIngoingDimensionSpacePoints = $event->generalizationCoverage;
Expand Down Expand Up @@ -244,9 +247,9 @@ public function whenNodeGeneralizationVariantWasCreated(NodeGeneralizationVarian
/**
* @throws \Throwable
*/
public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event): void
public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event, EventEnvelope $eventEnvelope): void
{
$this->transactional(function () use ($event) {
$this->transactional(function () use ($event, $eventEnvelope) {
// Do the peer variant creation itself
$sourceNode = $this->getProjectionContentGraph()->findNodeInAggregate(
$event->contentStreamId,
Expand All @@ -266,7 +269,8 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event):
}
$peerNode = $this->copyNodeToDimensionSpacePoint(
$sourceNode,
$event->peerOrigin
$event->peerOrigin,
$eventEnvelope
);

$unassignedIngoingDimensionSpacePoints = $event->peerCoverage;
Expand Down Expand Up @@ -336,7 +340,8 @@ public function whenNodePeerVariantWasCreated(NodePeerVariantWasCreated $event):

abstract protected function copyNodeToDimensionSpacePoint(
NodeRecord $sourceNode,
OriginDimensionSpacePoint $originDimensionSpacePoint
OriginDimensionSpacePoint $originDimensionSpacePoint,
EventEnvelope $eventEnvelope,
): NodeRecord;

abstract protected function copyHierarchyRelationToDimensionSpacePoint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
namespace Neos\ContentGraph\DoctrineDbalAdapter\Domain\Projection;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
Expand All @@ -38,7 +40,8 @@ public function __construct(
public NodeTypeName $nodeTypeName,
public NodeAggregateClassification $classification,
/** Transient node name to store a node name after fetching a node with hierarchy (not always available) */
public ?NodeName $nodeName = null
public ?NodeName $nodeName,
public Timestamps $timestamps,
) {
}

Expand All @@ -55,7 +58,16 @@ public function addToDatabase(Connection $databaseConnection, string $tableNameP
'origindimensionspacepointhash' => $this->originDimensionSpacePointHash,
'properties' => json_encode($this->properties),
'nodetypename' => (string)$this->nodeTypeName,
'classification' => $this->classification->value
'classification' => $this->classification->value,
'created' => $this->timestamps->created,
'originalcreated' => $this->timestamps->originalCreated,
'lastmodified' => $this->timestamps->lastModified,
'originallastmodified' => $this->timestamps->originalLastModified,
], [
'created' => Types::DATETIME_IMMUTABLE,
'originalcreated' => Types::DATETIME_IMMUTABLE,
'lastmodified' => Types::DATETIME_IMMUTABLE,
'originallastmodified' => Types::DATETIME_IMMUTABLE,
]);
}

Expand All @@ -73,10 +85,16 @@ public function updateToDatabase(Connection $databaseConnection, string $tableNa
'origindimensionspacepointhash' => $this->originDimensionSpacePointHash,
'properties' => json_encode($this->properties),
'nodetypename' => (string)$this->nodeTypeName,
'classification' => $this->classification->value
'classification' => $this->classification->value,
'lastmodified' => $this->timestamps->lastModified,
'originallastmodified' => $this->timestamps->originalLastModified,
],
[
'relationanchorpoint' => $this->relationAnchorPoint
],
[
'lastmodified' => Types::DATETIME_IMMUTABLE,
'originallastmodified' => Types::DATETIME_IMMUTABLE,
]
);
}
Expand Down Expand Up @@ -107,7 +125,22 @@ public static function fromDatabaseRow(array $databaseRow): self
SerializedPropertyValues::fromArray(json_decode($databaseRow['properties'], true)),
NodeTypeName::fromString($databaseRow['nodetypename']),
NodeAggregateClassification::from($databaseRow['classification']),
isset($databaseRow['name']) ? NodeName::fromString($databaseRow['name']) : null
isset($databaseRow['name']) ? NodeName::fromString($databaseRow['name']) : null,
Timestamps::create(
self::parseDateTimeString($databaseRow['created']),
self::parseDateTimeString($databaseRow['originalcreated']),
skurfuerst marked this conversation as resolved.
Show resolved Hide resolved
isset($databaseRow['lastmodified']) ? self::parseDateTimeString($databaseRow['lastmodified']) : null,
isset($databaseRow['originallastmodified']) ? self::parseDateTimeString($databaseRow['originallastmodified']) : null,
),
);
}

private static function parseDateTimeString(string $string): \DateTimeImmutable
{
$result = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $string);
if ($result === false) {
throw new \RuntimeException(sprintf('Failed to parse "%s" into a valid DateTime', $string), 1678902055);
}
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Nodes;
use Neos\ContentRepository\Core\Projection\ContentGraph\Reference;
use Neos\ContentRepository\Core\Projection\ContentGraph\References;
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
Expand Down Expand Up @@ -77,6 +78,12 @@ public function mapNodeRowToNode(
$this->nodeTypeManager->getNodeType($nodeRow['nodetypename']),
$this->createPropertyCollectionFromJsonString($nodeRow['properties']),
isset($nodeRow['name']) ? NodeName::fromString($nodeRow['name']) : null,
Timestamps::create(
self::parseDateTimeString($nodeRow['created']),
self::parseDateTimeString($nodeRow['originalcreated']),
isset($nodeRow['lastmodified']) ? self::parseDateTimeString($nodeRow['lastmodified']) : null,
isset($nodeRow['originallastmodified']) ? self::parseDateTimeString($nodeRow['originallastmodified']) : null,
),
);
}

Expand Down Expand Up @@ -306,4 +313,13 @@ public function mapNodeRowsToNodeAggregates(
);
}
}

private static function parseDateTimeString(string $string): \DateTimeImmutable
{
$result = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $string);
if ($result === false) {
throw new \RuntimeException(sprintf('Failed to parse "%s" into a valid DateTime', $string), 1678902055);
}
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ public function getAnchorPointForNodeAndOriginDimensionSpacePointAndContentStrea

if (count($rows) === 1) {
return NodeRelationAnchorPoint::fromString($rows[0]['relationanchorpoint']);
} else {
return null;
}
return null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\References;
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree;
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtrees;
use Neos\ContentRepository\Core\Projection\ContentGraph\Timestamps;
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
Expand Down Expand Up @@ -88,6 +89,13 @@ public function mapNodeRowToNode(
$this->propertyConverter
),
$nodeRow['nodename'] ? NodeName::fromString($nodeRow['nodename']) : null,
Timestamps::create(
// TODO replace with $nodeRow['created'] and $nodeRow['originalcreated'] once projection has implemented support
self::parseDateTimeString('2023-03-17 12:00:00'),
self::parseDateTimeString('2023-03-17 12:00:00'),
isset($nodeRow['lastmodified']) ? self::parseDateTimeString($nodeRow['lastmodified']) : null,
isset($nodeRow['originallastmodified']) ? self::parseDateTimeString($nodeRow['originallastmodified']) : null,
),
);

return $result;
Expand Down Expand Up @@ -340,4 +348,13 @@ public function mapNodeRowsToNodeAggregates(array $nodeRows, VisibilityConstrain
);
}
}

private static function parseDateTimeString(string $string): \DateTimeImmutable
{
$result = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $string);
if ($result === false) {
throw new \RuntimeException(sprintf('Failed to parse "%s" into a valid DateTime', $string), 1678902055);
}
return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/Features/WorkspacePublishing.php');
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/CurrentSubgraphTrait.php');
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/CurrentUserTrait.php');
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/CurrentDateTimeTrait.php');
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/GenericCommandExecutionAndEventPublication.php');
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/NodeTraversalTrait.php');
require_once(__DIR__ . '/../../../../Neos.ContentRepository.Core/Tests/Behavior/Features/Bootstrap/ProjectedNodeAggregateTrait.php');
Expand Down
Loading