Skip to content

Commit a898a0d

Browse files
Adrian Cerdeirat-heuser
andauthored
BUGFIX: Neos 9 Compatibility (#10)
#17 Co-authored-by: Timon Heuser <timon.heuser@sandstorm.de>
1 parent a9039c0 commit a898a0d

5 files changed

Lines changed: 79 additions & 45 deletions

File tree

Classes/Migration/Transformation/PropertyValueToLowercase.php

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,67 @@
44

55
namespace Flowpack\SeoRouting\Migration\Transformation;
66

7-
use Neos\ContentRepository\Domain\Model\NodeData;
8-
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;
7+
use Neos\ContentRepository\Core\ContentRepository;
8+
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
9+
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties;
10+
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite;
11+
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
12+
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
13+
use Neos\ContentRepository\NodeMigration\Transformation\GlobalTransformationInterface;
14+
use Neos\ContentRepository\NodeMigration\Transformation\NodeBasedTransformationInterface;
15+
use Neos\ContentRepository\NodeMigration\Transformation\TransformationFactoryInterface;
16+
use Neos\ContentRepository\NodeMigration\Transformation\TransformationStep;
917

10-
class PropertyValueToLowercase extends AbstractTransformation
18+
/**
19+
* Transforms a specified property value of a node to lowercase.
20+
*/
21+
class PropertyValueToLowercase implements TransformationFactoryInterface
1122
{
12-
private string $propertyName;
13-
14-
public function setProperty(string $propertyName): void
15-
{
16-
$this->propertyName = $propertyName;
17-
}
18-
1923
/**
2024
* @inheritDoc
2125
*/
22-
public function isTransformable(NodeData $node)
26+
public function build(
27+
array $settings,
28+
ContentRepository $contentRepository
29+
): GlobalTransformationInterface|NodeBasedTransformationInterface
2330
{
24-
return $node->hasProperty($this->propertyName);
25-
}
31+
/** @var array{property: string} $settings */
32+
return new class(
33+
$settings['property']
34+
) implements NodeBasedTransformationInterface {
2635

27-
/**
28-
* @inheritDoc
29-
*/
30-
public function execute(NodeData $node)
31-
{
32-
$currentPropertyValue = $node->getProperty($this->propertyName);
33-
if (! is_string($currentPropertyValue)) {
34-
return $node;
35-
}
36-
$newPropertyValue = strtolower($currentPropertyValue);
37-
$node->setProperty($this->propertyName, $newPropertyValue);
38-
39-
return $node;
36+
private string $propertyName;
37+
38+
public function __construct(string $propertyName)
39+
{
40+
$this->propertyName = $propertyName;
41+
}
42+
43+
public function execute(
44+
Node $node,
45+
DimensionSpacePointSet $coveredDimensionSpacePoints,
46+
WorkspaceName $workspaceNameForWriting
47+
): TransformationStep
48+
{
49+
$currentProperty = $node->getProperty($this->propertyName);
50+
51+
if (!is_string($currentProperty)) {
52+
return TransformationStep::createEmpty();
53+
}
54+
55+
$value = strtolower($currentProperty);
56+
57+
return TransformationStep::fromCommand(
58+
SetNodeProperties::create(
59+
$workspaceNameForWriting,
60+
$node->aggregateId,
61+
$node->originDimensionSpacePoint,
62+
PropertyValuesToWrite::fromArray([
63+
$this->propertyName => $value,
64+
])
65+
)
66+
);
67+
}
68+
};
4069
}
4170
}

Configuration/Settings.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ Neos:
1515
middlewares:
1616
'after routing':
1717
middleware: 'Flowpack\SeoRouting\RoutingMiddleware'
18+
19+
ContentRepositoryRegistry:
20+
nodeMigration:
21+
transformationFactories:
22+
PropertyValueToLowercase: Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
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+
transformations:
10+
- type: 'PropertyValueToLowercase'
11+
settings:
12+
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
},
1313
"require": {
1414
"guzzlehttp/psr7": "^2.0",
15-
"php": "^8.1",
16-
"neos/neos": "^8.3|^9.0"
15+
"php": "^8.1"
16+
},
17+
"conflict": {
18+
"neos/neos": "<9.0"
1719
},
1820
"require-dev": {
21+
"neos/neos": "^9.0",
22+
"neos/contentgraph-doctrinedbaladapter": "^9.0",
1923
"phpstan/phpstan": "^2.1",
2024
"phpstan/phpstan-phpunit": "^2.0",
2125
"phpstan/extension-installer": "^1.4",

0 commit comments

Comments
 (0)