diff --git a/Classes/Migration/Transformation/PropertyValueToLowercase.php b/Classes/Migration/Transformation/PropertyValueToLowercase.php new file mode 100644 index 0000000..dde1f30 --- /dev/null +++ b/Classes/Migration/Transformation/PropertyValueToLowercase.php @@ -0,0 +1,41 @@ +propertyName = $propertyName; + } + + /** + * @inheritDoc + */ + public function isTransformable(NodeData $node) + { + return $node->hasProperty($this->propertyName); + } + + /** + * @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; + } +} diff --git a/Migrations/ContentRepository/Version20250124153030.yaml b/Migrations/ContentRepository/Version20250124153030.yaml new file mode 100644 index 0000000..a17f8d7 --- /dev/null +++ b/Migrations/ContentRepository/Version20250124153030.yaml @@ -0,0 +1,16 @@ +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' diff --git a/README.md b/README.md index cdf023d..7d91d23 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,12 @@ Just require it via composer: `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` + +This migration transforms all the URLs of all your nodes to lowercase. It's irreversible. + ## Configuration ### Standard Configuration @@ -52,7 +58,8 @@ with / at the end) and do all redirects with a 301 http status. *Note: The lowercase redirect is deactivated by default, because you have to make sure, that there is no Neos page with an `uriPathSegment` with camelCase or upperspace letters - this would lead to redirects in the -neverland.* +neverland. You can achieve this by running the migration that ships with this package, +see [installation](#installation).* ``` Flowpack: