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:Site NodeType #4563

Merged
merged 17 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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 @@ -46,14 +46,13 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\NodePath;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePointSet;
use Neos\ContentRepository\Core\SharedModel\Node\PropertyName;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\Flow\Persistence\Doctrine\DataTypes\JsonArrayType;
use Neos\Flow\Property\PropertyMapper;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Ramsey\Uuid\Uuid;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -88,7 +87,7 @@ public function __construct(
private readonly Filesystem $files,
private readonly iterable $nodeDataRows,
) {
$this->sitesNodeTypeName = NodeTypeName::fromString('Neos.Neos:Sites');
$this->sitesNodeTypeName = NodeTypeNameFactory::forSites();
$this->contentStreamId = ContentStreamId::create();
$this->visitedNodes = new VisitedNodeAggregates();
}
Expand All @@ -100,6 +99,13 @@ public function setContentStreamId(ContentStreamId $contentStreamId): void

public function setSitesNodeType(NodeTypeName $nodeTypeName): void
{
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
if (!$nodeType->isOfType(NodeTypeNameFactory::NAME_SITES)) {
throw new \InvalidArgumentException(
sprintf('Sites NodeType "%s" must be of type "%s"', $nodeTypeName->value, NodeTypeNameFactory::NAME_SITES),
1695802415
);
}
$this->sitesNodeTypeName = $nodeTypeName;
}

Expand Down Expand Up @@ -244,6 +250,13 @@ public function processNodeDataWithoutFallbackToEmptyDimension(NodeAggregateId $
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);
$serializedPropertyValuesAndReferences = $this->extractPropertyValuesAndReferences($nodeDataRow, $nodeType);

$isSiteNode = $nodeDataRow['parentpath'] === '/sites';
if ($isSiteNode && !$nodeType->isOfType(NodeTypeNameFactory::NAME_SITE)) {
throw new MigrationException(sprintf(
'The site node "%s" (type: "%s") must be of type "%s"', $nodeDataRow['identifier'], $nodeTypeName->value, NodeTypeNameFactory::NAME_SITE
), 1695801620);
}

