diff --git a/Classes/Migration/Transformation/PropertyValueToLowercase.php b/Classes/Migration/Transformation/PropertyValueToLowercase.php index dde1f30..34c3547 100644 --- a/Classes/Migration/Transformation/PropertyValueToLowercase.php +++ b/Classes/Migration/Transformation/PropertyValueToLowercase.php @@ -4,38 +4,67 @@ namespace Flowpack\SeoRouting\Migration\Transformation; -use Neos\ContentRepository\Domain\Model\NodeData; -use Neos\ContentRepository\Migration\Transformations\AbstractTransformation; +use Neos\ContentRepository\Core\ContentRepository; +use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet; +use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties; +use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; +use Neos\ContentRepository\NodeMigration\Transformation\GlobalTransformationInterface; +use Neos\ContentRepository\NodeMigration\Transformation\NodeBasedTransformationInterface; +use Neos\ContentRepository\NodeMigration\Transformation\TransformationFactoryInterface; +use Neos\ContentRepository\NodeMigration\Transformation\TransformationStep; -class PropertyValueToLowercase extends AbstractTransformation +/** + * Transforms a specified property value of a node to lowercase. + */ +class PropertyValueToLowercase implements TransformationFactoryInterface { - private string $propertyName; - - public function setProperty(string $propertyName): void - { - $this->propertyName = $propertyName; - } - /** * @inheritDoc */ - public function isTransformable(NodeData $node) + public function build( + array $settings, + ContentRepository $contentRepository + ): GlobalTransformationInterface|NodeBasedTransformationInterface { - return $node->hasProperty($this->propertyName); - } + /** @var array{property: string} $settings */ + return new class( + $settings['property'] + ) implements NodeBasedTransformationInterface { - /** - * @inheritDoc - */ - public function execute(NodeData $node) - { - $currentPropertyValue = $node->getProperty($this->propertyName); - if (! is_string($currentPropertyValue)) { - return $node; - } - $newPropertyValue = strtolower($currentPropertyValue); - $node->setProperty($this->propertyName, $newPropertyValue); - - return $node; + private string $propertyName; + + public function __construct(string $propertyName) + { + $this->propertyName = $propertyName; + } + + public function execute( + Node $node, + DimensionSpacePointSet $coveredDimensionSpacePoints, + WorkspaceName $workspaceNameForWriting + ): TransformationStep + { + $currentProperty = $node->getProperty($this->propertyName); + + if (!is_string($currentProperty)) { + return TransformationStep::createEmpty(); + } + + $value = strtolower($currentProperty); + + return TransformationStep::fromCommand( + SetNodeProperties::create( + $workspaceNameForWriting, + $node->aggregateId, + $node->originDimensionSpacePoint, + PropertyValuesToWrite::fromArray([ + $this->propertyName => $value, + ]) + ) + ); + } + }; } } diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 77ff9d2..7526d74 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -15,3 +15,8 @@ Neos: middlewares: 'after routing': middleware: 'Flowpack\SeoRouting\RoutingMiddleware' + + ContentRepositoryRegistry: + nodeMigration: + transformationFactories: + PropertyValueToLowercase: Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase diff --git a/Migrations/ContentRepository/Version20250124153030.yaml b/Migrations/ContentRepository/Version20250124153030.yaml index a17f8d7..8792187 100644 --- a/Migrations/ContentRepository/Version20250124153030.yaml +++ b/Migrations/ContentRepository/Version20250124153030.yaml @@ -1,16 +1,12 @@ -up: - comments: 'Transforms all uriPathSegment values to lowercase' - warnings: 'As this migration removes the distinction between uppercase and lowercase it might not be cleanly undone by the down migration.' - migration: - - filters: - - type: 'NodeType' - settings: - nodeType: 'Neos.Neos:Document' - withSubTypes: TRUE - transformations: - - type: 'Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase' - settings: - property: 'uriPathSegment' - -down: - comments: 'No down migration available' +comments: "Transforms all uriPathSegment values to lowercase" +warnings: "As this migration removes the distinction between uppercase and lowercase it might not be cleanly undone by the down migration." +migration: + - filters: + - type: "NodeType" + settings: + nodeType: "Neos.Neos:Document" + withSubTypes: TRUE + transformations: + - type: 'PropertyValueToLowercase' + settings: + property: "uriPathSegment" diff --git a/README.md b/README.md index 69285ff..858802b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ composer require flowpack/seo-routing If you want to use the *toLowerCase* feature you should execute the migration that comes with this package: ``` -./flow node:migrate 20250124153030 --confirmation true +./flow nodemigration:execute 20250124153030 --force ``` > [!WARNING] diff --git a/composer.json b/composer.json index cbf61e9..2316a34 100644 --- a/composer.json +++ b/composer.json @@ -12,10 +12,14 @@ }, "require": { "guzzlehttp/psr7": "^2.0", - "php": "^8.1", - "neos/neos": "^8.3|^9.0" + "php": "^8.1" + }, + "conflict": { + "neos/neos": "<9.0" }, "require-dev": { + "neos/neos": "^9.0", + "neos/contentgraph-doctrinedbaladapter": "^9.0", "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", "phpstan/extension-installer": "^1.4",