Skip to content

Commit

Permalink
TASK: add migration to convert all node uriPathSegment to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
t-heuser committed Jan 24, 2025
1 parent a074c64 commit b3a1b1d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Classes/Migration/Transformation/PropertyValueToLowercase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Flowpack\SeoRouting\Migration\Transformation;

use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;

class PropertyValueToLowercase extends AbstractTransformation
{
private string $propertyName;

public function setProperty(string $propertyName): void
{
$this->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;
}
}
16 changes: 16 additions & 0 deletions Migrations/ContentRepository/Version20250124153030.yaml
Original file line number Diff line number Diff line change
@@ -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'
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit b3a1b1d

Please sign in to comment.