if ($this->isAutoCreatedChildNode($parentNodeAggregate->nodeTypeName, $nodeName) && !$this->visitedNodes->containsNodeAggregate($nodeAggregateId)) {
// Create tethered node if the node was not found before.
// If the node was already visited, we want to create a node variant (and keep the tethering status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ Feature: Export of used Assets, Image Variants and Persistent Resources
And using the following node types:
"""yaml
'unstructured': {}
'Some.Package:SomeNodeType':
'Neos.Neos:Site': {}
'Some.Package:Homepage':
superTypes:
'Neos.Neos:Site': true
properties:
'string':
type: string
Expand Down Expand Up @@ -43,7 +46,7 @@ Feature: Export of used Assets, Image Variants and Persistent Resources
When I have the following node data rows:
| Identifier | Path | Node Type | Properties |
| sites-node-id | /sites | unstructured | |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"string": "asset:\/\/variant1"} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"string": "asset:\/\/variant1"} |
And I run the asset migration
Then I expect the following Assets to be exported:
"""
Expand Down Expand Up @@ -87,10 +90,10 @@ Feature: Export of used Assets, Image Variants and Persistent Resources
When I have the following node data rows:
| Identifier | Path | Node Type | Dimension Values | Properties |
| sites-node-id | /sites | unstructured | | |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | | {"string": "asset:\/\/asset1"} |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"language": ["ch"]} | {"image": {"__flow_object_type": "Neos\\Media\\Domain\\Model\\Image", "__identifier": "asset2"}} |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"language": ["en"]} | {"assets": [{"__flow_object_type": "Neos\\Media\\Domain\\Model\\Document", "__identifier": "asset3"}, {"__flow_object_type": "Neos\\Media\\Domain\\Model\\Image", "__identifier": "asset2"}, {"__flow_object_type": "Neos\\Media\\Domain\\Model\\ImageVariant", "__identifier": "variant1"}]} |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"language": ["de"]} | {"string": "some text with an <a href=\"asset:\/\/asset4\">asset link</a>"} |
| site-node-id | /sites/test-site | Some.Package:Homepage | | {"string": "asset:\/\/asset1"} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["ch"]} | {"image": {"__flow_object_type": "Neos\\Media\\Domain\\Model\\Image", "__identifier": "asset2"}} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["en"]} | {"assets": [{"__flow_object_type": "Neos\\Media\\Domain\\Model\\Document", "__identifier": "asset3"}, {"__flow_object_type": "Neos\\Media\\Domain\\Model\\Image", "__identifier": "asset2"}, {"__flow_object_type": "Neos\\Media\\Domain\\Model\\ImageVariant", "__identifier": "variant1"}]} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["de"]} | {"string": "some text with an <a href=\"asset:\/\/asset4\">asset link</a>"} |
And I run the asset migration
Then I expect the following Assets to be exported:
"""
Expand Down Expand Up @@ -178,10 +181,10 @@ Feature: Export of used Assets, Image Variants and Persistent Resources
When I have the following node data rows:
| Identifier | Path | Node Type | Properties |
| sites-node-id | /sites | unstructured | |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"string": "asset:\/\/non-existing-asset"} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"string": "asset:\/\/non-existing-asset"} |
And I run the asset migration
Then I expect no Assets to be exported
And I expect no ImageVariants to be exported
And I expect no PersistentResources to be exported
And I expect the following errors to be logged
| Failed to extract assets of property "string" of node "site-node-id" (type: "Some.Package:SomeNodeType"): Failed to find mock asset with id "non-existing-asset" |
| Failed to extract assets of property "string" of node "site-node-id" (type: "Some.Package:Homepage"): Failed to find mock asset with id "non-existing-asset" |
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Feature: Simple migrations without content dimensions
Given using no content dimensions
And using the following node types:
"""yaml
'Some.Package:SomeNodeType':
'unstructured': {}
'Neos.Neos:Site': {}
'Some.Package:Homepage':
superTypes:
'Neos.Neos:Site': true
properties:
'text':
type: string
Expand All @@ -18,9 +22,9 @@ Feature: Simple migrations without content dimensions
When I have the following node data rows:
| Identifier | Path | Node Type | Properties |
| sites-node-id | /sites | unstructured | |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"text": "foo"} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"text": "foo"} |
And I run the event migration for content stream "cs-id"
Then I expect the following events to be exported
| Type | Payload |
| RootNodeAggregateWithNodeWasCreated | {"contentStreamId": "cs-id", "nodeAggregateId": "sites-node-id", "nodeTypeName": "Neos.Neos:Sites", "nodeAggregateClassification": "root"} |
| NodeAggregateWithNodeWasCreated | {"contentStreamId": "cs-id", "nodeAggregateId": "site-node-id", "nodeTypeName": "Some.Package:SomeNodeType", "nodeName": "test-site", "parentNodeAggregateId": "sites-node-id", "nodeAggregateClassification": "regular", "initialPropertyValues": {"text": {"type": "string", "value": "foo"}}} |
| NodeAggregateWithNodeWasCreated | {"contentStreamId": "cs-id", "nodeAggregateId": "site-node-id", "nodeTypeName": "Some.Package:Homepage", "nodeName": "test-site", "parentNodeAggregateId": "sites-node-id", "nodeAggregateClassification": "regular", "initialPropertyValues": {"text": {"type": "string", "value": "foo"}}} |
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ Feature: Exceptional cases during migrations
Given using no content dimensions
And using the following node types:
"""yaml
'unstructured': []
'Some.Package:SomeNodeType':
'unstructured': {}
'Neos.Neos:Site': {}
'Some.Package:Homepage':
superTypes:
'Neos.Neos:Site': true
properties:
'text':
type: string
defaultValue: 'My default text'
'Some.Package:SomeOtherNodeType': []
'Some.Package:SomeNodeType':
properties:
'text':
type: string
'Some.Package:SomeOtherHomepage':
superTypes:
'Neos.Neos:Site': true
"""
And using identifier "default", I define a content repository
And I am in content repository "default"
Expand All @@ -23,44 +32,44 @@ Feature: Exceptional cases during migrations
When I have the following node data rows:
| Identifier | Path | Node Type | Dimension Values |
| sites-node-id | /sites | unstructured | |
| site-node-id | /sites/test-site | Some.Package:SomeNodeType | {"language": ["de"]} |
| site-node-id | /sites/test-site | Some.Package:SomeOtherNodeType | {"language": ["en"]} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["de"]} |
| site-node-id | /sites/test-site | Some.Package:SomeOtherHomepage | {"language": ["en"]} |
And I run the event migration
Then I expect a MigrationError with the message
"""
Node aggregate with id "site-node-id" has a type of "Some.Package:SomeOtherNodeType" in content dimension [{"language":"en"}]. I was visited previously for content dimension [{"language":"de"}] with the type "Some.Package:SomeNodeType". Node variants must not have different types
Node aggregate with id "site-node-id" has a type of "Some.Package:SomeOtherHomepage" in content dimension [{"language":"en"}]. I was visited previously for content dimension [{"language":"de"}] with the type "Some.Package:Homepage". Node variants must not have different types
"""

