|
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; |
| 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; |
9 | 17 |
|
10 | | -class PropertyValueToLowercase extends AbstractTransformation |
| 18 | +/** |
| 19 | + * Transforms a specified property value of a node to lowercase. |
| 20 | + */ |
| 21 | +class PropertyValueToLowercase implements TransformationFactoryInterface |
11 | 22 | { |
12 | | - private string $propertyName; |
13 | | - |
14 | | - public function setProperty(string $propertyName): void |
15 | | - { |
16 | | - $this->propertyName = $propertyName; |
17 | | - } |
18 | | - |
19 | 23 | /** |
20 | 24 | * @inheritDoc |
21 | 25 | */ |
22 | | - public function isTransformable(NodeData $node) |
| 26 | + public function build( |
| 27 | + array $settings, |
| 28 | + ContentRepository $contentRepository |
| 29 | + ): GlobalTransformationInterface|NodeBasedTransformationInterface |
23 | 30 | { |
24 | | - return $node->hasProperty($this->propertyName); |
25 | | - } |
| 31 | + /** @var array{property: string} $settings */ |
| 32 | + return new class( |
| 33 | + $settings['property'] |
| 34 | + ) implements NodeBasedTransformationInterface { |
26 | 35 |
|
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 | + }; |
40 | 69 | } |
41 | 70 | } |
0 commit comments