installation-bundle/src/Database/Installer.php
private function checkEngineAndCollation(array &$sql, Schema $fromSchema, Schema $toSchema): void
    {
        $tables = $toSchema->getTables();
        $dynamic = $this->hasDynamicRowFormat();

        foreach ($tables as $table) {
            $tableName = $table->getName();
            $alterTables = [];
            $deleteIndexes = false;

            if (0 !== strncmp($tableName, 'tl_', 3)) {
                continue;
            }

            $this->setLegacyOptions($table);

            $tableOptions = $this->connection
                ->query("SHOW TABLE STATUS LIKE '".$tableName."'")
                ->fetch(\PDO::FETCH_OBJ)
            ;

            // The table does not yet exist
            if (false === $tableOptions) {
                continue;
            }

            $engine = $table->getOption('engine');
            $innodb = 'innodb' === strtolower($engine);

            if (strtolower($tableOptions->Engine) !== strtolower($engine)) {
                if ($innodb && $dynamic) {
                    $command = 'ALTER TABLE '.$tableName.' ENGINE = '.$engine.' ROW_FORMAT = DYNAMIC';
                } else {
                    $command = 'ALTER TABLE '.$tableName.' ENGINE = '.$engine;
                }

                $deleteIndexes = true;
                $alterTables[md5($command)] = $command;
            } elseif ($innodb && $dynamic) {
                $rowFormat = $table->getOption('row_format');

                if ($rowFormat && strtolower($tableOptions->Row_format) !== strtolower($rowFormat)) {
                    $command = 'ALTER TABLE '.$tableName.' ENGINE = '.$engine.' ROW_FORMAT = DYNAMIC';
                    $alterTables[md5($command)] = $command;
                }
            }

            $collate = $table->getOption('collate');

            if ($tableOptions->Collation !== $collate) {
                $charset = $table->getOption('charset');
                $command = 'ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET '.$charset.' COLLATE '.$collate;
                $deleteIndexes = true;
                $alterTables[md5($command)] = $command;
            }

            // Delete the indexes if the engine changes in case the existing
            // indexes are too long. The migration then needs to be run muliple
            // times to re-create the indexes with the correct length.
            if ($deleteIndexes) {
                if (!$fromSchema->hasTable($tableName)) {
                    continue;
                }

                $platform = $this->connection->getDatabasePlatform();

                foreach ($fromSchema->getTable($tableName)->getIndexes() as $index) {
                    $indexName = $index->getName();

                    if ('primary' === strtolower($indexName)) {
                        continue;
                    }

                    $indexCommand = $platform->getDropIndexSQL($indexName, $tableName);
                    $strKey = md5($indexCommand);

                    if (isset($sql['ALTER_CHANGE'][$strKey])) {
                        unset($sql['ALTER_CHANGE'][$strKey]);
                    }

                    $sql['ALTER_TABLE'][$strKey] = $indexCommand;
                }
            }

            foreach ($alterTables as $k => $alterTable) {
                $sql['ALTER_TABLE'][$k] = $alterTable;
            }
        }
    }
private function checkEngineAndCollation(array &$sql, Schema $fromSchema, Schema $toSchema): void
    {
        $tables = $toSchema->getTables();
        $dynamic = $this->hasDynamicRowFormat();

        foreach ($tables as $table) {
            $tableName = $table->getName();
            $alterTables = [];
            $deleteIndexes = false;

            if (0 !== strncmp($tableName, 'tl_', 3)) {
                continue;
            }

            $this->setLegacyOptions($table);

            $tableOptions = $this->connection
                ->query("SHOW TABLE STATUS LIKE '".$tableName."'")
                ->fetch(\PDO::FETCH_OBJ)
            ;

            // The table does not yet exist
            if (false === $tableOptions) {
                continue;
            }

            $engine = $table->getOption('engine');
            $innodb = 'innodb' === strtolower($engine);

            if (strtolower($tableOptions->Engine) !== strtolower($engine)) {
                if ($innodb && $dynamic) {
                    $command = 'ALTER TABLE '.$tableName.' ENGINE = '.$engine.' ROW_FORMAT = DYNAMIC';
                } else {
                    $command = 'ALTER TABLE '.$tableName.' ENGINE = '.$engine;
                }

                $deleteIndexes = true;
                $alterTables[md5($command)] = $command;
            } elseif ($innodb && $dynamic) {
                $rowFormat = $table->getOption('row_format');

                if ($rowFormat && strtolower($tableOptions->Row_format) !== strtolower($rowFormat)) {
                    $command = 'ALTER TABLE '.$tableName.' ENGINE = '.$engine.' ROW_FORMAT = DYNAMIC';
                    $alterTables[md5($command)] = $command;
                }
            }

            $collate = $table->getOption('collate');

            if ($tableOptions->Collation !== $collate) {
                $charset = $table->getOption('charset');
                $command = 'ALTER TABLE '.$tableName.' CONVERT TO CHARACTER SET '.$charset.' COLLATE '.$collate;
                $deleteIndexes = true;
                $alterTables[md5($command)] = $command;
            }

            // Delete the indexes if the engine changes in case the existing
            // indexes are too long. The migration then needs to be run muliple
            // times to re-create the indexes with the correct length.
            if ($deleteIndexes) {
                if (!$fromSchema->hasTable($tableName)) {
                    continue;
                }

                $platform = $this->connection->getDatabasePlatform();

                foreach ($fromSchema->getTable($tableName)->getIndexes() as $index) {
                    $indexName = $index->getName();

                    if ('primary' === strtolower($indexName)) {
                        continue;
                    }

                    $indexCommand = $platform->getDropIndexSQL($indexName, $tableName);
                    $strKey = md5($indexCommand);

                    if (isset($sql['ALTER_CHANGE'][$strKey])) {
                        unset($sql['ALTER_CHANGE'][$strKey]);
                    }

                    $sql['ALTER_TABLE'][$strKey] = $indexCommand;
                }
            }

            foreach ($alterTables as $k => $alterTable) {
                $sql['ALTER_TABLE'][$k] = $alterTable;
            }
        }
    }
