|
4 | 4 |
|
5 | 5 | namespace Flowpack\SeoRouting\Migration\Transformation; |
6 | 6 |
|
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 |
12 | 22 | { |
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 | | - |
28 | 23 | /** |
29 | | - * @inheritDoc |
| 24 | + * @param array<string,string> $settings |
30 | 25 | */ |
31 | | - public function execute(NodeData $node) |
| 26 | + public function build(array $settings, ContentRepository $contentRepository): GlobalTransformationInterface|NodeBasedTransformationInterface |
32 | 27 | { |
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 | + }; |
41 | 60 | } |
42 | 61 | } |
0 commit comments