From 6ddffb23ca779f99428bdec95014a28c23eb9ae5 Mon Sep 17 00:00:00 2001 From: Jon Uhlmann Date: Sun, 23 Aug 2020 17:07:13 +0200 Subject: [PATCH] :sparkles: Add migration for flat structure --- .../FlatStructureTransformation.php | 59 +++++++++++++++++++ .../Version20200823164840.yaml | 12 ++++ 2 files changed, 71 insertions(+) create mode 100644 Classes/ContentRepository/Transformations/FlatStructureTransformation.php create mode 100644 Migrations/ContentRepository/Version20200823164840.yaml diff --git a/Classes/ContentRepository/Transformations/FlatStructureTransformation.php b/Classes/ContentRepository/Transformations/FlatStructureTransformation.php new file mode 100644 index 0000000..856aa50 --- /dev/null +++ b/Classes/ContentRepository/Transformations/FlatStructureTransformation.php @@ -0,0 +1,59 @@ +getNumberOfChildNodes('Neos.Neos:ContentCollection', $node->getWorkspace(), $node->getDimensions()); + return ($numberOfChildNodes > 0); + } + + /** + * @param NodeData $node + * @return void + */ + public function execute(NodeData $node) + { + $contentContext = $this->createContentContext('live', []); + $containerNode = $contentContext->getNodeByIdentifier($node->getIdentifier()); + $contentCollections = $containerNode->getChildNodes('Neos.Neos:ContentCollection'); + + foreach ($contentCollections as $contentCollection) { + /** @var NodeInterface $contentCollection */ + if ($contentCollection->hasChildNodes()) { + $this->moveChildNodes($contentCollection->getChildNodes(), $containerNode); + $contentCollection->remove(); + } + } + } + + /** + * @param array $children + * @param NodeInterface $container + */ + protected function moveChildNodes(array $children, NodeInterface $container) + { + foreach ($children as $childNode) { + if ($childNode instanceof NodeInterface) { + /** @var NodeInterface $childNode */ + $childNode->moveInto($container); + } + } + } +} diff --git a/Migrations/ContentRepository/Version20200823164840.yaml b/Migrations/ContentRepository/Version20200823164840.yaml new file mode 100644 index 0000000..b4330a4 --- /dev/null +++ b/Migrations/ContentRepository/Version20200823164840.yaml @@ -0,0 +1,12 @@ +up: + comments: 'Migrate content collection of images to a flat structure' + migration: + - filters: + - type: 'NodeType' + settings: + nodeType: 'Jonnitto.ImagesInARow:Container' + transformations: + - type: 'Jonnitto\ImagesInARow\ContentRepository\Transformations\FlatStructureTransformation' + settings: [] +down: + comments: 'No down migration available'