private function checkEngineAndCollation ( array & $ sql , Schema $ fromSchema , Schema $ toSchema ) : void { $ tables = $ toSchema -> getTables ( ) ; $ dynamic = $ this -> hasDynamicRowFormat ( ) ; foreach ( $ tables as $ table ) { $ tableName = $ table -> getName ( ) ; $ alterTables = [ ] ; $ deleteIndexes = false ; if ( 0 !== strncmp ( $ tableName , 'tl_' , 3 ) ) { continue ; } $ this -> setLegacyOptions ( $ table ) ; $ tableOptions = $ this -> connection -> query ( "SHOW TABLE STATUS LIKE '" . $ tableName . "'" ) -> fetch ( \ PDO :: FETCH_OBJ ) ; // The table does not yet exist if ( false === $ tableOptions ) { continue ; } $ engine = $ table -> getOption ( 'engine' ) ; $ innodb = 'innodb' === strtolower ( $ engine ) ; if ( strtolower ( $ tableOptions -> Engine ) !== strtolower ( $ engine ) ) { if ( $ innodb && $ dynamic ) { $ command = 'ALTER TABLE ' . $ tableName . ' ENGINE = ' . $ engine . ' ROW_FORMAT = DYNAMIC' ; } else { $ command = 'ALTER TABLE ' . $ tableName . ' ENGINE = ' . $ engine ; } $ deleteIndexes = true ; $ alterTables [ md5 ( $ command ) ] = $ command ; } elseif ( $ innodb && $ dynamic ) { $ rowFormat = $ table -> getOption ( 'row_format' ) ; if ( $ rowFormat && strtolower ( $ tableOptions -> Row_format ) !== strtolower ( $ rowFormat ) ) { $ command = 'ALTER TABLE ' . $ tableName . ' ENGINE = ' . $ engine . ' ROW_FORMAT = DYNAMIC' ; $ alterTables [ md5 ( $ command ) ] = $ command ; } } $ collate = $ table -> getOption ( 'collate' ) ; if ( $ tableOptions -> Collation !== $ collate ) { $ charset = $ table -> getOption ( 'charset' ) ; $ command = 'ALTER TABLE ' . $ tableName . ' CONVERT TO CHARACTER SET ' . $ charset . ' COLLATE ' . $ collate ; $ deleteIndexes = true ; $ alterTables [ md5 ( $ command ) ] = $ command ; } // Delete the indexes if the engine changes in case the existing // indexes are too long. The migration then needs to be run muliple // times to re-create the indexes with the correct length. if ( $ deleteIndexes ) { if ( ! $ fromSchema -> hasTable ( $ tableName ) ) { continue ; } $ platform = $ this -> connection -> getDatabasePlatform ( ) ; foreach ( $ fromSchema -> getTable ( $ tableName ) -> getIndexes ( ) as $ index ) { $ indexName = $ index -> getName ( ) ; if ( 'primary' === strtolower ( $ indexName ) ) { continue ; } $ indexCommand = $ platform -> getDropIndexSQL ( $ indexName , $ tableName ) ; $ strKey = md5 ( $ indexCommand ) ; if ( isset ( $ sql [ 'ALTER_CHANGE' ] [ $ strKey ] ) ) { unset ( $ sql [ 'ALTER_CHANGE' ] [ $ strKey ] ) ; } $ sql [ 'ALTER_TABLE' ] [ $ strKey ] = $ indexCommand ; } } foreach ( $ alterTables as $ k => $ alterTable ) { $ sql [ 'ALTER_TABLE' ] [ $ k ] = $ alterTable ; } } }
Checks engine and collation and adds the ALTER TABLE queries.
Checks engine and collation and adds the ALTER TABLE queries .