-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
TetheredNodeInternals.php
151 lines (140 loc) · 7.23 KB
/
TetheredNodeInternals.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
declare(strict_types=1);
namespace Neos\ContentRepository\Core\Feature\Common;
/*
* This file is part of the Neos.ContentRepository package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\Infrastructure\Property\PropertyConverter;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\NodeType\TetheredNodeTypeDefinition;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateClassification;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
/**
* @internal implementation details of command handlers
*/
trait TetheredNodeInternals
{
use NodeVariationInternals;
abstract protected function getPropertyConverter(): PropertyConverter;
abstract protected function createEventsForVariations(
ContentGraphInterface $contentGraph,
OriginDimensionSpacePoint $sourceOrigin,
OriginDimensionSpacePoint $targetOrigin,
NodeAggregate $nodeAggregate
): Events;
/**
* This is the remediation action for non-existing tethered nodes.
* It handles two cases:
* - there is no tethered node IN ANY DimensionSpacePoint -> we can simply create it
* - there is a tethered node already in some DimensionSpacePoint
* -> we need to specialize/generalize/... the other Tethered Node.
* @throws \Exception
*/
protected function createEventsForMissingTetheredNode(
ContentGraphInterface $contentGraph,
NodeAggregate $parentNodeAggregate,
OriginDimensionSpacePoint $originDimensionSpacePoint,
TetheredNodeTypeDefinition $tetheredNodeTypeDefinition,
?NodeAggregateId $tetheredNodeAggregateId
): Events {
$childNodeAggregate = $contentGraph->findChildNodeAggregateByName(
$parentNodeAggregate->nodeAggregateId,
$tetheredNodeTypeDefinition->name
);
$expectedTetheredNodeType = $this->nodeTypeManager->getNodeType($tetheredNodeTypeDefinition->nodeTypeName);
$defaultProperties = $expectedTetheredNodeType
? SerializedPropertyValues::defaultFromNodeType($expectedTetheredNodeType, $this->getPropertyConverter())
: SerializedPropertyValues::createEmpty();
if ($childNodeAggregate === null) {
// there is no tethered child node aggregate already; let's create it!
$nodeType = $this->nodeTypeManager->getNodeType($parentNodeAggregate->nodeTypeName);
if ($nodeType?->isOfType(NodeTypeName::ROOT_NODE_TYPE_NAME)) {
$events = [];
$tetheredNodeAggregateId = $tetheredNodeAggregateId ?: NodeAggregateId::create();
// we create in one origin DSP and vary in the others
$creationOriginDimensionSpacePoint = null;
foreach ($this->getInterDimensionalVariationGraph()->getRootGeneralizations() as $rootGeneralization) {
$rootGeneralizationOrigin = OriginDimensionSpacePoint::fromDimensionSpacePoint($rootGeneralization);
if ($creationOriginDimensionSpacePoint) {
$events[] = new NodePeerVariantWasCreated(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$tetheredNodeAggregateId,
$creationOriginDimensionSpacePoint,
$rootGeneralizationOrigin,
InterdimensionalSiblings::fromDimensionSpacePointSetWithoutSucceedingSiblings(
$this->getInterDimensionalVariationGraph()->getSpecializationSet($rootGeneralization),
)
);
} else {
$events[] = new NodeAggregateWithNodeWasCreated(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$tetheredNodeAggregateId,
$tetheredNodeTypeDefinition->nodeTypeName,
$rootGeneralizationOrigin,
InterdimensionalSiblings::fromDimensionSpacePointSetWithoutSucceedingSiblings(
$this->getInterDimensionalVariationGraph()->getSpecializationSet($rootGeneralization)
),
$parentNodeAggregate->nodeAggregateId,
$tetheredNodeTypeDefinition->name,
$defaultProperties,
NodeAggregateClassification::CLASSIFICATION_TETHERED,
);
$creationOriginDimensionSpacePoint = $rootGeneralizationOrigin;
}
}
return Events::fromArray($events);
}
return Events::with(
new NodeAggregateWithNodeWasCreated(
$contentGraph->getWorkspaceName(),
$contentGraph->getContentStreamId(),
$tetheredNodeAggregateId ?: NodeAggregateId::create(),
$tetheredNodeTypeDefinition->nodeTypeName,
$originDimensionSpacePoint,
InterdimensionalSiblings::fromDimensionSpacePointSetWithoutSucceedingSiblings(
$parentNodeAggregate->getCoverageByOccupant($originDimensionSpacePoint)
),
$parentNodeAggregate->nodeAggregateId,
$tetheredNodeTypeDefinition->name,
$defaultProperties,
NodeAggregateClassification::CLASSIFICATION_TETHERED,
)
);
}
if (!$childNodeAggregate->classification->isTethered()) {
throw new \RuntimeException(
'We found a child node aggregate through the given node path; but it is not tethered.'
. ' We do not support re-tethering yet'
. ' (as this case should happen very rarely as far as we think).'
);
}
$childNodeSource = null;
foreach ($childNodeAggregate->getNodes() as $node) {
$childNodeSource = $node;
break;
}
/** @var Node $childNodeSource Node aggregates are never empty */
return $this->createEventsForVariations(
$contentGraph,
$childNodeSource->originDimensionSpacePoint,
$originDimensionSpacePoint,
$parentNodeAggregate
);
}
}