Skip to content
Merged
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
81 changes: 55 additions & 26 deletions Classes/Migration/Transformation/PropertyValueToLowercase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,67 @@

namespace Flowpack\SeoRouting\Migration\Transformation;

use Neos\ContentRepository\Domain\Model\NodeData;
use Neos\ContentRepository\Migration\Transformations\AbstractTransformation;
use Neos\ContentRepository\Core\ContentRepository;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\Feature\NodeModification\Command\SetNodeProperties;
use Neos\ContentRepository\Core\Feature\NodeModification\Dto\PropertyValuesToWrite;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\NodeMigration\Transformation\GlobalTransformationInterface;
use Neos\ContentRepository\NodeMigration\Transformation\NodeBasedTransformationInterface;
use Neos\ContentRepository\NodeMigration\Transformation\TransformationFactoryInterface;
use Neos\ContentRepository\NodeMigration\Transformation\TransformationStep;

class PropertyValueToLowercase extends AbstractTransformation
/**
* 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)
public function build(
array $settings,
ContentRepository $contentRepository
): GlobalTransformationInterface|NodeBasedTransformationInterface
{
return $node->hasProperty($this->propertyName);
}
/** @var array{property: string} $settings */
return new class(
$settings['property']
) implements NodeBasedTransformationInterface {

/**
* @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;
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 (!is_string($currentProperty)) {
return TransformationStep::createEmpty();
}

$value = strtolower($currentProperty);

return TransformationStep::fromCommand(
SetNodeProperties::create(
$workspaceNameForWriting,
$node->aggregateId,
$node->originDimensionSpacePoint,
PropertyValuesToWrite::fromArray([
$this->propertyName => $value,
])
)
);
}
};
}
}
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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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
./flow nodemigration:execute 20250124153030 --force
```

> [!WARNING]
Expand Down
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
},
"require": {
"guzzlehttp/psr7": "^2.0",
"php": "^8.1",
"neos/neos": "^8.3|^9.0"
"php": "^8.1"
},
"conflict": {
"neos/neos": "<9.0"
},
"require-dev": {
"neos/neos": "^9.0",
"neos/contentgraph-doctrinedbaladapter": "^9.0",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/extension-installer": "^1.4",
Expand Down
Loading