Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/node-template
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubitz committed Dec 23, 2024
2 parents 3cf9eab + ec19d6b commit 0a363df
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 49 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"tests": "phpunit tests"
},
"require": {
"rector/rector": "0.15.24",
"phpstan/phpstan": "1.10.13",
"rector/rector": "0.15.25",
"phpstan/phpstan": "1.10.14",
"symfony/yaml": "*",
"neos/utility-arrays": "*",
"webmozart/assert": "^1.11"
Expand Down
91 changes: 91 additions & 0 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetAutoCreatedChildNodesRector;
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetNameRector;
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetTypeOfAutoCreatedChildNodeRector;
use Neos\Rector\ContentRepository90\Rules\NodeTypeManagerAccessRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetNameRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryCountByNameRector;
use Neos\Rector\ContentRepository90\Rules\YamlDimensionConfigRector;
Expand Down Expand Up @@ -459,6 +460,96 @@
new ObjectInstantiationToWarningComment(\Neos\ContentRepository\Domain\Model\NodeTemplate::class, '!! NodeTemplate is removed in Neos 9.0. Use the "CreateNodeAggregateWithNode" command to create new nodes or "CreateNodeVariant" command to create variants of an existing node in other dimensions.')]
);

/**
* Neos\ContentRepository\Domain\Service\NodeTypeManager
*/
$rectorConfig->rule(NodeTypeManagerAccessRector::class);
// createNodeType(nodeTypeName: string): NodeType
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Service\NodeTypeManager::class, 'createNodeType', '!! NodeTypeManager::createNodeType() was never implemented and is removed in Neos 9.0.');
// getNodeType(nodeTypeName: string): NodeType
// --> Compatible with 9.0
// getNodeTypes([includeAbstractNodeTypes: bool = true]): NodeType[]
// --> Compatible with 9.0
// getSubNodeTypes(superTypeName: string, [includeAbstractNodeTypes: bool = true]): NodeType[]
// --> Compatible with 9.0
// hasNodeType(nodeTypeName: string): bool
// --> Compatible with 9.0
// overrideNodeTypes(completeNodeTypeConfiguration: array): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Service\NodeTypeManager::class, 'overrideNodeTypes', '!! NodeTypeManager::createNodeType() was never meant to be used outside of testing and is removed in Neos 9.0.');

/**
* NodeData
*/
$nodeDataWarningMessage = '!! NodeData::%2$s is removed in Neos 9.0 - the new CR is not based around the concept of NodeData anymore. You need to rewrite your code here.';
// createNodeData(name: string, [nodeType: NodeType|null = null], [identifier: null|string = null], [workspace: Workspace|null = null], [dimensions: array|null = null]): NodeData
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'createNodeData', $nodeDataWarningMessage);
// createNodeDataFromTemplate(nodeTemplate: NodeTemplate, [nodeName: null|string = null], [workspace: Workspace|null = null], [dimensions: array|null = null]): NodeData
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'createNodeDataFromTemplate', $nodeDataWarningMessage);
// createShadow(path: string): NodeData
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'createShadow', $nodeDataWarningMessage);
// createSingleNodeData(name: string, [nodeType: NodeType|null = null], [identifier: null|string = null], [workspace: Workspace|null = null], [dimensions: array|null = null]): NodeData
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'createSingleNodeData', $nodeDataWarningMessage);
// getContextPath(): string
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getContextPath', $nodeDataWarningMessage);
// getDepth(): int
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getDepth', $nodeDataWarningMessage);
// getDimensions(): NodeDimension[]
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getDimensions', $nodeDataWarningMessage);
// getDimensionsHash(): string
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getDimensionsHash', $nodeDataWarningMessage);
// getDimensionValues(): array
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getDimensionValues', $nodeDataWarningMessage);
// getIdentifier(): string
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getIdentifier', $nodeDataWarningMessage);
// getIndex(): int
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getIndex', $nodeDataWarningMessage);
// getMovedTo(): NodeData
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getMovedTo', $nodeDataWarningMessage);
// getName(): string
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getName', $nodeDataWarningMessage);
// getNumberOfChildNodes(nodeTypeFilter: string, workspace: Workspace, dimensions: array): int
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getNumberOfChildNodes', $nodeDataWarningMessage);
// getParent(): NodeData|null
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getParent', $nodeDataWarningMessage);
// getParentPath(): string
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getParentPath', $nodeDataWarningMessage);
// getPath(): string
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getPath', $nodeDataWarningMessage);
// getWorkspace(): Workspace
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'getWorkspace', $nodeDataWarningMessage);
// hasAccessRestrictions(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'hasAccessRestrictions', $nodeDataWarningMessage);
// isAccessible(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'isAccessible', $nodeDataWarningMessage);
// isInternal(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'isInternal', $nodeDataWarningMessage);
// isRemoved(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'isRemoved', $nodeDataWarningMessage);
// isVisible(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'isVisible', $nodeDataWarningMessage);
// matchesWorkspaceAndDimensions(workspace: Workspace, [dimensions: array|null = null]): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'matchesWorkspaceAndDimensions', $nodeDataWarningMessage);
// move(targetPath: string, targetWorkspace: Workspace): NodeData|null
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'targetPath', $nodeDataWarningMessage);
// remove(): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'remove', $nodeDataWarningMessage);
// setDimensions(dimensionsToBeSet: array): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setDimensions', $nodeDataWarningMessage);
// setIdentifier(identifier: string): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setIdentifier', $nodeDataWarningMessage);
// setIndex(index: int): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setIndex', $nodeDataWarningMessage);
// setMovedTo([nodeData: NodeData|null = null]): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setMovedTo', $nodeDataWarningMessage);
// setPath(path: string, [recursive: bool = true]): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setPath', $nodeDataWarningMessage);
// setRemoved(removed: bool): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setRemoved', $nodeDataWarningMessage);
// setWorkspace([workspace: Workspace|null = null]): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'setWorkspace', $nodeDataWarningMessage);
// similarize(sourceNode: AbstractNodeData, [isCopy: bool = false]): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\NodeData::class, 'similarize', $nodeDataWarningMessage);

