Adds missing default values for the given node type

@param NodeType $nodeType
@param string $workspaceName
@param boolean $dryRun
@return void
@throws NodeConfigurationException
@throws NodeTypeNotFoundException
337910
public function addMissingDefaultValuesByNodeType(NodeType $nodeType, $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->dispatch(self::EVENT_ERROR, sprintf('Node type <i>%s</i> does not exist', $nodeType));
            return;
        }

        /** @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->dispatch(self::EVENT_NOTICE, sprintf('Skipping node <i>%s</i> because it has no dimension values set', $node->getPath()));
                    } else {
                        $this->dispatch(self::EVENT_NOTICE, sprintf('Skipping node <i>%s</i> because it has invalid dimension values: %s', $node->getPath(), json_encode($node->getNodeData()->getDimensionValues())));
                    }
                    continue;
                }

                foreach ($defaultValues as $propertyName => $defaultValue) {
                    if ($propertyName[0] === '_' || $node->hasProperty($propertyName)) {
                        continue;
                    }

                    $taskDescription = sprintf('Set default value for property named "<i>%s</i>" in "<i>%s</i>" (<i>%s</i>)', $propertyName, $node->getPath(), $node->getNodeType()->getName());
                    $taskClosure = function () use ($node, $propertyName ,$defaultValue) {
                        $node->setProperty($propertyName, $defaultValue);
                    };
                    $this->dispatch(self::EVENT_TASK, $taskDescription, $taskClosure);
                    $addedMissingDefaultValuesCount++;
                }
            }
        }

        if ($addedMissingDefaultValuesCount !== 0) {
            if ($dryRun === false) {
                $this->persistenceManager->persistAll();
                $this->dispatch(self::EVENT_NOTICE, sprintf('Added <i>%d</i> new default values', $addedMissingDefaultValuesCount));
            } else {
                $this->dispatch(self::EVENT_NOTICE, sprintf('<i>%d</i> missing default values need to be set', $addedMissingDefaultValuesCount));
            }
        }
    }
474860
private function addBlock($blockType, $blockOptions = null)
    {
        //====================================================================//
        // Commit Last Created if not already done
        if (!empty($this->new)) {
            $this->commit();
        }
        //====================================================================//
        // Unset Current
        $this->new = null;
        //====================================================================//
        // Create new empty block
        $this->new = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
        //====================================================================//
        // Set Block Type
        $this->new->type = $blockType;
        //====================================================================//
        // Set Block Options
        $this->new->options = $blockOptions;
        //====================================================================//
        // Set Block Data
        $this->new->data = array();

        return $this;
    }
558492
public static function encode($nodeType, $databaseId)
    {
        @trigger_error(
            'IDEncoder::encode has been deprecated since v1.1 and will be removed in v2.0, use IDEncoder::encode() instead',
            E_USER_DEPRECATED
        );

        return base64_encode(sprintf('%s%s%s', $nodeType, self::DIVIDER, $databaseId));
    }
935873
public function nodeExistsInWorkspace(NodeInterface $node, Workspace $workspace)
    {
        $context = ['workspaceName' => $workspace->getName()];
        $flowQuery = new FlowQuery([$node]);

        return $flowQuery->context($context)->count() > 0;
    }
168790
@Override
    public void nodeType(int index, String nodeType) throws OperationFormatException {

        assertValidType(nodeType);
        validatedNodeType(index, nodeType);
    }
1019381
public function getByWorkspaceAndResourceType(
        Workspace $workspace,
        ResourceType $resourceType
    )
    {
        return $this->resourceNodeRepo->findBy(
            array('workspace' => $workspace, 'resourceType' => $resourceType),
            array('name' => 'ASC')
        );
    }
202034
private function addNodeJSConfiguration(NodeBuilder $node)
    {
        $node
            ->arrayNode('node')
            ->addDefaultsIfNotSet()
            ->children()
                ->arrayNode('binary')
                    ->addDefaultsIfNotSet()
                    ->beforeNormalization()
                    ->ifString()
                        ->then(function ($value) {
                            return [
                                'win32'     => $value,
                                'win64'     => $value,
                                'linux_x32' => $value,
                                'linux_x64' => $value,
                                'darwin'    => $value,
                                'fallback'  => $value,
                            ];
                        })
                    ->end()
                    ->children()
                        ->scalarNode('win32')->defaultValue('node')->end()
                        ->scalarNode('win64')->defaultValue('node')->end()
                        ->scalarNode('linux_x32')->defaultValue('node')->end()
                        ->scalarNode('linux_x64')->defaultValue('node')->end()
                        ->scalarNode('darwin')->defaultValue('node')->end()
                        ->scalarNode('fallback')->defaultValue('node')->end()
                    ->end()
                ->end()
                ->scalarNode('npm_packages_path')->defaultNull()->end()
                ->scalarNode('node_modules_path')->defaultNull()->end()
            ->end();
    }
751012
@Override
    public KeywordLiteral setType(int nodeType) {
        if (!(nodeType == Token.THIS
              || nodeType == Token.NULL
              || nodeType == Token.TRUE
              || nodeType == Token.FALSE
              || nodeType == Token.DEBUGGER))
            throw new IllegalArgumentException("Invalid node type: "
                                               + nodeType);
        type = nodeType;
        return this;
    }
71353
protected void addNode(ClusterNode node,
                         Map<ResourceType, String> resourceInfos) {
    synchronized (node) {
      // 1: primary
      nameToNode.put(node.getName(), node);
      faultManager.addNode(node.getName(), resourceInfos.keySet());
      nameToApps.put(node.getName(), resourceInfos);
      hostsToSessions.put(node, new HashSet<String>());
      clusterManager.getMetrics().restartTaskTracker(1);
      setAliveDeadMetrics();

      // 2: update runnable indices
      for (Map.Entry<ResourceType, RunnableIndices> entry :
          typeToIndices.entrySet()) {
        ResourceType type = entry.getKey();
        if (resourceInfos.containsKey(type)) {
          if (node.checkForGrant(Utilities.getUnitResourceRequest(type),
                                 resourceLimit)) {
            RunnableIndices r = entry.getValue();
            r.addRunnable(node);
          }
        }
      }
    }
  }
1139914
public void setType( AstNode node,
                         String type ) {
        CheckArg.isNotNull(node, "node");
        CheckArg.isNotNull(type, "parent");
        node.setProperty(JCR_MIXIN_TYPES, type);
    }
1099225
public function setNodeType(NodeType $nodeType): void
    {
        if ($this->getNodeType() === $nodeType) {
            return;
        }
        if (!$this->isNodeDataMatchingContext()) {
            $this->materializeNodeData();
        }
        $this->nodeData->setNodeType($nodeType);

        $this->context->getFirstLevelNodeCache()->flush();
        $this->emitNodeUpdated($this);
    }
544681
protected function transformNodeType(NodeType $nodeType)
    {
        $this->setNodeTypeByKey($nodeType->getKey());

        foreach ($this->translations as $translation)
        {
            $translation->source_type = $nodeType->getName();
        }
    }
1311425
public function addDefaultPerms(ResourceType $type)
    {
        /** @var MaskDecoder[] $decoders */
        $decoders = $this->maskRepo->findBy(['resourceType' => $type]);

        $actionNames = [];
        foreach ($decoders as $decoder) {
            $actionNames[] = $decoder->getName();
        }

        $createdPerms = [];
        // Add only non-existent default actions
        $defaultActions = array_diff(self::$defaultActions, $actionNames);

        foreach ($defaultActions as $i => $action) {
            $maskDecoder = new MaskDecoder();
            $maskDecoder->setValue(pow(2, $i));
            $maskDecoder->setName($action);
            $maskDecoder->setResourceType($type);
            $this->om->persist($maskDecoder);
            $createdPerms[$action] = $maskDecoder;
        }

        $this->om->flush();
    }
