@param array        $nodes
@param int          $reindexed
@param SymfonyStyle $io
@param array        $context
@param int          $batch
@param bool         $dryRun
@param bool         $skipErrors

@throws \Throwable
338988
protected function reindex(array $nodes, int &$reindexed, SymfonyStyle $io, array $context, int $batch, bool $dryRun = false, bool $skipErrors = false): void
    {
        if ($dryRun) {
            $io->note(sprintf('DRY RUN - Would reindex node batch %d here.', $batch));
        } else {
            try {
                $this->ncrSearch->indexNodes($nodes, $context);
            } catch (\Throwable $e) {
                $io->error($e->getMessage());
                $io->note(sprintf('Failed to index batch %d.', $batch));
                $io->newLine(2);

                if (!$skipErrors) {
                    throw $e;
                }
            }
        }

        $reindexed += count($nodes);
    }
113107
function reindexNodes () {
  var child = this.node.firstChild;
  this._length = 0;
  
  while (child) {
    this[this._length++] = child;
    child = child.nextSibling;
  }
}
298948
public function bindPersistentFields(Node &$node, Errors &$errors, array $fields, array $rawFields)
    {
        $pFields = array_intersect_key($fields,array_flip($this->NodeDBMeta->getPersistentFields()));

        foreach($pFields as $key => $value) {
//            $validation = $this->NodeDBMeta->getValidation($key);

            try {
                $pFields[$key] = $this->TypeConverter->convertFromString($this->NodeDBMeta->getValidationExpression($key), $fields[$key], $rawFields[$key]);
            } catch(TypeConversionException $tce)
            {
                $errors->addFieldError('invalid', $key, 'field', $this->NodeDBMeta->getFieldTitle($key), $fields[$key], $tce->getMessage());
            }
        }

        $node->setFromArray($pFields);

    }
602714
static function processNodeCombining( $useComments, $php, $tpl, &$node, &$resourceData, &$newNode )
    {
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $children = $node[1];
            $newNode[0] = $nodeType;
            $newNode[1] = false;
            if ( $children )
            {
                eZTemplateCompiler::processNodeCombiningChildren( $useComments, $php, $tpl, $children, $resourceData, $newNode );
            }
        }
        else
            $tpl->error( 'processNodeCombining', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
    }
1074262
public function batch( $parallelRequests = null, callable $callback = null ) {
        /** @noinspection PhpParamsInspection */
        if( !isset( $callback ) && is_callable( $parallelRequests )) {
            $callback = $parallelRequests;
            $parallelRequests = null;
        }

        if( is_null( $parallelRequests )) {
            $parallelRequests = 6;
        }

        $size = $this->maxPageSize();

        $firstPageResponse = $this->request( $this->createPaginatedRequestQuery( 0, $size ) );
        $header_values = $firstPageResponse->getResponse()->getHeader('X-Result-Total');
        $total = array_shift($header_values);

        call_user_func( $callback, $firstPageResponse->json() );
        unset( $firstPageResponse );

        $lastPage = ceil( $total / $size );

        for( $page = 1; $page < $lastPage; ) {
            $batchRequests = [];

            for( $batchPage = 0; $batchPage < $parallelRequests && $page + $batchPage < $lastPage; $batchPage++ ) {
                $batchRequests[] = $this->createPaginatedRequestQuery( $page + $batchPage, $size );
            }

            $responses = $this->requestMany( $batchRequests );

            foreach( $responses as $response ) {
                call_user_func( $callback, $response->json() );
            }

            unset( $responses );

            $page += $parallelRequests;
        }
    }
