Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 49 additions & 29 deletions Classes/Migration/Transformation/PropertyValueToLowercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,string> $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();
}
};
}
}
5 changes: 5 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ Neos:
middlewares:
'after routing':
middleware: 'Flowpack\SeoRouting\RoutingMiddleware'

ContentRepositoryRegistry:
nodeMigration:
transformationFactories:
PropertyValueToLowercase: Flowpack\SeoRouting\Migration\Transformation\PropertyValueToLowercase
28 changes: 12 additions & 16 deletions Migrations/ContentRepository/Version20250124153030.yaml
Original file line number Diff line number Diff line change
@@ -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"
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<!-- TOC -->

* [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)

<!-- TOC -->

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down