664201
protected function configureImage(NodeInterface $node, NodeType $nodeType, array $config = [])
    {
        $this->configureCreateAssistanceChildNodes($node, $nodeType, $config);

        switch ($node->getParent()->getNodeType()->getName()) {
            // Image slider: enable caption by default
            case 'M12.Foundation:Orbit':
                if (!$node->getProperty('hasCaption')) {
                    $node->setProperty('hasCaption', true);
                    $node->setProperty('caption', 'Image caption');
                }
                break;
        }
    }
114126
public function removeUndefinedProperties($workspaceName, /** @noinspection PhpUnusedParameterInspection */$dryRun, NodeType $nodeType = null)
    {
        $this->dispatch(self::EVENT_NOTICE, 'Checking for undefined properties ...');

        /** @var \Neos\ContentRepository\Domain\Model\Workspace $workspace */
        $workspace = $this->workspaceRepository->findByIdentifier($workspaceName);

        $nodesWithUndefinedPropertiesNodes = [];
        $undefinedPropertiesCount = 0;
        $nodes = $nodeType !== null ? $this->getNodeDataByNodeTypeAndWorkspace($nodeType, $workspaceName) : $this->nodeDataRepository->findByWorkspace($workspace);
        foreach ($nodes as $nodeData) {
            try {
                /** @var NodeData $nodeData */
                if ($nodeData->getNodeType()->getName() === 'unstructured') {
                    continue;
                }
                $context = $this->nodeFactory->createContextMatchingNodeData($nodeData);
                $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
                if (!$node instanceof NodeInterface) {
                    continue;
                }
                $nodeType = $node->getNodeType();

                $nodeTypePropertyNames = array_keys($nodeType->getProperties());
                $undefinedProperties = [];

                foreach ($node->getProperties() as $propertyName => $propertyValue) {
                    if (!in_array($propertyName, $nodeTypePropertyNames)) {
                        $undefinedProperties[] = $propertyName;
                    }
                }
                if ($undefinedProperties !== []) {
                    $nodesWithUndefinedPropertiesNodes[$node->getIdentifier()] = ['node' => $node, 'undefinedProperties' => $undefinedProperties];
                    foreach ($undefinedProperties as $undefinedProperty) {
                        $undefinedPropertiesCount++;
                        $this->dispatch(self::EVENT_NOTICE, sprintf('Found undefined property named "<i>%s</i>" in "<i>%s</i>" (<i>%s</i>)', $undefinedProperty, $node->getPath(), $node->getNodeType()->getName()));
                    }
                }
            } /** @noinspection PhpRedundantCatchClauseInspection */ catch (NodeTypeNotFoundException $exception) {
                $this->dispatch(self::EVENT_NOTICE, sprintf('Skipped undefined node type in "%s"', $nodeData->getPath()));
            }
        }

        if ($undefinedPropertiesCount > 0) {
            $taskDescription = sprintf('Remove <i>%d</i> undefined propert%s.', $undefinedPropertiesCount, $undefinedPropertiesCount > 1 ? 'ies' : 'y');
            $taskClosure = function () use ($nodesWithUndefinedPropertiesNodes) {
                foreach ($nodesWithUndefinedPropertiesNodes as $nodesWithUndefinedPropertiesNode) {
                    /** @var NodeInterface $node */
                    $node = $nodesWithUndefinedPropertiesNode['node'];
                    foreach ($nodesWithUndefinedPropertiesNode['undefinedProperties'] as $undefinedProperty) {
                        if ($node->hasProperty($undefinedProperty)) {
                            $node->removeProperty($undefinedProperty);
                        }
                    }
                }
            };
            $taskRequiresConfirmation = true;
            $this->dispatch(self::EVENT_TASK, $taskDescription, $taskClosure, $taskRequiresConfirmation);
        }

        $this->persistenceManager->persistAll();
    }