505033
private function addImplicitReturn(array $nodes)
    {
        // If nodes is empty, it can't have a return value.
        if (empty($nodes)) {
            return [new Return_(NoReturnValue::create())];
        }

        $last = \end($nodes);

        // Special case a few types of statements to add an implicit return
        // value (even though they technically don't have any return value)
        // because showing a return value in these instances is useful and not
        // very surprising.
        if ($last instanceof If_) {
            $last->stmts = $this->addImplicitReturn($last->stmts);

            foreach ($last->elseifs as $elseif) {
                $elseif->stmts = $this->addImplicitReturn($elseif->stmts);
            }

            if ($last->else) {
                $last->else->stmts = $this->addImplicitReturn($last->else->stmts);
            }
        } elseif ($last instanceof Switch_) {
            foreach ($last->cases as $case) {
                // only add an implicit return to cases which end in break
                $caseLast = \end($case->stmts);
                if ($caseLast instanceof Break_) {
                    $case->stmts = $this->addImplicitReturn(\array_slice($case->stmts, 0, -1));
                    $case->stmts[] = $caseLast;
                }
            }
        } elseif ($last instanceof Expr && !($last instanceof Exit_)) {
            // @codeCoverageIgnoreStart
            $nodes[\count($nodes) - 1] = new Return_($last, [
                'startLine' => $last->getLine(),
                'endLine'   => $last->getLine(),
            ]);
        // @codeCoverageIgnoreEnd
        } elseif ($last instanceof Expression && !($last->expr instanceof Exit_)) {
            // For PHP Parser 4.x
            $nodes[\count($nodes) - 1] = new Return_($last->expr, [
                'startLine' => $last->getLine(),
                'endLine'   => $last->getLine(),
            ]);
        } elseif ($last instanceof Namespace_) {
            $last->stmts = $this->addImplicitReturn($last->stmts);
        }

        // Return a "no return value" for all non-expression statements, so that
        // PsySH can suppress the `null` that `eval()` returns otherwise.
        //
        // Note that statements special cased above (if/elseif/else, switch)
        // _might_ implicitly return a value before this catch-all return is
        // reached.
        //
        // We're not adding a fallback return after namespace statements,
        // because code outside namespace statements doesn't really work, and
        // there's already an implicit return in the namespace statement anyway.
        if (self::isNonExpressionStmt($last)) {
            $nodes[] = new Return_(NoReturnValue::create());
        }

        return $nodes;
    }
306084
public function updateNodes(array $nodes, $flush = true)
    {
        foreach ($nodes as $node) {
            $node->setSiterootId($this->siterootId);

            $this->entityManager->persist($node);
        }

        if ($flush) {
            $this->entityManager->flush();
        }

        return $this;
    }
588614
private function setFieldErrorsAndFocus(array $nodes)
    {
        foreach ($nodes as $nodeKey => $node) {
            if (!($node instanceof Field) && !($node instanceof Fieldset)) {
                throw new \Exception('Invalid node');
            }

            if ($node instanceof Field) {
                if (method_exists($node, 'getValue') && mb_strlen($node->getValue()) == 0 && mb_strlen($this->focusFieldId) == 0) {
                    $this->focusFieldId = $node->getId();
                }

                if ($node->getError()) {
                    $this->fieldErrorMessages[] = $node->getErrorMessage();
                    if (!$this->hasError()) {
                        $this->errorMessage = self::GENERAL_ERROR_MESSAGE;
                        $this->focusFieldId = $node->getId();
                    }
                }

            } else {
                // Fieldset
                if (!$this->hasError()) {
                    if ($node->hasError()) {
                        $this->errorMessage = self::GENERAL_ERROR_MESSAGE;
                    }
                    $this->setFieldErrorsAndFocus($node->getNodes());
                }
            }
        }
    }
787009
function skip($numRows)
    {
        $this->getNodes()->offset = $numRows !== null ? new Offset($numRows) : null;
        return $this;
    }
146328
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Stmt\GroupUse || ! $parent instanceof PhpFileModelInterface) {
            throw new Exception('GroupUseNodeParser is made to parse a use group node');
        }

        if ($this->validateType($node->type)) {
            $prefix = $node->prefix->toString();
            foreach ($node->uses as $use) {
                if ($this->validateType($node->type)) {
                    $parent->addUse($use->getAlias()->name, $prefix . '\\' . $use->name->toString());
                }
            }
        }
    }
100082
static function processNodeTransformationRoot( $useComments, $php, $tpl, &$node, &$resourceData )
    {
        $nodeType = $node[0];
        if ( $nodeType == eZTemplate::NODE_ROOT )
        {
            $children = $node[1];
            $newNode = array( $nodeType,
                              false );
            if ( $children )
            {
                $newChildren = array();
                foreach ( $children as $childNode )
                {
                    $newChildNode = eZTemplateCompiler::processNodeTransformationChild( $useComments, $php, $tpl, $childNode, $resourceData );
                    if ( !$newChildNode )
                        $newChildren[] = $childNode;
                    else
                        $newChildren = array_merge( $newChildren, $newChildNode );
                }
                if ( count( $newChildren ) > 0 )
                    $newNode[1] = $newChildren;
            }
            return $newNode;
        }
        else
            $tpl->error( 'processNodeTransformation', "Unknown root type $nodeType, should be " . eZTemplate::NODE_ROOT );
        return false;
    }
514357
public function run(string $file, Node $node): array
    {
        // This inspection only works to top level statements in each file.
        if ($this->inspectedFile === $file) {
            return [];
        }

        $found = false;
        foreach ($node->children as $child) {
            if (!$child instanceof Node) {
                continue;
            }

            if ($child->kind !== \ast\AST_DECLARE) {
                continue;
            }

            $declares = $child->children["declares"];
            if ($declares->kind !== \ast\AST_CONST_DECL) {
                continue;
            }

            foreach ($declares->children as $declare) {
                if ($declare->kind === \ast\AST_CONST_ELEM && $declare->children["name"] === "strict_types") {
                    $found = true;
                }
            }
        }
        $this->inspectedFile = $file;

        if (!$found) {
            return [new Hint(
                self::HINT_TYPE,
                self::HINT_MESSAGE,
                $file,
                $node->lineno,
                self::HINT_LINK
            )];
        }

        return [];
    }
