protected function addIndicesToFields(DOMXPath $rootPath)
    {
        $fetchedNodes = [];
        $fields = $this->getFields();
        $multipleIndices = [];
        $idMap = array_flip(
            array_map(
                function (MigrationField $field) {
                    return $field->getId();
                },
                $fields
            )
        );

        /** @var MigrationField $field */
        foreach ($fields as $name => $field) {
            $usedId = $field->getId();
            $indexNodes = $rootPath->query(
                './value[@content-struct-name="db.mysql.Index" and @key="indices"]/' .
                'value[@type="object" and @struct-name="db.mysql.Index"]//' .
                'value[@type="object" and @struct-name="db.mysql.IndexColumn"]//' .
                'link[@type="object" and @struct-name="db.Column" and @key="referencedColumn" ' .
                'and text() = "' . $usedId . '"]/' .
                '../' .
                '../' .
                '..'
            );

            if ($indexNodes && $indexNodes->length) {
                $fks = $this->getForeignKeysForField($field, $rootPath);

                /** @var \DOMNode $indexNode */
                foreach ($indexNodes as $indexNode) {
                    if (in_array($nodeId = $indexNode->attributes->getNamedItem('id')->nodeValue, $fetchedNodes)) {
                        continue;
                    } // if

                    $fetchedNodes[] = $nodeId;

                    $indexColumns = $rootPath->query(
                        './/link[@type="object" and @struct-name="db.Column" and @key="referencedColumn"]',
                        $indexNode
                    );

                    $isSingleColumn = $indexColumns && $indexColumns->length <= 1;
                    $genericCall = !$isSingleColumn ? new Base() : null;

                    if ($rootPath->evaluate(
                        'boolean(./value[@type="int" and @key="unique" and number() = 1])',
                        $indexNode
                    )
                    ) {
                        if ($isSingleColumn) {
                            $field->addAdditionalOption('unique');
                        } // if
                        else {
                            $genericMethod = 'unique';
                        } // else
                    } // if

                    $hasIndex = $rootPath->evaluate(
                        'boolean(./value[@type="string" and @key="indexType" and text() = "INDEX"])',
                        $indexNode
                    );

                    if ($hasIndex && (!$fks || !$fks->length)) {
                        if ($isSingleColumn) {
                            $field->addAdditionalOption('index');
                        } // if
                        else {
                            $genericMethod = 'index';
                        } // else
                    } // if

                    if ($rootPath->evaluate(
                        'boolean(./value[@type="string" and @key="indexType" and text() = "PRIMARY"])',
                        $indexNode
                    )
                    ) {
                        if ($isSingleColumn) {
                            $field->addAdditionalOption('primary');
                        } // if
                        else {
                            $genericMethod = 'primary';
                        } // else
                    } // if

                    if ($genericCall && $genericMethod) {
                        $genericParams = [];
                        /** @var DOMNode $column */
                        foreach ($indexColumns as $column) {
                            $genericParams[] = $idMap[$column->nodeValue];
                        } // foreach

                        $this->addGenericCall(call_user_func_array(
                            [$genericCall, $genericMethod],
                            $genericParams ? [$genericParams] : []
                        ));
                    }
                }
            }
        }

        return array_unique($multipleIndices);
    }
protected function addIndicesToFields(DOMXPath $rootPath)
    {
        $fetchedNodes = [];
        $fields = $this->getFields();
        $multipleIndices = [];
        $idMap = array_flip(
            array_map(
                function (MigrationField $field) {
                    return $field->getId();
                },
                $fields
            )
        );

        /** @var MigrationField $field */
        foreach ($fields as $name => $field) {
            $usedId = $field->getId();
            $indexNodes = $rootPath->query(
                './value[@content-struct-name="db.mysql.Index" and @key="indices"]/' .
                'value[@type="object" and @struct-name="db.mysql.Index"]//' .
                'value[@type="object" and @struct-name="db.mysql.IndexColumn"]//' .
                'link[@type="object" and @struct-name="db.Column" and @key="referencedColumn" ' .
                'and text() = "' . $usedId . '"]/' .
                '../' .
                '../' .
                '..'
            );

            if ($indexNodes && $indexNodes->length) {
                $fks = $this->getForeignKeysForField($field, $rootPath);

                /** @var \DOMNode $indexNode */
                foreach ($indexNodes as $indexNode) {
                    if (in_array($nodeId = $indexNode->attributes->getNamedItem('id')->nodeValue, $fetchedNodes)) {
                        continue;
                    } // if

                    $fetchedNodes[] = $nodeId;

                    $indexColumns = $rootPath->query(
                        './/link[@type="object" and @struct-name="db.Column" and @key="referencedColumn"]',
                        $indexNode
                    );

                    $isSingleColumn = $indexColumns && $indexColumns->length <= 1;
                    $genericCall = !$isSingleColumn ? new Base() : null;

                    if ($rootPath->evaluate(
                        'boolean(./value[@type="int" and @key="unique" and number() = 1])',
                        $indexNode
                    )
                    ) {
                        if ($isSingleColumn) {
                            $field->addAdditionalOption('unique');
                        } // if
                        else {
                            $genericMethod = 'unique';
                        } // else
                    } // if

                    $hasIndex = $rootPath->evaluate(
                        'boolean(./value[@type="string" and @key="indexType" and text() = "INDEX"])',
                        $indexNode
                    );

                    if ($hasIndex && (!$fks || !$fks->length)) {
                        if ($isSingleColumn) {
                            $field->addAdditionalOption('index');
                        } // if
                        else {
                            $genericMethod = 'index';
                        } // else
                    } // if

                    if ($rootPath->evaluate(
                        'boolean(./value[@type="string" and @key="indexType" and text() = "PRIMARY"])',
                        $indexNode
                    )
                    ) {
                        if ($isSingleColumn) {
                            $field->addAdditionalOption('primary');
                        } // if
                        else {
                            $genericMethod = 'primary';
                        } // else
                    } // if

                    if ($genericCall && $genericMethod) {
                        $genericParams = [];
                        /** @var DOMNode $column */
                        foreach ($indexColumns as $column) {
                            $genericParams[] = $idMap[$column->nodeValue];
                        } // foreach

                        $this->addGenericCall(call_user_func_array(
                            [$genericCall, $genericMethod],
                            $genericParams ? [$genericParams] : []
                        ));
                    }
                }
            }
        }

        return array_unique($multipleIndices);
    }
