diff --git a/Classes/Migration/Transformation/PropertyValueToLowercase.php b/Classes/Migration/Transformation/PropertyValueToLowercase.php index dde1f30..5a329a4 100644 --- a/Classes/Migration/Transformation/PropertyValueToLowercase.php +++ b/Classes/Migration/Transformation/PropertyValueToLowercase.php @@ -4,38 +4,58 @@ namespace Flowpack\SeoRouting\Migration\Transformation; -use Neos\ContentRepository\Domain\Model\NodeData; -use Neos\ContentRepository\Migration\Transformations\AbstractTransformation; - -class PropertyValueToLowercase extends AbstractTransformation +use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; +use Neos\ContentRepository\NodeMigration\Transformation\NodeBasedTransformationInterface; +use Neos\ContentRepository\Core\ContentRepository; +use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties; +use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite; +use Neos\ContentRepository\NodeMigration\Transformation\GlobalTransformationInterface; +use Neos\ContentRepository\NodeMigration\Transformation\TransformationFactoryInterface; +use Neos\ContentRepository\NodeMigration\Transformation\TransformationStep; + +/** + * 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) - { - return $node->hasProperty($this->propertyName); - } - /** - * @inheritDoc + * @param array $settings */ - public function execute(NodeData $node) + public function build(array $settings, ContentRepository $contentRepository): GlobalTransformationInterface|NodeBasedTransformationInterface { - $currentPropertyValue = $node->getProperty($this->propertyName); - if (! is_string($currentPropertyValue)) { - return $node; - } - $newPropertyValue = strtolower($currentPropertyValue); - $node->setProperty($this->propertyName, $newPropertyValue); - - return $node; + return new class( + $settings['property'] + ) implements NodeBasedTransformationInterface { + + 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 ($currentProperty !== null && is_string($currentProperty)) { + $value = strtolower($currentProperty); + + return TransformationStep::fromCommand( + SetNodeProperties::create( + $workspaceNameForWriting, + $node->aggregateId, + $node->originDimensionSpacePoint, + PropertyValuesToWrite::fromArray([ + $this->propertyName => $value, + ]) + ) + ); + } + + return TransformationStep::createEmpty(); + } + }; } } 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 5770e5f..d6050f0 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ -* [Flowpack.SeoRouting](#flowpackseorouting) - * [Sponsoring](#sponsoring) - * [Introduction](#introduction) - * [Features](#features) - * [Installation](#installation) - * [Configuration](#configuration) - * [Standard Configuration](#standard-configuration) - * [Trailing slash mode](#trailing-slash-mode) - * [Blocklist for redirects](#blocklist-for-redirects) - * [Thank you](#thank-you) +- [Flowpack.SeoRouting](#flowpackseorouting) + - [Sponsoring](#sponsoring) + - [Introduction](#introduction) + - [Features](#features) + - [Installation](#installation) + - [Configuration](#configuration) + - [Standard Configuration](#standard-configuration) + - [Trailing slash mode](#trailing-slash-mode) + - [Blocklist for redirects](#blocklist-for-redirects) + - [Thank you](#thank-you) @@ -46,7 +46,7 @@ Just require it via composer: 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` This migration transforms all the URLs of all your nodes to lowercase. It's irreversible. diff --git a/composer.json b/composer.json index cbf61e9..10822a0 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "guzzlehttp/psr7": "^2.0", "php": "^8.1", - "neos/neos": "^8.3|^9.0" + "neos/neos": "^9.0" }, "require-dev": { "phpstan/phpstan": "^2.1",