Skip to content

Commit

Permalink
Merge pull request #121 from neos/bugfix/node-type-manager
Browse files Browse the repository at this point in the history
BUGFIX: Fix replacement of NodeTypeManager and add tests to cover this
  • Loading branch information
dlubitz authored Dec 23, 2024
2 parents d126245 + 1b90ed2 commit ec19d6b
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 39 deletions.
18 changes: 18 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 @@ -435,6 +436,23 @@
*/
$rectorConfig->rule(WorkspaceGetNameRector::class);

/**
* 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
*/
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'),
);
}
}
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
92 changes: 92 additions & 0 deletions tests/Sets/ContentRepository90/Fixture/node-type-manager.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);

namespace Neos\MarketPlace\Domain\Model;

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
use Neos\Flow\Annotations as Flow;
use Neos\MarketPlace\Exception;

class Storage
{
/**
* @var NodeTypeManager
* @Flow\Inject
*/
protected $nodeTypeManager;

/**
* @throws Exception
* @throws NodeTypeNotFoundException
*/
public function createVendor(string $vendor): NodeInterface
{
$vendor = Slug::create($vendor);
$node = $this->node()->getNode($vendor);

if ($node === null) {
$node = $this->node()->createNode($vendor, $this->nodeTypeManager->getNodeType('Neos.MarketPlace:Vendor'));
$node->setProperty('uriPathSegment', $vendor);
$node->setProperty('title', $vendor);
}

$nodeTypeManager = $this->getNodeTypeManager();
$nodeTypeManager->createNodeType('Neos.MarketPlace:New');
return $node;
}

public function getNodeTypeManager(): NodeTypeManager
{
return $this->nodeTypeManager;
}
}
-----
<?php
declare(strict_types=1);

namespace Neos\MarketPlace\Domain\Model;

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
use Neos\Flow\Annotations as Flow;
use Neos\MarketPlace\Exception;

class Storage
{
#[\Neos\Flow\Annotations\Inject]
protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* @throws Exception
* @throws NodeTypeNotFoundException
*/
public function createVendor(string $vendor): \Neos\ContentRepository\Core\Projection\ContentGraph\Node
{
$vendor = Slug::create($vendor);
$node = $this->node()->getNode($vendor);

if ($node === null) {
// TODO 9.0 migration: Make this code aware of multiple Content Repositories.
$contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default'));
$node = $this->node()->createNode($vendor, $contentRepository->getNodeTypeManager()->getNodeType('Neos.MarketPlace:Vendor'));
$node->setProperty('uriPathSegment', $vendor);
$node->setProperty('title', $vendor);
}

$nodeTypeManager = $this->getNodeTypeManager();
// TODO 9.0 migration: !! NodeTypeManager::createNodeType() was never implemented and is removed in Neos 9.0.

$nodeTypeManager->createNodeType('Neos.MarketPlace:New');
return $node;
}

public function getNodeTypeManager(): \Neos\ContentRepository\Core\NodeType\NodeTypeManager
{
// TODO 9.0 migration: Make this code aware of multiple Content Repositories.
$contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default'));
return $contentRepository->getNodeTypeManager();
}
}

0 comments on commit ec19d6b

Please sign in to comment.