protected function reorderChildNodesByNodeType($workspaceName, $dryRun, NodeType $nodeType)
{
$nodeTypes = $this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), false);
$nodeTypes[$nodeType->getName()] = $nodeType;
if ($this->nodeTypeManager->hasNodeType((string) $nodeType)) {
$nodeType = $this->nodeTypeManager->getNodeType((string) $nodeType);
$nodeTypeNames[$nodeType->getName()] = $nodeType;
} else {
$this->output->outputLine('Node type "%s" does not exist', array((string) $nodeType));
exit(1);
}
/** @var $nodeType NodeType */
foreach ($nodeTypes as $nodeTypeName => $nodeType) {
$childNodes = $nodeType->getAutoCreatedChildNodes();
if ($childNodes === array()) {
continue;
}
foreach ($this->getNodeDataByNodeTypeAndWorkspace($nodeTypeName, $workspaceName) as $nodeData) {
/** @var NodeInterface $childNodeBefore */
$childNodeBefore = null;
$context = $this->nodeFactory->createContextMatchingNodeData($nodeData);
$node = $this->nodeFactory->createFromNodeData($nodeData, $context);
if (!$node instanceof NodeInterface) {
continue;
}
foreach ($childNodes as $childNodeName => $childNodeType) {
$childNode = $node->getNode($childNodeName);
if ($childNode) {
if ($childNodeBefore) {
if ($dryRun === false) {
if ($childNodeBefore->getIndex() >= $childNode->getIndex()) {
$childNode->moveAfter($childNodeBefore);
$this->output->outputLine('Moved node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath()));
}
} else {
$this->output->outputLine('Should move node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath()));
}
}
} else {
$this->output->outputLine('Missing child node named "%s" in "%s".', array($childNodeName, $node->getPath()));
}
$childNodeBefore = $childNode;
}
}
}
}