# Note: The behavior was changed with https://github.com/neos/neos-development-collection/pull/4201
Scenario: Node with missing parent
When I have the following node data rows:
| Identifier | Path |
| sites | /sites |
| a | /sites/a |
| c | /sites/b/c |
| Identifier | Path | Node Type |
| sites | /sites | unstructured |
| a | /sites/a | Some.Package:Homepage |
| c | /sites/b/c | unstructured |
And I run the event migration
Then I expect the following events to be exported
| Type | Payload |
| RootNodeAggregateWithNodeWasCreated | {"nodeAggregateId": "sites", "nodeTypeName": "Neos.Neos:Sites", "nodeAggregateClassification": "root"} |
| NodeAggregateWithNodeWasCreated | {"nodeAggregateId": "a", "parentNodeAggregateId": "sites"} |
| NodeAggregateWithNodeWasCreated | {"nodeAggregateId": "a", "nodeTypeName": "Some.Package:Homepage", "parentNodeAggregateId": "sites"} |
And I expect the following errors to be logged
| Failed to find parent node for node with id "c" and dimensions: []. Please ensure that the new content repository has a valid content dimension configuration. Also note that the old CR can sometimes have orphaned nodes. |


# Note: The behavior was changed with https://github.com/neos/neos-development-collection/pull/4201
Scenario: Nodes out of order
When I have the following node data rows:
| Identifier | Path |
| sites | /sites |
| a | /sites/a |
| c | /sites/b/c |
| b | /sites/b |
| Identifier | Path | Node Type |
| sites | /sites | unstructured |
| a | /sites/a | Some.Package:Homepage |
| c | /sites/b/c | unstructured |
| b | /sites/b | Some.Package:Homepage |
And I run the event migration
Then I expect the following events to be exported
| Type | Payload |
| RootNodeAggregateWithNodeWasCreated | {"nodeAggregateId": "sites", "nodeTypeName": "Neos.Neos:Sites", "nodeAggregateClassification": "root"} |
| NodeAggregateWithNodeWasCreated | {"nodeAggregateId": "a", "parentNodeAggregateId": "sites"} |
| NodeAggregateWithNodeWasCreated | {"nodeAggregateId": "b", "parentNodeAggregateId": "sites"} |
| NodeAggregateWithNodeWasCreated | {"nodeAggregateId": "a", "nodeTypeName": "Some.Package:Homepage", "parentNodeAggregateId": "sites"} |
| NodeAggregateWithNodeWasCreated | {"nodeAggregateId": "b", "nodeTypeName": "Some.Package:Homepage", "parentNodeAggregateId": "sites"} |
And I expect the following errors to be logged
| Failed to find parent node for node with id "c" and dimensions: []. Please ensure that the new content repository has a valid content dimension configuration. Also note that the old CR can sometimes have orphaned nodes. |

Expand Down Expand Up @@ -104,11 +113,11 @@ Feature: Exceptional cases during migrations
| Identifier | Default | Values | Generalizations |
| language | en | en, de, ch | ch->de |
When I have the following node data rows:
| Identifier | Path | Dimension Values |
| sites-node-id | /sites | |
| site-node-id | /sites/test-site | {"language": ["de"]} |
| site-node-id | /sites/test-site | {"language": ["ch"]} |
| site-node-id | /sites/test-site | {"language": ["ch"]} |
| Identifier | Path | Node Type | Dimension Values |
| sites-node-id | /sites | unstructured | |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["de"]} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["ch"]} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["ch"]} |
And I run the event migration
Then I expect a MigrationError with the message
"""
Expand All @@ -120,12 +129,23 @@ Feature: Exceptional cases during migrations
| Identifier | Default | Values | Generalizations |
| language | en | en, de, ch | ch->de |
When I have the following node data rows:
| Identifier | Path | Dimension Values |
| sites-node-id | /sites | |
| site-node-id | /sites/test-site | {"language": ["de"]} |
| site-node-id | /sites/test-site | {"language": ["de"]} |
| Identifier | Path | Node Type | Dimension Values |
| sites-node-id | /sites | unstructured | |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["de"]} |
| site-node-id | /sites/test-site | Some.Package:Homepage | {"language": ["de"]} |
And I run the event migration
Then I expect a MigrationError with the message
"""
Node "site-node-id" for dimension {"language":"de"} was already created previously
"""

Scenario: Homepage node is not of type "Neos.Neos:Site"
When I have the following node data rows:
| Identifier | Path | Node Type |
| sites-node-id | /sites | unstructured |
| site-node-id | /sites/test-site | unstructured |
And I run the event migration
Then I expect a MigrationError with the message
"""
The site node "site-node-id" (type: "unstructured") must be of type "Neos.Neos:Site"
"""
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Feature: Migrations that contain nodes with "reference" or "references propertie
Given using no content dimensions
And using the following node types:
"""yaml
'Some.Package:Homepage': []
'unstructured': {}
'Neos.Neos:Site': {}
'Some.Package:Homepage':
superTypes:
'Neos.Neos:Site': true
'Some.Package:SomeNodeType':
properties:
'text':
Expand Down
Loading
Loading