public function addMissingDefaultValuesByNodeType(NodeType $nodeType = null, $workspaceName, $dryRun)
{
$addedMissingDefaultValuesCount = 0;
$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) {
$defaultValues = $nodeType->getDefaultValuesForProperties();
foreach ($this->getNodeDataByNodeTypeAndWorkspace($nodeTypeName, $workspaceName) as $nodeData) {
/** @var NodeData $nodeData */
$context = $this->nodeFactory->createContextMatchingNodeData($nodeData);
$node = $this->nodeFactory->createFromNodeData($nodeData, $context);
if (!$node instanceof NodeInterface) {
continue;
}
if ($node instanceof Node && !$node->dimensionsAreMatchingTargetDimensionValues()) {
if ($node->getNodeData()->getDimensionValues() === []) {
$this->output->outputLine('Skipping node %s because it has no dimension values set', [$node->getPath()]);
} else {
$this->output->outputLine('Skipping node %s because it has invalid dimension values: %s', [$node->getPath(), json_encode($node->getNodeData()->getDimensionValues())]);
}
continue;
}
foreach ($defaultValues as $propertyName => $defaultValue) {
if ($propertyName[0] === '_') {
continue;
}
if (!$node->hasProperty($propertyName)) {
$addedMissingDefaultValuesCount++;
if (!$dryRun) {
$node->setProperty($propertyName, $defaultValue);
$this->output->outputLine('Set default value for property named "%s" in "%s" (%s)', array($propertyName, $node->getPath(), $node->getNodeType()->getName()));
} else {
$this->output->outputLine('Found missing default value for property named "%s" in "%s" (%s)', array($propertyName, $node->getPath(), $node->getNodeType()->getName()));
}
}
}
}
}
if ($addedMissingDefaultValuesCount !== 0) {
if ($dryRun === false) {
$this->persistenceManager->persistAll();
$this->output->outputLine('Added %s new default values', array($addedMissingDefaultValuesCount));
} else {
$this->output->outputLine('%s missing default values need to be set', array($addedMissingDefaultValuesCount));
}
}
}