diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index c7e975b..cb5ace8 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -394,9 +394,12 @@ * Neos.Fusion:Attributes */ $rectorConfig->ruleWithConfiguration(FusionPrototypeNameAddCommentRector::class, [ - new FusionPrototypeNameAddComment('Neos.Neos:PrimaryContent', 'TODO 9.0 migration: You need to refactor "Neos.Neos:PrimaryContent" to use "Neos.Neos:ContentCollection" instead.'), new FusionPrototypeNameAddComment('Neos.Fusion:Attributes', 'TODO 9.0 migration: Neos.Fusion:Attributes has been removed without a replacement. You need to replace it by the property attributes in Neos.Fusion:Tag') ]); + $rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [ + new FusionPrototypeNameReplacement('Neos.Neos:PrimaryContent', 'Neos.Neos:ContentCollection', '"Neos.Neos:PrimaryContent" has been removed without a complete replacement. We replaced all usages with "Neos.Neos:ContentCollection" but not the prototype definition. Please check the replacements and if you have overridden the "Neos.Neos:PrimaryContent" prototype and rewrite it for your needs.', true), + ]); + $rectorConfig->rule(ContentRepositoryUtilityRenderValidNodeNameRector::class); diff --git a/src/Generic/Rules/FusionReplacePrototypeNameRector.php b/src/Generic/Rules/FusionReplacePrototypeNameRector.php index 1505ae9..4cec8ff 100644 --- a/src/Generic/Rules/FusionReplacePrototypeNameRector.php +++ b/src/Generic/Rules/FusionReplacePrototypeNameRector.php @@ -28,12 +28,16 @@ public function refactorFileContent(string $fileContent): string $comments = []; foreach ($this->fusionPrototypeNameReplacements as $fusionPrototypeNameReplacement) { $replacementCount = 0; - $pattern = '/(^|[=\s\(<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s\{\)\/>]|$)/'; + if ($fusionPrototypeNameReplacement->skipPrototypeDefinitions) { + $pattern = '/(^|[=\s<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s{\/>]|$)/'; + } else { + $pattern = '/(^|[=\s(<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s{)\/>]|$)/'; + } $replacement = '$1'.$fusionPrototypeNameReplacement->newName.'$3'; $fileContent = preg_replace($pattern, $replacement, $fileContent, count: $replacementCount); if($replacementCount > 0 && $fusionPrototypeNameReplacement->comment !== null) { - $comments[] = '// TODO 9.0 migration:' . $fusionPrototypeNameReplacement->comment; + $comments[] = '// TODO 9.0 migration: ' . $fusionPrototypeNameReplacement->comment; } } diff --git a/src/Generic/ValueObject/FusionPrototypeNameReplacement.php b/src/Generic/ValueObject/FusionPrototypeNameReplacement.php index f60e47d..56e3d39 100644 --- a/src/Generic/ValueObject/FusionPrototypeNameReplacement.php +++ b/src/Generic/ValueObject/FusionPrototypeNameReplacement.php @@ -8,7 +8,8 @@ class FusionPrototypeNameReplacement public function __construct( public readonly string $oldName, public readonly string $newName, - public readonly ?string $comment = null + public readonly ?string $comment = null, + public readonly bool $skipPrototypeDefinitions = false, ) { } } diff --git a/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/skip_prototype_definition.fusion.inc b/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/skip_prototype_definition.fusion.inc new file mode 100644 index 0000000..e8899e0 --- /dev/null +++ b/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/skip_prototype_definition.fusion.inc @@ -0,0 +1,17 @@ +prototype(Neos.Neos:Foo) < prototype(Neos.Neos:Bar) { + + raw = Neos.Neos:Foo + renderer = afx` + + ` +} +----- +// TODO 9.0 migration: Neos.Neos:FooReplaced: This comment should be added on top of the file. +// TODO 9.0 migration: Neos.Neos:BarReplaced: This comment should be added on top of the file. +prototype(Neos.Neos:Foo) < prototype(Neos.Neos:Bar) { + + raw = Neos.Neos:FooReplaced + renderer = afx` + + ` +} diff --git a/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/some_file.fusion.inc b/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/some_file.fusion.inc index 77f1105..a3ded36 100644 --- a/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/some_file.fusion.inc +++ b/tests/Generic/Rules/FusionPrototypeNameReplacement/Fixture/some_file.fusion.inc @@ -16,8 +16,8 @@ prototype(Neos.Neos:SomethingOld) < prototype(Neos.Neos:Raw) { } } ----- -// TODO 9.0 migration:Neos.Neos:Raw: This comment should be added on top of the file. -// TODO 9.0 migration:Neos.Neos:SomethingOlder: This comment should be added on top of the file. +// TODO 9.0 migration: Neos.Neos:Raw: This comment should be added on top of the file. +// TODO 9.0 migration: Neos.Neos:SomethingOlder: This comment should be added on top of the file. prototype(Neos.Neos:SomethingNew) < prototype(Neos.Neos:NewRaw) { raw = Neos.Neos:NewRaw diff --git a/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php b/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php index 740ee4e..0dde646 100644 --- a/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php +++ b/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php @@ -21,5 +21,7 @@ new FusionPrototypeNameReplacement('Neos.Neos:NotExisting', 'Neos.Neos:NewNotExisting', 'Neos.Neos:NotExisting: This comment should NOT be added on top of the file.'), new FusionPrototypeNameReplacement('Neos.Neos:SomethingOld', 'Neos.Neos:SomethingNew'), new FusionPrototypeNameReplacement('Neos.Neos:SomethingOlder', 'Neos.Neos:SomethingNewer', 'Neos.Neos:SomethingOlder: This comment should be added on top of the file.'), + new FusionPrototypeNameReplacement('Neos.Neos:Foo', 'Neos.Neos:FooReplaced', 'Neos.Neos:FooReplaced: This comment should be added on top of the file.', true), + new FusionPrototypeNameReplacement('Neos.Neos:Bar', 'Neos.Neos:BarReplaced', 'Neos.Neos:BarReplaced: This comment should be added on top of the file.', true), ]); }; diff --git a/tests/Sets/ContentRepository90/ContentRepository90Test.php b/tests/Sets/ContentRepository90/ContentRepository90Test.php new file mode 100644 index 0000000..4e5019c --- /dev/null +++ b/tests/Sets/ContentRepository90/ContentRepository90Test.php @@ -0,0 +1,31 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.fusion.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/../../../config/set/contentrepository-90.php'; + } +} diff --git a/tests/Sets/ContentRepository90/Fixture/primary-content.fusion.inc b/tests/Sets/ContentRepository90/Fixture/primary-content.fusion.inc new file mode 100644 index 0000000..646d2f3 --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/primary-content.fusion.inc @@ -0,0 +1,22 @@ +prototype(Neos.Neos:PrimaryContent) { + myArticle { + condition = ${q(node).is('[instanceof My.Site:Article]')} + renderer = My.Site:ArticleRenderer + } +} + +content = Neos.Neos:PrimaryContent { + nodePath = 'main' +} +----- +// TODO 9.0 migration: "Neos.Neos:PrimaryContent" has been removed without a complete replacement. We replaced all usages with "Neos.Neos:ContentCollection" but not the prototype definition. Please check the replacements and if you have overridden the "Neos.Neos:PrimaryContent" prototype and rewrite it for your needs. +prototype(Neos.Neos:PrimaryContent) { + myArticle { + condition = ${q(node).is('[instanceof My.Site:Article]')} + renderer = My.Site:ArticleRenderer + } +} + +content = Neos.Neos:ContentCollection { + nodePath = 'main' +}