Skip to content

Commit

Permalink
4191 - Adjust to aggregate scoped changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schmitt committed Oct 23, 2024
1 parent 7e5a13b commit 4fe6b98
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->originDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
&& $nodeIdToPublish->dimensionSpacePoint?->equals($this->originDimensionSpacePoint)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
$this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
);
return (
!is_null($targetNodeAggregateId)
&& $this->targetDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
&& $nodeIdToPublish->dimensionSpacePoint?->equals($this->targetDimensionSpacePoint)
&& $targetNodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return (
$this->originDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
$nodeIdToPublish->dimensionSpacePoint?->equals($this->originDimensionSpacePoint)
&& $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function jsonSerialize(): array

public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return ($this->sourceOriginDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint)
return ($nodeIdToPublish->dimensionSpacePoint?->equals($this->sourceOriginDimensionSpacePoint)
&& $this->sourceNodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function jsonSerialize(): array
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->targetOrigin->equals($nodeIdToPublish->dimensionSpacePoint);
&& $nodeIdToPublish->dimensionSpacePoint?->equals($this->targetOrigin);
}

public function createCopyForWorkspace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName): self
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->coveredDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint);
&& $nodeIdToPublish->dimensionSpacePoint === $this->coveredDimensionSpacePoint;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function createCopyForWorkspace(WorkspaceName $targetWorkspaceName): self
public function matchesNodeId(NodeIdToPublishOrDiscard $nodeIdToPublish): bool
{
return $this->nodeAggregateId->equals($nodeIdToPublish->nodeAggregateId)
&& $this->coveredDimensionSpacePoint->equals($nodeIdToPublish->dimensionSpacePoint);
&& $this->coveredDimensionSpacePoint === $nodeIdToPublish->dimensionSpacePoint;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
{
public function __construct(
public NodeAggregateId $nodeAggregateId,
public DimensionSpacePoint $dimensionSpacePoint,
/** Can be null for aggregate scoped changes, e.g. ChangeNodeAggregateName or ChangeNodeAggregateName */
public ?DimensionSpacePoint $dimensionSpacePoint,
) {
}

Expand All @@ -41,7 +42,9 @@ public static function fromArray(array $array): self
{
return new self(
NodeAggregateId::fromString($array['nodeAggregateId']),
DimensionSpacePoint::fromArray($array['dimensionSpacePoint']),
is_array($array['dimensionSpacePoint'] ?? null)
? DimensionSpacePoint::fromArray($array['dimensionSpacePoint'])
: null,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ private function discardWorkspace(WorkspaceName $workspaceName): void
private function discardNodes(WorkspaceName $workspaceName, NodeIdsToPublishOrDiscard $nodeIds): void
{
foreach ($nodeIds as $nodeId) {
if (!$nodeId->dimensionSpacePoint) {
// NodeAggregateTypeWasChanged and NodeAggregateNameWasChanged don't impact asset usage
continue;
}
$this->assetUsageIndexingService->removeIndexForWorkspaceNameNodeAggregateIdAndDimensionSpacePoint(
$this->contentRepository->id,
$workspaceName,
Expand Down
47 changes: 33 additions & 14 deletions Neos.Neos/Classes/Domain/Service/WorkspacePublishingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Dto\RebaseErrorHandlingStrategy;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Exception\WorkspaceRebaseFailed;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateIds;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace as ContentRepositoryWorkspace;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Exception\NodeAggregateCurrentlyDoesNotExist;
Expand Down Expand Up @@ -339,7 +341,7 @@ private function resolveNodeIdsToPublishOrDiscard(

$nodeIdsToPublishOrDiscard[] = new NodeIdToPublishOrDiscard(
$change->nodeAggregateId,
$change->originDimensionSpacePoint->toDimensionSpacePoint()
$change->originDimensionSpacePoint?->toDimensionSpacePoint()
);
}

Expand All @@ -358,7 +360,6 @@ private function countPendingWorkspaceChangesInternal(ContentRepository $content
return $contentRepository->projectionState(ChangeFinder::class)->countByContentStreamId($crWorkspace->currentContentStreamId);
}


private function isChangePublishableWithinAncestorScope(
ContentRepository $contentRepository,
WorkspaceName $workspaceName,
Expand All @@ -374,20 +375,38 @@ private function isChangePublishableWithinAncestorScope(
}
}

$subgraph = $contentRepository->getContentGraph($workspaceName)->getSubgraph(
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
VisibilityConstraints::withoutRestrictions()
);
if ($change->originDimensionSpacePoint) {
$subgraph = $contentRepository->getContentGraph($workspaceName)->getSubgraph(
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
VisibilityConstraints::withoutRestrictions()
);

// A Change is publishable if the respective node (or the respective
// removal attachment point) has a closest ancestor that matches our
// current ancestor scope (Document/Site)
$actualAncestorNode = $subgraph->findClosestNode(
$change->removalAttachmentPoint ?? $change->nodeAggregateId,
FindClosestNodeFilter::create(nodeTypes: $ancestorNodeTypeName->value)
);
// A Change is publishable if the respective node (or the respective
// removal attachment point) has a closest ancestor that matches our
// current ancestor scope (Document/Site)
$actualAncestorNode = $subgraph->findClosestNode(
$change->removalAttachmentPoint ?? $change->nodeAggregateId,
FindClosestNodeFilter::create(nodeTypes: $ancestorNodeTypeName->value)
);

return $actualAncestorNode?->aggregateId->equals($ancestorId) ?? false;
} else {
return $this->findAncestorAggregateIds(
$contentRepository->getContentGraph($workspaceName),
$change->nodeAggregateId
)->contain($ancestorId);
}
}

private function findAncestorAggregateIds(ContentGraphInterface $contentGraph, NodeAggregateId $descendantNodeAggregateId): NodeAggregateIds
{
$nodeAggregateIds = NodeAggregateIds::create($descendantNodeAggregateId);
foreach ($contentGraph->findParentNodeAggregates($descendantNodeAggregateId) as $parentNodeAggregate) {
$nodeAggregateIds = $nodeAggregateIds->merge(NodeAggregateIds::create($parentNodeAggregate->nodeAggregateId));
$nodeAggregateIds = $nodeAggregateIds->merge($this->findAncestorAggregateIds($contentGraph, $parentNodeAggregate->nodeAggregateId));
}

return $actualAncestorNode?->aggregateId->equals($ancestorId) ?? false;
return $nodeAggregateIds;
}

/**
Expand Down
12 changes: 7 additions & 5 deletions Neos.Neos/Classes/PendingChangesProjection/Change.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public function addToDatabase(Connection $databaseConnection, string $tableName)
$databaseConnection->insert($tableName, [
'contentStreamId' => $this->contentStreamId->value,
'nodeAggregateId' => $this->nodeAggregateId->value,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint->toJson(),
'originDimensionSpacePointHash' => $this->originDimensionSpacePoint->hash,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint?->toJson(),
'originDimensionSpacePointHash' => $this->originDimensionSpacePoint?->hash ?: 'AGGREGATE',
'created' => (int)$this->created,
'changed' => (int)$this->changed,
'moved' => (int)$this->moved,
Expand All @@ -84,8 +84,8 @@ public function updateToDatabase(Connection $databaseConnection, string $tableNa
[
'contentStreamId' => $this->contentStreamId->value,
'nodeAggregateId' => $this->nodeAggregateId->value,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint->toJson(),
'originDimensionSpacePointHash' => $this->originDimensionSpacePoint->hash,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint?->toJson(),
'originDimensionSpacePointHash' => $this->originDimensionSpacePoint?->hash ?: 'AGGREGATE',
]
);
} catch (DbalException $e) {
Expand All @@ -101,7 +101,9 @@ public static function fromDatabaseRow(array $databaseRow): self
return new self(
ContentStreamId::fromString($databaseRow['contentStreamId']),
NodeAggregateId::fromString($databaseRow['nodeAggregateId']),
OriginDimensionSpacePoint::fromJsonString($databaseRow['originDimensionSpacePoint']),
$databaseRow['originDimensionSpacePoint'] ?? null
? OriginDimensionSpacePoint::fromJsonString($databaseRow['originDimensionSpacePoint'])
: null,
(bool)$databaseRow['created'],
(bool)$databaseRow['changed'],
(bool)$databaseRow['moved'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private function determineRequiredSqlStatements(): array
(new Column('moved', Type::getType(Types::BOOLEAN)))->setNotnull(true),
DbalSchemaFactory::columnForNodeAggregateId('nodeAggregateId')->setNotnull(true),
DbalSchemaFactory::columnForDimensionSpacePoint('originDimensionSpacePoint')->setNotnull(false),
DbalSchemaFactory::columnForDimensionSpacePointHash('originDimensionSpacePointHash')->setNotnull(false),
DbalSchemaFactory::columnForDimensionSpacePointHash('originDimensionSpacePointHash')->setNotnull(true),
(new Column('deleted', Type::getType(Types::BOOLEAN)))->setNotnull(true),
// Despite the name suggesting this might be an anchor point of sorts, this is a nodeAggregateId type
DbalSchemaFactory::columnForNodeAggregateId('removalAttachmentPoint')->setNotnull(false)
Expand Down
8 changes: 6 additions & 2 deletions Neos.Workspace.Ui/Classes/Controller/WorkspaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Doctrine\DBAL\Exception as DBALException;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists;
use Neos\ContentRepository\Core\Feature\WorkspaceModification\Command\DeleteWorkspace;
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Command\DiscardIndividualNodesFromWorkspace;
Expand Down Expand Up @@ -684,6 +685,9 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
->findByContentStreamId(
$selectedWorkspace->currentContentStreamId
);
$dimensionSpacePoints = iterator_to_array($contentRepository->getVariationGraph()->getDimensionSpacePoints());
/** @var DimensionSpacePoint $arbitraryDimensionSpacePoint */
$arbitraryDimensionSpacePoint = reset($dimensionSpacePoints);

foreach ($changes as $change) {
$workspaceName = $selectedWorkspace->workspaceName;
Expand All @@ -697,7 +701,7 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
$workspaceName = $baseWorkspace->workspaceName;
}
$subgraph = $contentRepository->getContentGraph($workspaceName)->getSubgraph(
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
$change->originDimensionSpacePoint?->toDimensionSpacePoint() ?: $arbitraryDimensionSpacePoint,
VisibilityConstraints::withoutRestrictions()
);

Expand Down Expand Up @@ -765,7 +769,7 @@ protected function computeSiteChanges(Workspace $selectedWorkspace, ContentRepos
$nodeAddress = NodeAddress::create(
$contentRepository->id,
$selectedWorkspace->workspaceName,
$change->originDimensionSpacePoint->toDimensionSpacePoint(),
$change->originDimensionSpacePoint?->toDimensionSpacePoint() ?: $arbitraryDimensionSpacePoint,
$change->nodeAggregateId
);

Expand Down

0 comments on commit 4fe6b98

Please sign in to comment.