/**
* Signals and Slots
* https://docs.neos.io/api/upgrade-instructions/9/signals-and-slots
Expand Down
5 changes: 4 additions & 1 deletion src/ContentRepository90/Rules/NodeSearchServiceRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\Neos\Domain\Service\NodeSearchService::class))) {
if (
!$this->isObjectType($node->var, new ObjectType(\Neos\Neos\Domain\Service\NodeSearchService::class))
&& !$this->isObjectType($node->var, new ObjectType(\Neos\Neos\Domain\Service\NodeSearchServiceInterface::class))
) {
return null;
}
if (!$this->isName($node->name, 'findByProperties')) {
Expand Down
38 changes: 1 addition & 37 deletions src/ContentRepository90/Rules/NodeTypeManagerAccessRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
declare (strict_types=1);
namespace Neos\Rector\ContentRepository90\Rules;

use Neos\ContentRepository\Core\NodeType\NodeTypeManager;
use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints;
use Neos\Rector\ContentRepository90\Legacy\LegacyContextStub;
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
Expand Down Expand Up @@ -43,7 +39,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\PropertyFetch);

if (!$this->isObjectType($node, new ObjectType(NodeTypeManager::class))) {
if (!$this->isObjectType($node, new ObjectType(\Neos\ContentRepository\Domain\Service\NodeTypeManager::class))) {
return null;
}

Expand All @@ -59,36 +55,4 @@ public function refactor(Node $node) : ?Node

return $this->contentRepository_getNodeTypeManager();
}


private function context_workspaceName_fallbackToLive(Node\Expr $legacyContextStub)
{
return new Node\Expr\BinaryOp\Coalesce(
$this->nodeFactory->createPropertyFetch($legacyContextStub, 'workspaceName'),
new Node\Scalar\String_('live')
);
}


private function workspace_currentContentStreamId(): Expr
{
return $this->nodeFactory->createPropertyFetch('workspace', 'currentContentStreamId');
}

private function context_dimensions_fallbackToEmpty(Expr $legacyContextStub)
{
return new Node\Expr\BinaryOp\Coalesce(
$this->nodeFactory->createPropertyFetch($legacyContextStub, 'dimensions'),
new Expr\Array_()
);
}

private function visibilityConstraints(Expr $legacyContextStub)
{
return new Node\Expr\Ternary(
$this->nodeFactory->createPropertyFetch($legacyContextStub, 'invisibleContentShown'),
$this->nodeFactory->createStaticCall(VisibilityConstraints::class, 'withoutRestrictions'),
$this->nodeFactory->createStaticCall(VisibilityConstraints::class, 'frontend'),
);
}
}
2 changes: 1 addition & 1 deletion src/Generic/Rules/MethodCallToWarningCommentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function refactor(Node $node): ?Node

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::todoComment($methodCallToWarningComment->warningMessage)
self::todoComment(sprintf($methodCallToWarningComment->warningMessage, $methodCallToWarningComment->objectType, $methodCallToWarningComment->methodName))
],
$node
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Neos\Rector\Test;

use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Service\Context;

class SomeClass extends AnotherClass
{
/**
* @var \Neos\Neos\Domain\Service\NodeSearchServiceInterface
*/
private $nodeSearchServiceInterface;

