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: Add migration for removed Workspace methods #134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
57 changes: 56 additions & 1 deletion config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
use Neos\Neos\Domain\Service\RenderingModeService;
use Neos\Neos\Domain\Service\WorkspacePublishingService;
use Neos\Neos\Domain\Service\WorkspaceService;
use Neos\Rector\ContentRepository90\Legacy\LegacyContextStub;
use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub;
use Neos\Rector\ContentRepository90\Rules\ContentDimensionCombinatorGetAllAllowedCombinationsRector;
Expand Down Expand Up @@ -64,10 +66,18 @@
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetNameRector;
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetTypeOfAutoCreatedChildNodeRector;
use Neos\Rector\ContentRepository90\Rules\NodeTypeManagerAccessRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetBaseWorkspaceRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetBaseWorkspacesRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetDescriptionRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetNameRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetTitleRector;
use Neos\Rector\ContentRepository90\Rules\WorkspacePublishNodeRector;
use Neos\Rector\ContentRepository90\Rules\WorkspacePublishRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryCountByNameRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryFindByBaseWorkspaceRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryFindByIdentifierRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceSetDescriptionRector;
use Neos\Rector\ContentRepository90\Rules\WorkspaceSetTitleRector;
use Neos\Rector\ContentRepository90\Rules\YamlDimensionConfigRector;
use Neos\Rector\ContentRepository90\Rules\YamlRoutePartHandlerRector;
use Neos\Rector\Generic\Rules\FusionFlowQueryNodePropertyToWarningCommentRector;
Expand Down Expand Up @@ -125,7 +135,7 @@
\Neos\ContentRepository\Domain\Model\NodeType::class => \Neos\ContentRepository\Core\NodeType\NodeType::class,
\Neos\ContentRepository\Domain\Service\NodeTypeManager::class => \Neos\ContentRepository\Core\NodeType\NodeTypeManager::class,

\Neos\ContentRepository\Domain\Model\Workspace::class => \Neos\ContentRepository\Core\Projection\Workspace\Workspace::class,
\Neos\ContentRepository\Domain\Model\Workspace::class => \Neos\ContentRepository\Core\SharedModel\Workspace\Workspace::class,
\Neos\ContentRepository\Domain\NodeAggregate\NodeAggregateIdentifier::class => \Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId::class,
\Neos\ContentRepository\Domain\NodeAggregate\NodeName::class => \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class,
\Neos\ContentRepository\Domain\NodeType\NodeTypeName::class => \Neos\ContentRepository\Core\NodeType\NodeTypeName::class,
Expand Down Expand Up @@ -702,6 +712,49 @@
*/
$rectorConfig->rule(FusionFlowQueryContextRector::class);

/**
* \Neos\ContentRepository\Domain\Model\Workspace
*/
// getBaseWorkspace(): Workspace|null
$rectorConfig->rule(WorkspaceGetBaseWorkspaceRector::class);
// getBaseWorkspaces(): Workspace[]
$rectorConfig->rule(WorkspaceGetBaseWorkspacesRector::class);
// getDescription(): null|string
$rectorConfig->rule(WorkspaceGetDescriptionRector::class);
// getName(): string
// ->name
// getNodeCount(): int
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'getNodeCount', '!! Workspace::getNodeCount() has been removed in Neos 9.0 without a replacement.');
// getOwner(): UserInterface|null
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'getOwner', '!! Workspace::getOwner() has been removed in Neos 9.0. Use WorkspaceService::getWorkspaceMetadata()->ownerUserId to get the userId of the owner.');
// getRootNodeData(): NodeData
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'getRootNodeData', '!! Workspace::getRootNodeData() has been removed in Neos 9.0 without a replacement.');
// getTitle(): string
$rectorConfig->rule(WorkspaceGetTitleRector::class);
// meta->setWorkspaceTitle
// isInternalWorkspace(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'isInternalWorkspace', '!! Workspace::isInternalWorkspace() has been removed in Neos 9.0. Please use the new Workspace permission api instead. See ContentRepositoryAuthorizationService::getWorkspacePermissions()');
// isPersonalWorkspace(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'isPersonalWorkspace', '!! Workspace::isPersonalWorkspace() has been removed in Neos 9.0. Please use the new Workspace permission api instead. See ContentRepositoryAuthorizationService::getWorkspacePermissions()');
// isPrivateWorkspace(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'isPrivateWorkspace', '!! Workspace::isPrivateWorkspace() has been removed in Neos 9.0. Please use the new Workspace permission api instead. See ContentRepositoryAuthorizationService::getWorkspacePermissions()');
// isPublicWorkspace(): bool
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'isPublicWorkspace', '!! Workspace::isPublicWorkspace() has been removed in Neos 9.0. Please use the new Workspace permission api instead. See ContentRepositoryAuthorizationService::getWorkspacePermissions()');
// publish(targetWorkspace: Workspace): void
$rectorConfig->rule(WorkspacePublishRector::class);
// publishNode(nodeToPublish: NodeInterface, targetWorkspace: Workspace): void
$rectorConfig->rule(WorkspacePublishNodeRector::class);
// publishNodes(nodes: NodeInterface[], targetWorkspace: Workspace): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'publishNodes', '!! Workspace::publishNodes() has been removed in Neos 9.0. Use the \Neos\Neos\Domain\Service\WorkspacePublishingService to publish a workspace or changes in a document.');
// setBaseWorkspace(baseWorkspace: Workspace): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'setBaseWorkspace', '!! Workspace::setBaseWorkspace() is not supported by the new CR. Use the "ChangeBaseWorkspace" command to change the baseWorkspace of a workspace.');
// setDescription(description: string): void
$rectorConfig->rule(WorkspaceSetDescriptionRector::class);
// setOwner(user: UserInterface|null|string): void
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'setOwner', '!! Workspace::setOwner() has been removed in Neos 9.0. You can set the owner of a workspace during creation WorkspaceService::createPersonalWorkspace().');
// setTitle(title: string): void
$rectorConfig->rule(WorkspaceSetTitleRector::class);

