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

BUGFIX: Fix replacement of NodeTypeManager and add tests to cover this #121

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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.');
dlubitz marked this conversation as resolved.
Show resolved Hide resolved
// 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
// --> Compatible with 9.0
dlubitz marked this conversation as resolved.
Show resolved Hide resolved

/**
* Signals and Slots
* https://docs.neos.io/api/upgrade-instructions/9/signals-and-slots
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'));
dlubitz marked this conversation as resolved.
Show resolved Hide resolved
return $contentRepository->getNodeTypeManager();
}
}
Loading