Skip to content

Commit cb633dd

Browse files
Adrian Cerdeirat-heuser
authored andcommitted
feat: resolve todos and create custom transformation (who cannot be used at the moment)
# Conflicts: # README.md
1 parent 671b2eb commit cb633dd

4 files changed

Lines changed: 64 additions & 48 deletions

File tree

Classes/Migration/Transformation/PropertyValueToLowercase.php

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,58 @@
44

55
namespace Flowpack\SeoRouting\Migration\Transformation;
66

7-
use Neos\ContentRepository\Domain\Model\NodeData;
8-
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;
9-
10-
// TODO 9.0 migration: You need to convert your AbstractTransformation to an implementation of Neos\ContentRepository\NodeMigration\Transformation\TransformationFactoryInterface
11-
class PropertyValueToLowercase
7+
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
8+
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
9+
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
10+
use Neos\ContentRepository\NodeMigration\Transformation\NodeBasedTransformationInterface;
11+
use Neos\ContentRepository\Core\ContentRepository;
12+
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties;
13+
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite;
14+
use Neos\ContentRepository\NodeMigration\Transformation\GlobalTransformationInterface;
15+
use Neos\ContentRepository\NodeMigration\Transformation\TransformationFactoryInterface;
16+
use Neos\ContentRepository\NodeMigration\Transformation\TransformationStep;
17+
18+
/**
19+
* Transforms a specified property value of a node to lowercase.
20+
*/
21+
class PropertyValueToLowercase implements TransformationFactoryInterface
1222
{
13-
private string $propertyName;
14-
15-
public function setProperty(string $propertyName): void
16-
{
17-
$this->propertyName = $propertyName;
18-
}
19-
20-
/**
21-
* @inheritDoc
22-
*/
23-
public function isTransformable(NodeData $node)
24-
{
25-
return $node->hasProperty($this->propertyName);
26-
}
27-
2823
/**
29-
* @inheritDoc
24+
* @param array<string,string> $settings
3025
*/
31-
public function execute(NodeData $node)
26+
public function build(array $settings, ContentRepository $contentRepository): GlobalTransformationInterface|NodeBasedTransformationInterface
3227
{
33-
$currentPropertyValue = $node->getProperty($this->propertyName);
34-
if (! is_string($currentPropertyValue)) {
35-
return $node;
36-
}
37-
$newPropertyValue = strtolower($currentPropertyValue);
38-
$node->setProperty($this->propertyName, $newPropertyValue);
39-
40-
return $node;
28+
return new class(
29+
$settings['property']
30+
) implements NodeBasedTransformationInterface {
31+
32+
private string $propertyName;
33+
34+
public function __construct(string $propertyName)
35+
{
36+
$this->propertyName = $propertyName;
37+
}
38+
39+
public function execute(Node $node, DimensionSpacePoint $coveredDimensionSpacePoints, WorkspaceName $workspaceNameForWriting): TransformationStep
40+
{
41+
$currentProperty = $node->getProperty($this->propertyName);
42+
43+
if ($currentProperty !== null && is_string($currentProperty)) {
44+
$value = strtolower($currentProperty);
45+
return TransformationStep::fromCommand(
46+
SetNodeProperties::create(
47+
$workspaceNameForWriting,
48+
$node->aggregateId,
49+
$node->originDimensionSpacePoint,
50+
PropertyValuesToWrite::fromArray([
51+
$this->propertyName => $value,
52+
])
53+
)
54+
);
55+
}
56+
57+
return TransformationStep::createEmpty();
58+
}
59+
};
4160
}
4261
}
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
up:
2-
comments: 'Transforms all uriPathSegment values to lowercase'
3-
warnings: 'As this migration removes the distinction between uppercase and lowercase it might not be cleanly undone by the down migration.'
4-
migration:
5-
- filters:
6-
- type: 'NodeType'
7-
settings:
8-
nodeType: 'Neos.Neos:Document'
9-
withSubTypes: TRUE
10-
transformations:
11-
- type: 'Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase'
12-
settings:
13-
property: 'uriPathSegment'
14-
15-
down:
16-
comments: 'No down migration available'
1+
comments: "Transforms all uriPathSegment values to lowercase"
2+
warnings: "As this migration removes the distinction between uppercase and lowercase it might not be cleanly undone by the down migration."
3+
migration:
4+
- filters:
5+
- type: "NodeType"
6+
settings:
7+
nodeType: "Neos.Neos:Document"
8+
withSubTypes: TRUE
9+
# Custom transformation not possible in Neos < 9.0: https://neos-project.slack.com/archives/C04V4C6B0/p1752678184783919
10+
# transformations:
11+
# - type: 'Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase'
12+
# settings:
13+
# property: "uriPathSegment"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ composer require flowpack/seo-routing
5050
If you want to use the *toLowerCase* feature you should execute the migration that comes with this package:
5151

5252
```
53-
./flow node:migrate 20250124153030 --confirmation true
53+
./flow nodemigration:execute 20250124153030 --force
5454
```
5555

5656
> [!WARNING]

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"guzzlehttp/psr7": "^2.0",
1515
"php": "^8.1",
16-
"neos/neos": "^8.3|^9.0"
16+
"neos/neos": "^9.0"
1717
},
1818
"require-dev": {
1919
"phpstan/phpstan": "^2.1",

0 commit comments

Comments
 (0)