protected function addIndicesToFields ( DOMXPath $ rootPath ) { $ fetchedNodes = [ ] ; $ fields = $ this -> getFields ( ) ; $ multipleIndices = [ ] ; $ idMap = array_flip ( array_map ( function ( MigrationField $ field ) { return $ field -> getId ( ) ; } , $ fields ) ) ; /** @var MigrationField $field */ foreach ( $ fields as $ name => $ field ) { $ usedId = $ field -> getId ( ) ; $ indexNodes = $ rootPath -> query ( './value[@content-struct-name="db.mysql.Index" and @key="indices"]/' . 'value[@type="object" and @struct-name="db.mysql.Index"]//' . 'value[@type="object" and @struct-name="db.mysql.IndexColumn"]//' . 'link[@type="object" and @struct-name="db.Column" and @key="referencedColumn" ' . 'and text() = "' . $ usedId . '"]/' . '../' . '../' . '..' ) ; if ( $ indexNodes && $ indexNodes -> length ) { $ fks = $ this -> getForeignKeysForField ( $ field , $ rootPath ) ; /** @var \DOMNode $indexNode */ foreach ( $ indexNodes as $ indexNode ) { if ( in_array ( $ nodeId = $ indexNode -> attributes -> getNamedItem ( 'id' ) -> nodeValue , $ fetchedNodes ) ) { continue ; } // if $ fetchedNodes [ ] = $ nodeId ; $ indexColumns = $ rootPath -> query ( './/link[@type="object" and @struct-name="db.Column" and @key="referencedColumn"]' , $ indexNode ) ; $ isSingleColumn = $ indexColumns && $ indexColumns -> length <= 1 ; $ genericCall = ! $ isSingleColumn ? new Base ( ) : null ; if ( $ rootPath -> evaluate ( 'boolean(./value[@type="int" and @key="unique" and number() = 1])' , $ indexNode ) ) { if ( $ isSingleColumn ) { $ field -> addAdditionalOption ( 'unique' ) ; } // if else { $ genericMethod = 'unique' ; } // else } // if $ hasIndex = $ rootPath -> evaluate ( 'boolean(./value[@type="string" and @key="indexType" and text() = "INDEX"])' , $ indexNode ) ; if ( $ hasIndex && ( ! $ fks || ! $ fks -> length ) ) { if ( $ isSingleColumn ) { $ field -> addAdditionalOption ( 'index' ) ; } // if else { $ genericMethod = 'index' ; } // else } // if if ( $ rootPath -> evaluate ( 'boolean(./value[@type="string" and @key="indexType" and text() = "PRIMARY"])' , $ indexNode ) ) { if ( $ isSingleColumn ) { $ field -> addAdditionalOption ( 'primary' ) ; } // if else { $ genericMethod = 'primary' ; } // else } // if if ( $ genericCall && $ genericMethod ) { $ genericParams = [ ] ; /** @var DOMNode $column */ foreach ( $ indexColumns as $ column ) { $ genericParams [ ] = $ idMap [ $ column -> nodeValue ] ; } // foreach $ this -> addGenericCall ( call_user_func_array ( [ $ genericCall , $ genericMethod ] , $ genericParams ? [ $ genericParams ] : [ ] ) ) ; } } } } return array_unique ( $ multipleIndices ) ; }
Adds the simple indices to the fields directly and returns the indices for multiple values.
@param DOMXPath $rootPath
@return array
@todo   Primary missing; Problems with m:ns.
Adds the simple indices to the fields directly and returns the indices for multiple values .