public function startingPointNodeIsGiven(Node $node, Context $context)
{
$term = "term";
$searchNodeTypes = [];
$nodes = $this->nodeSearchServiceInterface->findByProperties($term, $searchNodeTypes, $context, $node);
}

public function startingPointNodeIsNotGiven(Context $context)
{
$term = "term";
$searchNodeTypes = [];
$nodes = $this->nodeSearchServiceInterface->findByProperties($term, $searchNodeTypes, $context);
}
}

-----
<?php

namespace Neos\Rector\Test;

use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Service\Context;

class SomeClass extends AnotherClass
{
/**
* @var \Neos\Neos\Domain\Service\NodeSearchServiceInterface
*/
private $nodeSearchServiceInterface;

public function startingPointNodeIsGiven(Node $node, Context $context)
{
$term = "term";
$searchNodeTypes = [];
// TODO 9.0 migration: This could be a suitable replacement. Please check if all your requirements are still fulfilled.
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$nodes = $subgraph->findDescendantNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter::create(nodeTypes: \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria::create(\Neos\ContentRepository\Core\NodeType\NodeTypeNames::fromStringArray($searchNodeTypes), \Neos\ContentRepository\Core\NodeType\NodeTypeNames::createEmpty()), searchTerm: $term));
}

public function startingPointNodeIsNotGiven(Context $context)
{
$term = "term";
$searchNodeTypes = [];
// TODO 9.0 migration: The replacement needs a node as starting point for the search. Please provide a node, to make this replacement working.
$node = 'we-need-a-node-here';
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$nodes = $subgraph->findDescendantNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter::create(nodeTypes: \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\NodeType\NodeTypeCriteria::create(\Neos\ContentRepository\Core\NodeType\NodeTypeNames::fromStringArray($searchNodeTypes), \Neos\ContentRepository\Core\NodeType\NodeTypeNames::createEmpty()), searchTerm: $term));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class SomeClass
{
/**
* @var \Neos\ContentRepository\Core\NodeType\NodeTypeManager
* @var \Neos\ContentRepository\Domain\Service\NodeTypeManager
* @Flow\Inject
*/
protected $nodeTypeManager;
Expand All @@ -20,7 +20,7 @@ class SomeClass
class SomeClass
{
/**
* @var \Neos\ContentRepository\Core\NodeType\NodeTypeManager
* @var \Neos\ContentRepository\Domain\Service\NodeTypeManager
* @Flow\Inject
*/
protected $nodeTypeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class SomeClass
{
public function run(NodeLegacyStub $node)
{
$node->getNode();
return $node->getWorkspace();
}
}
Expand All @@ -20,6 +21,9 @@ class SomeClass
{
public function run(NodeLegacyStub $node)
{
// TODO 9.0 migration: !! Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::getNode() has been removed.

$node->getNode();
// TODO 9.0 migration: !! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.

return $node->getWorkspace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(MethodCallToWarningCommentRector::class, [
new MethodCallToWarningComment(NodeLegacyStub::class, 'getWorkspace', '!! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.')
new MethodCallToWarningComment(NodeLegacyStub::class, 'getWorkspace', '!! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.'),
new MethodCallToWarningComment(NodeLegacyStub::class, 'getNode', '!! %%1$s::%%2$s() has been removed.'),
]);
};
Loading

0 comments on commit 0a363df

Please sign in to comment.