Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
skurfuerst committed Nov 14, 2023
1 parent 872f1ee commit 47c9523
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\SerializedPropertyValues;
Expand Down Expand Up @@ -84,12 +85,14 @@ protected function createEventsForMissingTetheredNode(
foreach ($this->getInterDimensionalVariationGraph()->getRootGeneralizations() as $rootGeneralization) {
$rootGeneralizationOrigin = OriginDimensionSpacePoint::fromDimensionSpacePoint($rootGeneralization);
if ($creationOriginDimensionSpacePoint) {
$specializations = $this->getInterDimensionalVariationGraph()->getSpecializationSet($rootGeneralization);
$events[] = new NodePeerVariantWasCreated(
$parentNodeAggregate->contentStreamId,
$tetheredNodeAggregateId,
$creationOriginDimensionSpacePoint,
$rootGeneralizationOrigin,
$this->getInterDimensionalVariationGraph()->getSpecializationSet($rootGeneralization)
$specializations,
array_map(fn(DimensionSpacePoint $dimensionSpacePoint) $specializations)
);
} else {
$events[] = new NodeAggregateWithNodeWasCreated(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto;

use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;

/**
* See the docs of {@see NodePeerVariantWasCreated} and {@see NodeGeneralizationVariantWasCreated} for a full description.
*
* @api DTO of {@see NodeAggregateWasMoved} event
*/
final class CoverageNodeVariantMapping implements \JsonSerializable
{
private function __construct(
public readonly DimensionSpacePoint $coveredDimensionSpacePoint,
public readonly SucceedingSiblingVariantPosition|EndSiblingVariantPosition $destination,
) {
}

public static function createForNewSucceedingSibling(
DimensionSpacePoint $coveredDimensionSpacePoint,
SucceedingSiblingVariantPosition $newSucceedingSibling
): self {
return new self($coveredDimensionSpacePoint, $newSucceedingSibling);
}

public static function createForNewEndSibling(
DimensionSpacePoint $coveredDimensionSpacePoint,
EndSiblingVariantPosition $newSucceedingSibling
): self {
return new self($coveredDimensionSpacePoint, $newSucceedingSibling);
}

/**
* @param array<string,mixed> $array
*/
public static function fromArray(array $array): self
{
if (!empty($array['newSucceedingSibling'])) {
return new self(
DimensionSpacePoint::fromArray($array['coveredDimensionSpacePoint']),
SucceedingSiblingVariantPosition::fromArray($array['newSucceedingSibling']),
);
} elseif (!empty($array['endSibling'])) {
return new self(
DimensionSpacePoint::fromArray($array['coveredDimensionSpacePoint']),
EndSiblingVariantPosition::create(),
);
} else {
throw new \RuntimeException('!!!');
}
}

/**
* @return array<string,mixed>
*/
public function jsonSerialize(): array
{
if ($this->destination instanceof SucceedingSiblingVariantPosition) {
return [
'coveredDimensionSpacePoint' => $this->coveredDimensionSpacePoint,
'newSucceedingSibling' => $this->destination
];
} elseif ($this->destination instanceof EndSiblingVariantPosition) {
return [
'endSibling' => true,
];
} else {
throw new \RuntimeException('!!!');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/*
* This file is part of the Neos.ContentRepository.Core 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.
*/

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto;

/**
* @implements \IteratorAggregate<int,CoverageNodeMoveMapping>
* @api DTO of {@see NodeAggregateWasMoved} event
*/
final class CoverageNodeVariantMappings implements \IteratorAggregate, \Countable, \JsonSerializable
{
/**
* @var array<int,CoverageNodeMoveMapping>
*/
private array $mappings;

/**
* @param array<int,CoverageNodeMoveMapping> $values
*/
private function __construct(array $values)
{
$this->mappings = $values;
}

/**
* @param array<int|string,array<string,mixed>|CoverageNodeMoveMapping> $mappings
*/
public static function fromArray(array $mappings): self
{
$processedMappings = [];
foreach ($mappings as $mapping) {
if (is_array($mapping)) {
$processedMappings[] = CoverageNodeMoveMapping::fromArray($mapping);
} elseif ($mapping instanceof CoverageNodeMoveMapping) {
$processedMappings[] = $mapping;
} else {
/** @var mixed $mapping */
throw new \InvalidArgumentException(
sprintf(
'Invalid NodeMoveMapping. Expected instance of %s, got: %s',
CoverageNodeMoveMapping::class,
is_object($mapping) ? get_class($mapping) : gettype($mapping)
),
1547811318
);
}
}
return new self($processedMappings);
}

public static function create(CoverageNodeMoveMapping ...$coverageNodeMoveMappings): self
{
return new self(array_values($coverageNodeMoveMappings));
}


/**
* @return \Traversable<int,CoverageNodeMoveMapping>
*/
public function getIterator(): \Traversable
{
yield from $this->mappings;
}

public function count(): int
{
return count($this->mappings);
}

/**
* @return array<int,CoverageNodeMoveMapping>
*/
public function jsonSerialize(): array
{
return $this->mappings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* 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.
*/

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto;

use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;

/**
* See the docs of {@see NodePeerVariantWasCreated} for a full description.
*
* @api DTO of {@see NodePeerVariantWasCreated} and {@see NodeGeneralizationVariantWasCreated} event
*/
final class EndSiblingVariantPosition implements \JsonSerializable
{
private function __construct(
) {
}

public static function create(
): self {
return new self(
);
}

/**
* @param array<string,mixed> $array
*/
public static function fromArray(array $array): self
{
return new self(
);
}

/**
* @return array<string,\JsonSerializable>
*/
public function jsonSerialize(): array
{
return [
];
}

public function toJson(): string
{
return json_encode($this, JSON_THROW_ON_ERROR);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* 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.
*/

declare(strict_types=1);

namespace Neos\ContentRepository\Core\Feature\NodeVariation\Dto;

use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodeGeneralizationVariantWasCreated;
use Neos\ContentRepository\Core\Feature\NodeVariation\Event\NodePeerVariantWasCreated;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;

/**
* See the docs of {@see NodePeerVariantWasCreated} for a full description.
*
* @api DTO of {@see NodePeerVariantWasCreated} and {@see NodeGeneralizationVariantWasCreated} event
*/
final class SucceedingSiblingVariantPosition implements \JsonSerializable
{
private function __construct(
public readonly NodeAggregateId $nodeAggregateId,
public readonly OriginDimensionSpacePoint $originDimensionSpacePoint,
) {
}

public static function create(
NodeAggregateId $nodeAggregateId,
OriginDimensionSpacePoint $originDimensionSpacePoint,
): self {
return new self(
$nodeAggregateId,
$originDimensionSpacePoint,
);
}

/**
* @param array<string,mixed> $array
*/
public static function fromArray(array $array): self
{
return new self(
NodeAggregateId::fromString($array['nodeAggregateId']),
OriginDimensionSpacePoint::fromArray($array['originDimensionSpacePoint']),
);
}

/**
* @return array<string,\JsonSerializable>
*/
public function jsonSerialize(): array
{
return [
'nodeAggregateId' => $this->nodeAggregateId,
'originDimensionSpacePoint' => $this->originDimensionSpacePoint,
];
}

public function toJson(): string
{
return json_encode($this, JSON_THROW_ON_ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\Common\EmbedsContentStreamAndNodeAggregateId;
use Neos\ContentRepository\Core\Feature\Common\PublishableToOtherContentStreamsInterface;
use Neos\ContentRepository\Core\Feature\NodeMove\Dto\CoverageNodeMoveMapping;
use Neos\ContentRepository\Core\Feature\NodeVariation\Dto\CoverageNodeVariantMapping;
use Neos\ContentRepository\Core\Feature\NodeVariation\Dto\CoverageNodeVariantMappings;
use Neos\ContentRepository\Core\Feature\NodeVariation\Dto\EndSiblingVariantPosition;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;

Expand All @@ -27,6 +31,16 @@
*
* This event means: "Copy all properties (and references) of the given node from the source to the target dimension."
*
* ## Positioning of Nodes across variants
*
* When translating content, e.g. from en to de, we effectively make a new node visible in all dimensions
* specified by {@see $peerCoverage} (i.e. we create **new edges** in the Content Graph). Because the edges
* contain positioning information ("I am 3rd child", ...), we need to specify exactly where the new edges
* should go to; as there might be different nodes and different sortings existing in all the different
* target dimensions.
*
* TODO: ALSO PARENT NODE AGG ID?? OR ONLY SUCC SIBLING?? ({@see SucceedingSiblingNodeMoveDestination})
*
*
* ## Background: What is Node Variation?
*
Expand Down Expand Up @@ -87,8 +101,12 @@ public function __construct(
* Because {@see $peerOrigin} can have nested dimensions underneath (e.g. in the example above from `en` to `de`)
* this is the multiplied-out list of dimensions where the translation will be *visible in*. Will at least
* contain {@see $peerOrigin}, but could have additional dimensions as well.
*
* TODO: REMOVE THIS, and create positionMappings from it?
*/
public readonly DimensionSpacePointSet $peerCoverage,
public readonly DimensionSpacePointSet $peerCoverage, // DEPRECATED

public readonly CoverageNodeVariantMappings $positionMappings,
) {
}

Expand All @@ -110,17 +128,32 @@ public function createCopyForContentStream(ContentStreamId $targetContentStreamI
$this->sourceOrigin,
$this->peerOrigin,
$this->peerCoverage,
$this->positionMappings,
);
}

public static function fromArray(array $values): self
{
if (!isset($values['positionMappings'])) {
// TODO: if peerCoverage and no positionMappings, create peerCoverage with type "end"

// DEPRECATED
$coverageNodeVariantMappings = [];
foreach (DimensionSpacePointSet::fromArray($values['peerCoverage'])->getIterator() as $dimensionSpacePoint) {
$coverageNodeVariantMappings[] = CoverageNodeVariantMapping::createForNewEndSibling($dimensionSpacePoint, EndSiblingVariantPosition::create());
}
$coverageNodeVariantMappings = CoverageNodeVariantMappings::create(...$coverageNodeVariantMappings);
} else {
$coverageNodeVariantMappings = CoverageNodeVariantMappings::fromArray($values['positionMappings']);
}

return new self(
ContentStreamId::fromString($values['contentStreamId']),
NodeAggregateId::fromString($values['nodeAggregateId']),
OriginDimensionSpacePoint::fromArray($values['sourceOrigin']),
OriginDimensionSpacePoint::fromArray($values['peerOrigin']),
DimensionSpacePointSet::fromArray($values['peerCoverage']),
DimensionSpacePointSet::fromArray($values['peerCoverage']), // DEPRECATED
$coverageNodeVariantMappings,
);
}

Expand Down

0 comments on commit 47c9523

Please sign in to comment.