Skip to content

Commit 21ecc7d

Browse files
authored
Merge pull request #134 from neos/workspace
FEATURE: Add migration for removed Workspace methods
2 parents 11576d3 + e5e6e4a commit 21ecc7d

38 files changed

+1357
-7
lines changed

config/set/contentrepository-90.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
77
use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface;
88
use Neos\Neos\Domain\Service\RenderingModeService;
9+
use Neos\Neos\Domain\Service\WorkspacePublishingService;
10+
use Neos\Neos\Domain\Service\WorkspaceService;
911
use Neos\Rector\ContentRepository90\Legacy\LegacyContextStub;
1012
use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub;
1113
use Neos\Rector\ContentRepository90\Rules\ContentDimensionCombinatorGetAllAllowedCombinationsRector;
@@ -64,10 +66,18 @@
6466
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetNameRector;
6567
use Neos\Rector\ContentRepository90\Rules\NodeTypeGetTypeOfAutoCreatedChildNodeRector;
6668
use Neos\Rector\ContentRepository90\Rules\NodeTypeManagerAccessRector;
69+
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetBaseWorkspaceRector;
70+
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetBaseWorkspacesRector;
71+
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetDescriptionRector;
6772
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetNameRector;
73+
use Neos\Rector\ContentRepository90\Rules\WorkspaceGetTitleRector;
74+
use Neos\Rector\ContentRepository90\Rules\WorkspacePublishNodeRector;
75+
use Neos\Rector\ContentRepository90\Rules\WorkspacePublishRector;
6876
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryCountByNameRector;
6977
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryFindByBaseWorkspaceRector;
7078
use Neos\Rector\ContentRepository90\Rules\WorkspaceRepositoryFindByIdentifierRector;
79+
use Neos\Rector\ContentRepository90\Rules\WorkspaceSetDescriptionRector;
80+
use Neos\Rector\ContentRepository90\Rules\WorkspaceSetTitleRector;
7181
use Neos\Rector\ContentRepository90\Rules\YamlDimensionConfigRector;
7282
use Neos\Rector\ContentRepository90\Rules\YamlRoutePartHandlerRector;
7383
use Neos\Rector\Generic\Rules\FusionFlowQueryNodePropertyToWarningCommentRector;
@@ -125,7 +135,7 @@
125135
\Neos\ContentRepository\Domain\Model\NodeType::class => \Neos\ContentRepository\Core\NodeType\NodeType::class,
126136
\Neos\ContentRepository\Domain\Service\NodeTypeManager::class => \Neos\ContentRepository\Core\NodeType\NodeTypeManager::class,
127137

128-
\Neos\ContentRepository\Domain\Model\Workspace::class => \Neos\ContentRepository\Core\Projection\Workspace\Workspace::class,
138+
\Neos\ContentRepository\Domain\Model\Workspace::class => \Neos\ContentRepository\Core\SharedModel\Workspace\Workspace::class,
129139
\Neos\ContentRepository\Domain\NodeAggregate\NodeAggregateIdentifier::class => \Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId::class,
130140
\Neos\ContentRepository\Domain\NodeAggregate\NodeName::class => \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class,
131141
\Neos\ContentRepository\Domain\NodeType\NodeTypeName::class => \Neos\ContentRepository\Core\NodeType\NodeTypeName::class,
@@ -702,6 +712,49 @@
702712
*/
703713
$rectorConfig->rule(FusionFlowQueryContextRector::class);
704714