28670
public function execute(NodeData $node)
    {
        foreach ($node->getNodeType()->getProperties() as $propertyName => $propertyConfiguration) {
            if (isset($propertyConfiguration['type']) && in_array(trim($propertyConfiguration['type']), $this->getHandledObjectTypes())) {
                if (!isset($nodeProperties)) {
                    $nodeRecordQuery = $this->entityManager->getConnection()->prepare('SELECT properties FROM typo3_typo3cr_domain_model_nodedata WHERE persistence_object_identifier=?');
                    $nodeRecordQuery->execute([$this->persistenceManager->getIdentifierByObject($node)]);
                    $nodeRecord = $nodeRecordQuery->fetch(\PDO::FETCH_ASSOC);
                    $nodeProperties = unserialize($nodeRecord['properties']);
                }

                if (!isset($nodeProperties[$propertyName]) || !is_object($nodeProperties[$propertyName])) {
                    continue;
                }

                /** @var Asset $assetObject */
                $assetObject = $nodeProperties[$propertyName];
                $nodeProperties[$propertyName] = null;

                $stream = $assetObject->getResource()->getStream();

                if ($stream === false) {
                    continue;
                }

                fclose($stream);
                $objectType = TypeHandling::getTypeForValue($assetObject);
                $objectIdentifier = ObjectAccess::getProperty($assetObject, 'Persistence_Object_Identifier', true);

                $nodeProperties[$propertyName] = [
                    '__flow_object_type' => $objectType,
                    '__identifier' => $objectIdentifier
                ];
            }
        }

        if (isset($nodeProperties)) {
            $nodeUpdateQuery = $this->entityManager->getConnection()->prepare('UPDATE typo3_typo3cr_domain_model_nodedata SET properties=? WHERE persistence_object_identifier=?');
            $nodeUpdateQuery->execute([serialize($nodeProperties), $this->persistenceManager->getIdentifierByObject($node)]);
        }
    }
840884
public function beforeTraverse(array $nodes) : array
    {
        // quick fix - if the list is empty, replace it it
        if (! $nodes) {
            return (new ParserFactory())
                ->create(ParserFactory::PREFER_PHP7)
                ->parse(file_get_contents($this->reflectedClass->getFileName()));
        }

        return $nodes;
    }
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));
            }
        }
    }
966346
public function discardAction(array $nodeContextPaths)
    {
        try {
            foreach ($nodeContextPaths as $contextPath) {
                $node = $this->nodeService->getNodeFromContextPath($contextPath, null, null, true);
                if ($node->isRemoved() === true) {
                    // When discarding node removal we should re-create it
                    $updateNodeInfo = new UpdateNodeInfo();
                    $updateNodeInfo->setNode($node);
                    $updateNodeInfo->recursive();

                    $updateParentNodeInfo = new UpdateNodeInfo();
                    $updateParentNodeInfo->setNode($node->getParent());

                    $this->feedbackCollection->add($updateNodeInfo);
                    $this->feedbackCollection->add($updateParentNodeInfo);

                    // Reload document for content node changes
                    // (as we can't RenderContentOutOfBand from here, we don't know dom addresses)
                    if (!$this->nodeService->isDocument($node)) {
                        $reloadDocument = new ReloadDocument();
                        $this->feedbackCollection->add($reloadDocument);
                    }
                } elseif (!$this->nodeService->nodeExistsInWorkspace($node, $node->getWorkSpace()->getBaseWorkspace())) {
                    // If the node doesn't exist in the target workspace, tell the UI to remove it
                    $removeNode = new RemoveNode();
                    $removeNode->setNode($node);
                    $this->feedbackCollection->add($removeNode);
                }

                $this->publishingService->discardNode($node);
            }

            $success = new Success();
            $success->setMessage(sprintf('Discarded %d node(s).', count($nodeContextPaths)));

            $this->updateWorkspaceInfo($nodeContextPaths[0]);
            $this->feedbackCollection->add($success);

            $this->persistenceManager->persistAll();
        } catch (\Exception $e) {
            $error = new Error();
            $error->setMessage($e->getMessage());

            $this->feedbackCollection->add($error);
        }

        $this->view->assign('value', $this->feedbackCollection);
    }
1336223
public function derefNodes($node, array $fields = [], ?string $return = null): array
    {
        if (!$node instanceof Node) {
            return [];
        }

        return $this->ncrCache->derefNodes($node, $fields, $return);
    }