Skip to content

Commit d828089

Browse files
committed
TASK: add migration to convert all node uriPathSegment to lowercase
1 parent a074c64 commit d828089

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Flowpack\SeoRouting\Migration\Transformation;
6+
7+
use Neos\ContentRepository\Domain\Model\NodeData;
8+
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;
9+
10+
class PropertyValueToLowercase extends AbstractTransformation
11+
{
12+
private string $propertyName;
13+
14+
public function setProperty(string $propertyName): void
15+
{
16+
$this->propertyName = $propertyName;
17+
}
18+
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function isTransformable(NodeData $node)
23+
{
24+
return $node->hasProperty($this->propertyName);
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function execute(NodeData $node)
31+
{
32+
$currentPropertyValue = $node->getProperty($this->propertyName);
33+
$newPropertyValue = strtolower($currentPropertyValue);
34+
$node->setProperty($this->propertyName, $newPropertyValue);
35+
}
36+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
up:
2+
comments: 'Transforms all uriPathSegment values to lowercase'
3+
warnings: 'As this migration removes the distinction between uppercase and lowercase it might not be cleanly undone by the down migration.'
4+
migration:
5+
- filters:
6+
- type: 'NodeType'
7+
settings:
8+
nodeType: 'Neos.Neos:Document'
9+
withSubTypes: TRUE
10+
transformations:
11+
- type: 'Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase'
12+
settings:
13+
property: 'uriPathSegment'
14+
15+
down:
16+
comments: 'No down migration available'

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ Just require it via composer:
4343

4444
`composer require flowpack/seo-routing`
4545

46+
If you want to use the *toLowerCase* feature you should execute the migration that comes with this package:
47+
48+
`./flow node:migrate 20250124153030 --confirmation true`
49+
50+
This migration transforms all the URLs of all your nodes to lowercase. It's irreversible.
51+
4652
## Configuration
4753

4854
### Standard Configuration
@@ -52,7 +58,8 @@ with / at the end) and do all redirects with a 301 http status.
5258

5359
*Note: The lowercase redirect is deactivated by default, because you have to make sure, that there is
5460
no Neos page with an `uriPathSegment` with camelCase or upperspace letters - this would lead to redirects in the
55-
neverland.*
61+
neverland. You can achieve this by running the migration that ships with this package,
62+
see [installation](#installation).*
5663

5764
```
5865
Flowpack:

0 commit comments

Comments
 (0)