715+
/**
716+
* \Neos\ContentRepository\Domain\Model\Workspace
717+
*/
718+
// getBaseWorkspace(): Workspace|null
719+
$rectorConfig->rule(WorkspaceGetBaseWorkspaceRector::class);
720+
// getBaseWorkspaces(): Workspace[]
721+
$rectorConfig->rule(WorkspaceGetBaseWorkspacesRector::class);
722+
// getDescription(): null|string
723+
$rectorConfig->rule(WorkspaceGetDescriptionRector::class);
724+
// getName(): string
725+
// ->name
726+
// getNodeCount(): int
727+
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'getNodeCount', '!! Workspace::getNodeCount() has been removed in Neos 9.0 without a replacement.');
728+
// getOwner(): UserInterface|null
729+
$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.');
730+
// getRootNodeData(): NodeData
731+
$methodCallToWarningComments[] = new MethodCallToWarningComment(\Neos\ContentRepository\Domain\Model\Workspace::class, 'getRootNodeData', '!! Workspace::getRootNodeData() has been removed in Neos 9.0 without a replacement.');
732+
// getTitle(): string
733+
$rectorConfig->rule(WorkspaceGetTitleRector::class);
734+
// meta->setWorkspaceTitle
735+
// isInternalWorkspace(): bool
736+
$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()');
737+
// isPersonalWorkspace(): bool
738+
$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()');
739+
// isPrivateWorkspace(): bool
740+
$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()');
741+
// isPublicWorkspace(): bool
742+
$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()');
743+
// publish(targetWorkspace: Workspace): void
744+
$rectorConfig->rule(WorkspacePublishRector::class);
745+
// publishNode(nodeToPublish: NodeInterface, targetWorkspace: Workspace): void
746+
$rectorConfig->rule(WorkspacePublishNodeRector::class);
747+
// publishNodes(nodes: NodeInterface[], targetWorkspace: Workspace): void
748+
$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.');
749+
// setBaseWorkspace(baseWorkspace: Workspace): void
750+
$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.');
751+
// setDescription(description: string): void
752+
$rectorConfig->rule(WorkspaceSetDescriptionRector::class);
753+
// setOwner(user: UserInterface|null|string): void
754+
$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().');
755+
// setTitle(title: string): void
756+
$rectorConfig->rule(WorkspaceSetTitleRector::class);
757+
705758
/**
706759
* SPECIAL rules
707760
*/
@@ -788,6 +841,8 @@ class_alias(RenameClassRector::class, \Alias\RenameClassRectorLegacy::class);
788841
new AddInjection('contentRepositoryRegistry', ContentRepositoryRegistry::class),
789842
new AddInjection('renderingModeService', RenderingModeService::class),
790843
new AddInjection('nodeLabelGenerator', NodeLabelGeneratorInterface::class),
844+
new AddInjection('workspacePublishingService', WorkspacePublishingService::class),
845+
new AddInjection('workspaceService', WorkspaceService::class),
791846
]);
792847
// TODO: does not fully seem to work.$rectorConfig->rule(RemoveDuplicateCommentRector::class);
793848
};

src/ContentRepository90/Rules/Traits/ThisTrait.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,29 @@ private function this_contentRepositoryRegistry_get(Expr $contentRepositoryIdent
3333
);
3434
}
3535

36+
private function this_workspaceService_getWorkspaceMetadata(Expr $contentRepositoryIdentifier, Expr $workspaceName): Expr
37+
{
38+
return $this->nodeFactory->createMethodCall(
39+
$this->this_workspaceService(),
40+
'getWorkspaceMetadata',
41+
[
42+
$contentRepositoryIdentifier,
43+
$workspaceName
44+
]
45+
);
46+
}
47+
48+
private function this_workspaceService()
49+
{
50+
return $this->nodeFactory->createPropertyFetch('this', 'workspaceService');
51+
}
52+
53+
private function this_workspacePublishingService()
54+
{
55+
return $this->nodeFactory->createPropertyFetch('this', 'workspacePublishingService');
56+
}
57+
58+
3659
private function this_contentRepositoryRegistry(): Expr
3760
{
3861
return $this->nodeFactory->createPropertyFetch('this', 'contentRepositoryRegistry');
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
5+
namespace Neos\Rector\ContentRepository90\Rules;
6+
7+
use Neos\Rector\Utility\CodeSampleLoader;
8+
use PhpParser\Node;
9+
use PhpParser\Node\Expr\Variable;
10+
use PHPStan\Type\ObjectType;
11+
use Rector\Core\Rector\AbstractRector;
12+
use Rector\PostRector\Collector\NodesToAddCollector;
13+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
14+
15+
final class WorkspaceGetBaseWorkspaceRector extends AbstractRector
16+
{
17+
use AllTraits;
18+
19+
public function __construct(
20+
private readonly NodesToAddCollector $nodesToAddCollector,
21+
)
22+
{
23+
}
24+
25+
public function getRuleDefinition(): RuleDefinition
26+
{
27+
return CodeSampleLoader::fromFile('"Workspace::getBaseWorkspace()" will be rewritten', __CLASS__);
28+
}
29+
30+
/**
31+
* @return array<class-string<Node>>
32+
*/
33+
public function getNodeTypes(): array
34+
{
35+
return [\PhpParser\Node\Expr\MethodCall::class];
36+
}
37+
38+
/**
39+
* @param \PhpParser\Node\Expr\MethodCall $node
40+
*/
41+
public function refactor(Node $node): ?Node
42+
{
43+
assert($node instanceof Node\Expr\MethodCall);
44+
45+
if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace::class))) {
46+
return null;
47+
}
48+
if (!$this->isName($node->name, 'getBaseWorkspace')) {
49+
return null;
50+
}
51+
52+
$this->nodesToAddCollector->addNodesBeforeNode(
53+
[
54+
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.',
55+
self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))),
56+
)
57+
],
58+
$node
59+
);
60+
61+
62+
return
63+
$this->nodeFactory->createMethodCall(
64+
new Variable('contentRepository'),
65+
'findWorkspaceByName',
66+
[$this->nodeFactory->createPropertyFetch($node->var, 'baseWorkspaceName')]
67+
);
68+
}
69+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
5+
namespace Neos\Rector\ContentRepository90\Rules;
6+
7+
use Neos\Rector\Utility\CodeSampleLoader;
8+
use PhpParser\Node;
9+
use PhpParser\Node\Expr\Variable;
10+
use PHPStan\Type\ObjectType;
11+
use Rector\Core\Rector\AbstractRector;
12+
use Rector\PostRector\Collector\NodesToAddCollector;
13+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
14+
15+
final class WorkspaceGetBaseWorkspacesRector extends AbstractRector
16+
{
17+
use AllTraits;
18+
19+
public function __construct(
20+
private readonly NodesToAddCollector $nodesToAddCollector,
21+
)
22+
{
23+
}
24+
25+
public function getRuleDefinition(): RuleDefinition
26+
{
27+
return CodeSampleLoader::fromFile('"Workspace::getBaseWorkspaces()" will be rewritten', __CLASS__);
28+
}
29+
30+
/**
31+
* @return array<class-string<Node>>
32+
*/
33+
public function getNodeTypes(): array
34+
{
35+
return [\PhpParser\Node\Expr\MethodCall::class];
36+
}
37+
38+
/**
39+
* @param \PhpParser\Node\Expr\MethodCall $node
40+
*/
41+
public function refactor(Node $node): ?Node
42+
{
43+
assert($node instanceof Node\Expr\MethodCall);
44+
45+
if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace::class))) {
46+
return null;
47+
}
48+
if (!$this->isName($node->name, 'getBaseWorkspaces')) {
49+
return null;
50+
}
51+
52+
$this->nodesToAddCollector->addNodesBeforeNode(
53+
[
54+
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.',
55+
self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))),
56+
)
57+
],
58+
$node
59+
);
60+
61+
62+
return
63+
$this->nodeFactory->createMethodCall(
64+
$this->nodeFactory->createMethodCall(
65+
new Variable('contentRepository'),
66+
'findWorkspaces'
67+
),
68+
'getBaseWorkspaces',
69+
[$this->nodeFactory->createPropertyFetch($node->var, 'workspaceName')]
70+
);
71+
}
72+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
5+
namespace Neos\Rector\ContentRepository90\Rules;
6+
7+
use Neos\Rector\Utility\CodeSampleLoader;
8+
use PhpParser\Node;
9+
use PhpParser\Node\Expr\Variable;
10+
use PHPStan\Type\ObjectType;
11+
use Rector\Core\Rector\AbstractRector;
12+
use Rector\PostRector\Collector\NodesToAddCollector;
13+
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
14+
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
15+
16+
final class WorkspaceGetDescriptionRector extends AbstractRector
17+
{
18+
use AllTraits;
19+
20+
public function __construct(
21+
private readonly NodesToAddCollector $nodesToAddCollector,
22+
)
23+
{
24+
}
25+
26+
public function getRuleDefinition(): RuleDefinition
27+
{
28+
return CodeSampleLoader::fromFile('"Workspace::getDescription()" will be rewritten', __CLASS__);
29+
}
30+
31+
/**
32+
* @return array<class-string<Node>>
33+
*/
34+
public function getNodeTypes(): array
35+
{
36+
return [\PhpParser\Node\Expr\MethodCall::class];
37+
}
38+
39+
/**
40+
* @param \PhpParser\Node\Expr\MethodCall $node
41+
*/
42+
public function refactor(Node $node): ?Node
43+
{
44+
assert($node instanceof Node\Expr\MethodCall);
45+
46+
if (!$this->isObjectType($node->var, new ObjectType(Workspace::class))) {
47+
return null;
48+
}
49+
if (!$this->isName($node->name, 'getDescription')) {
50+
return null;
51+
}
52+
53+
$this->nodesToAddCollector->addNodesBeforeNode(
54+
[
55+
self::todoComment('Make this code aware of multiple Content Repositories.')
56+
],
57+
$node
58+
);
59+
60+
return
61+
$this->nodeFactory->createPropertyFetch(
62+
$this->nodeFactory->createPropertyFetch(
63+
$this->this_workspaceService_getWorkspaceMetadata(
64+
$this->contentRepositoryId_fromString('default'),
65+
$this->nodeFactory->createPropertyFetch($node->var, 'workspaceName')
66+
),
67+
'description',
68+
), 'value'
69+
);
70+
}
71+
}

src/ContentRepository90/Rules/WorkspaceGetNameRector.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
use Rector\Core\Rector\AbstractRector;
1111
use Rector\PostRector\Collector\NodesToAddCollector;
1212
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
13-
use Neos\ContentRepository\Core\Projection\Workspace\Workspace;
13+
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
1414

1515
final class WorkspaceGetNameRector extends AbstractRector
1616
{
1717
use AllTraits;
1818

1919
public function __construct(
2020
private readonly NodesToAddCollector $nodesToAddCollector,
21-
) {
21+
)
22+
{
2223
}
2324

2425
public function getRuleDefinition(): RuleDefinition

0 commit comments

Comments
 (0)