Skip to content

Commit

Permalink
Merge pull request #4559 from neos/nodeTypeFallbackHandling-review
Browse files Browse the repository at this point in the history
TASK: Review of "Node type fallback handling"
  • Loading branch information
mhsdesign authored Sep 25, 2023
2 parents faf4419 + e20071e commit 552a40a
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\Utility\ContentRepositoryRegistryProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Security\Context as SecurityContext;
use Neos\Neos\Utility\NodeTypeWithFallbackProvider;
Expand All @@ -27,9 +27,11 @@
*/
class NodePrivilegeContext
{
use ContentRepositoryRegistryProvider;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var SecurityContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePointSet;
use Neos\ContentRepository\Core\EventStore\Events;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Feature\ContentStreamEventStreamName;
use Neos\ContentRepository\Core\Feature\NodeRemoval\Event\NodeAggregateWasRemoved;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePointSet;
use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\SharedModel\User\UserId;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeAggregate;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\EventStore\Model\EventStream\ExpectedVersion;

class DisallowedChildNodeAdjustment
{
use RemoveNodeAggregateTrait;
use LoadNodeTypeTrait;

public function __construct(
private readonly ContentRepository $contentRepository,
Expand All @@ -37,19 +35,17 @@ public function __construct(
*/
public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generator
{
$nodeType = $this->loadNodeType($nodeTypeName);

if ($nodeType === null) {
if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) {
// no adjustments for unknown node types
return;
}

foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) {
$nodeType = $this->loadNodeType($nodeAggregate->nodeTypeName);
if ($nodeType === null) {
if (!$this->nodeTypeManager->hasNodeType($nodeAggregate->nodeTypeName)) {
// unknown child node type, so we skip this test as we won't be able to find out node type constraints
continue;
}
$nodeType = $this->nodeTypeManager->getNodeType($nodeAggregate->nodeTypeName);

// Here, we iterate over the covered dimension space points of the node aggregate one by one;
// as it can happen that the constraint is only violated in e.g. "AT", but not in "DE".
Expand All @@ -70,8 +66,8 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat
$allowedByParent = true;
$parentNodeType = null;
if ($parentNode !== null) {
$parentNodeType = $this->loadNodeType($parentNode->nodeTypeName);
if ($parentNodeType !== null) {
if ($this->nodeTypeManager->hasNodeType($parentNode->nodeTypeName)) {
$parentNodeType = $this->nodeTypeManager->getNodeType($parentNode->nodeTypeName);
$allowedByParent = $parentNodeType->allowsChildNodeType($nodeType);
}
}
Expand All @@ -84,8 +80,8 @@ public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generat
&& $parentNode->classification->isTethered()
&& !is_null($parentNode->nodeName)
) {
$grandparentNodeType = $this->loadNodeType($grandparentNode->nodeTypeName);
if ($grandparentNodeType !== null) {
if ($this->nodeTypeManager->hasNodeType($grandparentNode->nodeTypeName)) {
$grandparentNodeType = $this->nodeTypeManager->getNodeType($grandparentNode->nodeTypeName);
$allowedByGrandparent = $grandparentNodeType->allowsGrandchildNodeType(
$parentNode->nodeName->value,
$nodeType
Expand Down Expand Up @@ -153,9 +149,4 @@ private function removeNodeInSingleDimensionSpacePoint(
ExpectedVersion::ANY()
);
}

protected function getNodeTypeManager(): NodeTypeManager
{
return $this->nodeTypeManager;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

class PropertyAdjustment
{
use LoadNodeTypeTrait;

public function __construct(
private readonly ProjectedNodeIterator $projectedNodeIterator,
private readonly NodeTypeManager $nodeTypeManager
Expand All @@ -31,11 +29,12 @@ public function __construct(
*/
public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generator
{
$nodeType = $this->loadNodeType($nodeTypeName);
if ($nodeType === null) {
if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) {
// In case we cannot find the expected tethered nodes, this fix cannot do anything.
return;
}
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);

$expectedPropertiesFromNodeType = array_filter($nodeType->getProperties(), fn ($value) => $value !== null);

foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) {
Expand Down Expand Up @@ -132,9 +131,4 @@ private function publishNodePropertiesWereSet(
ExpectedVersion::ANY()
);
}

protected function getNodeTypeManager(): NodeTypeManager
{
return $this->nodeTypeManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TetheredNodeAdjustments
{
use NodeVariationInternals;
use RemoveNodeAggregateTrait;
use LoadNodeTypeTrait;
use TetheredNodeInternals;

public function __construct(
Expand All @@ -48,11 +47,12 @@ public function __construct(
*/
public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generator
{
$nodeType = $this->loadNodeType($nodeTypeName);
if ($nodeType === null) {
if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) {
// In case we cannot find the expected tethered nodes, this fix cannot do anything.
return;
}
$nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName);

$expectedTetheredNodes = $nodeType->getAutoCreatedChildNodes();

foreach ($this->projectedNodeIterator->nodeAggregatesOfType($nodeTypeName) as $nodeAggregate) {
Expand Down Expand Up @@ -204,11 +204,6 @@ protected function getInterDimensionalVariationGraph(): DimensionSpace\InterDime
return $this->interDimensionalVariationGraph;
}

protected function getNodeTypeManager(): NodeTypeManager
{
return $this->nodeTypeManager;
}

/**
* array key: name of tethered child node. Value: the Node itself.
* @param array<string,Node> $actualTetheredChildNodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class UnknownNodeTypeAdjustment
{
use RemoveNodeAggregateTrait;
use LoadNodeTypeTrait;

public function __construct(
private readonly ProjectedNodeIterator $projectedNodeIterator,
Expand All @@ -23,8 +22,7 @@ public function __construct(
*/
public function findAdjustmentsForNodeType(NodeTypeName $nodeTypeName): \Generator
{
$nodeType = $this->loadNodeType($nodeTypeName);
if ($nodeType === null) {
if (!$this->nodeTypeManager->hasNodeType($nodeTypeName)) {
// node type is not existing right now.
yield from $this->removeAllNodesOfType($nodeTypeName);
}
Expand All @@ -47,9 +45,4 @@ function () use ($nodeAggregate) {
);
}
}

protected function getNodeTypeManager(): NodeTypeManager
{
return $this->nodeTypeManager;
}
}

This file was deleted.

6 changes: 4 additions & 2 deletions Neos.Neos/Classes/Controller/Backend/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Neos\Neos\Controller\Backend;

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\Utility\ContentRepositoryRegistryProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
Expand Down Expand Up @@ -52,9 +52,11 @@
class ContentController extends ActionController
{
use BackendUserTranslationTrait;
use ContentRepositoryRegistryProvider;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var AssetRepository
Expand Down
6 changes: 4 additions & 2 deletions Neos.Neos/Classes/Controller/Frontend/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\ContentRepositoryRegistry\Utility\ContentRepositoryRegistryProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Flow\Mvc\Exception\NoMatchingRouteException;
Expand Down Expand Up @@ -52,9 +52,11 @@
*/
class NodeController extends ActionController
{
use ContentRepositoryRegistryProvider;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var PrivilegeManagerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Neos\ContentRepository\Core\Feature\WorkspaceCreation\Exception\WorkspaceAlreadyExists;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindAncestorNodesFilter;
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\I18n\Exception\IndexOutOfBoundsException;
use Neos\Flow\I18n\Exception\InvalidFormatPlaceholderException;
use Neos\Flow\Mvc\Exception\StopActionException;
Expand Down Expand Up @@ -73,6 +74,9 @@ class WorkspacesController extends AbstractModuleController
use ModuleTranslationTrait;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @Flow\Inject
* @var SiteRepository
Expand Down
6 changes: 4 additions & 2 deletions Neos.Neos/Classes/Domain/Service/NodeSiteResolvingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use Neos\ContentRepository\Core\Factory\ContentRepositoryId;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepositoryRegistry\Utility\ContentRepositoryRegistryProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Neos\FrontendRouting\NodeAddress;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\Flow\Annotations as Flow;
Expand All @@ -25,9 +25,11 @@
#[Flow\Scope('singleton')]
class NodeSiteResolvingService
{
use ContentRepositoryRegistryProvider;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

public function findSiteNodeForNodeAddress(
NodeAddress $nodeAddress,
ContentRepositoryId $contentRepositoryId
Expand Down
6 changes: 4 additions & 2 deletions Neos.Neos/Classes/Domain/Service/SiteNodeUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepositoryRegistry\Utility\ContentRepositoryRegistryProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Model\Site;
use Neos\Neos\Domain\Repository\DomainRepository;
Expand All @@ -30,9 +30,11 @@
#[Flow\Scope('singleton')]
final class SiteNodeUtility
{
use ContentRepositoryRegistryProvider;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

public function __construct(
private readonly DomainRepository $domainRepository,
private readonly SiteRepository $siteRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepositoryRegistry\Utility\ContentRepositoryRegistryProvider;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Neos\FrontendRouting\NodeAddressFactory;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Persistence\PersistenceManagerInterface;
Expand All @@ -31,9 +31,11 @@
*/
class ContentRepositoryIntegrationService extends AbstractIntegrationService
{
use ContentRepositoryRegistryProvider;
use NodeTypeWithFallbackProvider;

#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

public const NODE_ADDED = 'Node.Added';
public const NODE_UPDATED = 'Node.Updated';
public const NODE_LABEL_CHANGED = 'Node.LabelChanged';
Expand Down
Loading

0 comments on commit 552a40a

Please sign in to comment.