223806
protected function loadNodeTypes()
    {
        $this->fullNodeTypeConfigurations = $this->fullConfigurationCache->get('fullNodeTypeConfigurations');
        $fillFullConfigurationCache = !is_array($this->fullNodeTypeConfigurations);

        $completeNodeTypeConfiguration = $this->configurationManager->getConfiguration('NodeTypes');

        foreach (array_keys($completeNodeTypeConfiguration) as $nodeTypeName) {
            if (!is_array($completeNodeTypeConfiguration[$nodeTypeName])) {
                continue;
            }
            $nodeType = $this->loadNodeType($nodeTypeName, $completeNodeTypeConfiguration, (isset($this->fullNodeTypeConfigurations[$nodeTypeName]) ? $this->fullNodeTypeConfigurations[$nodeTypeName] : null));
            if ($fillFullConfigurationCache) {
                $this->fullNodeTypeConfigurations[$nodeTypeName] = $nodeType->getFullConfiguration();
            }
        }

        if ($fillFullConfigurationCache) {
            $this->fullConfigurationCache->set('fullNodeTypeConfigurations', $this->fullNodeTypeConfigurations);
        }
        $this->fullNodeTypeConfigurations = null;
    }
301181
protected function addProperty($nodeType, $propertyName, array $propertyConfiguration)
    {
        if (isset($this->properties[$propertyName])) {
            $this->properties[$propertyName]->domains[] = $nodeType;
        } else {
            $propertyLabel = isset($propertyConfiguration['ui']['label']) ? $propertyConfiguration['ui']['label'] : $propertyName;
            $this->properties[$propertyName] = (object) [
                'comment' => $propertyLabel,
                'comment_plain' => $propertyLabel,
                'domains' => [$nodeType],
                'id' => $propertyName,
                'label' => $propertyName,
                'ranges' => [],
                'min' => 0,
                'max' => -1
            ];
        }
    }