/**
* SPECIAL rules
*/
Expand Down Expand Up @@ -788,6 +841,8 @@ class_alias(RenameClassRector::class, \Alias\RenameClassRectorLegacy::class);
new AddInjection('contentRepositoryRegistry', ContentRepositoryRegistry::class),
new AddInjection('renderingModeService', RenderingModeService::class),
new AddInjection('nodeLabelGenerator', NodeLabelGeneratorInterface::class),
new AddInjection('workspacePublishingService', WorkspacePublishingService::class),
new AddInjection('workspaceService', WorkspaceService::class),
]);
// TODO: does not fully seem to work.$rectorConfig->rule(RemoveDuplicateCommentRector::class);
};
23 changes: 23 additions & 0 deletions src/ContentRepository90/Rules/Traits/ThisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ private function this_contentRepositoryRegistry_get(Expr $contentRepositoryIdent
);
}

private function this_workspaceService_getWorkspaceMetadata(Expr $contentRepositoryIdentifier, Expr $workspaceName): Expr
{
return $this->nodeFactory->createMethodCall(
$this->this_workspaceService(),
'getWorkspaceMetadata',
[
$contentRepositoryIdentifier,
$workspaceName
]
);
}

private function this_workspaceService()
{
return $this->nodeFactory->createPropertyFetch('this', 'workspaceService');
}

private function this_workspacePublishingService()
{
return $this->nodeFactory->createPropertyFetch('this', 'workspacePublishingService');
}


private function this_contentRepositoryRegistry(): Expr
{
return $this->nodeFactory->createPropertyFetch('this', 'contentRepositoryRegistry');
Expand Down
69 changes: 69 additions & 0 deletions src/ContentRepository90/Rules/WorkspaceGetBaseWorkspaceRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare (strict_types=1);

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class WorkspaceGetBaseWorkspaceRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector,
)
{
}

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('"Workspace::getBaseWorkspace()" will be rewritten', __CLASS__);
}

/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [\PhpParser\Node\Expr\MethodCall::class];
}

/**
* @param \PhpParser\Node\Expr\MethodCall $node
*/
public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace::class))) {
return null;
}
if (!$this->isName($node->name, 'getBaseWorkspace')) {
return null;
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::withTodoComment('Check if you could change your code to work with the WorkspaceName value object instead and make this code aware of multiple Content Repositories.',
self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))),
)
],
$node
);


return
$this->nodeFactory->createMethodCall(
new Variable('contentRepository'),
'findWorkspaceByName',
[$this->nodeFactory->createPropertyFetch($node->var, 'baseWorkspaceName')]
);
}
}
72 changes: 72 additions & 0 deletions src/ContentRepository90/Rules/WorkspaceGetBaseWorkspacesRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare (strict_types=1);

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

final class WorkspaceGetBaseWorkspacesRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector,
)
{
}

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('"Workspace::getBaseWorkspaces()" will be rewritten', __CLASS__);
}

/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [\PhpParser\Node\Expr\MethodCall::class];
}

/**
* @param \PhpParser\Node\Expr\MethodCall $node
*/
public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace::class))) {
return null;
}
if (!$this->isName($node->name, 'getBaseWorkspaces')) {
return null;
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::withTodoComment('Check if you could change your code to work with the WorkspaceName value object instead and make this code aware of multiple Content Repositories.',
self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))),
)
],
$node
);


return
$this->nodeFactory->createMethodCall(
$this->nodeFactory->createMethodCall(
new Variable('contentRepository'),
'findWorkspaces'
),
'getBaseWorkspaces',
[$this->nodeFactory->createPropertyFetch($node->var, 'workspaceName')]
);
}
}
71 changes: 71 additions & 0 deletions src/ContentRepository90/Rules/WorkspaceGetDescriptionRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare (strict_types=1);

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;

final class WorkspaceGetDescriptionRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector,
)
{
}

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('"Workspace::getDescription()" will be rewritten', __CLASS__);
}

/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [\PhpParser\Node\Expr\MethodCall::class];
}

/**
* @param \PhpParser\Node\Expr\MethodCall $node
*/
public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(Workspace::class))) {
return null;
}
if (!$this->isName($node->name, 'getDescription')) {
return null;
}

$this->nodesToAddCollector->addNodesBeforeNode(
[
self::todoComment('Make this code aware of multiple Content Repositories.')
],
$node
);

return
$this->nodeFactory->createPropertyFetch(
$this->nodeFactory->createPropertyFetch(
$this->this_workspaceService_getWorkspaceMetadata(
$this->contentRepositoryId_fromString('default'),
$this->nodeFactory->createPropertyFetch($node->var, 'workspaceName')
),
'description',
), 'value'
);
}
}
5 changes: 3 additions & 2 deletions src/ContentRepository90/Rules/WorkspaceGetNameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;

final class WorkspaceGetNameRector extends AbstractRector
{
use AllTraits;

public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector,
) {
)
{
}

public function getRuleDefinition(): RuleDefinition
Expand Down
Loading