private function compileCommands(): void
    {
        $return = [
            'CREATE' => [],
            'ALTER_TABLE' => [],
            'ALTER_CHANGE' => [],
            'ALTER_ADD' => [],
            'DROP' => [],
            'ALTER_DROP' => [],
        ];

        $config = $this->connection->getConfiguration();

        // Overwrite the schema filter (see #78)
        $previousFilter = $config->getFilterSchemaAssetsExpression();
        $config->setFilterSchemaAssetsExpression('/^tl_/');

        // Create the from and to schema
        $fromSchema = $this->connection->getSchemaManager()->createSchema();
        $toSchema = $this->schemaProvider->createSchema();

        // Reset the schema filter
        $config->setFilterSchemaAssetsExpression($previousFilter);

        $diff = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());

        foreach ($diff as $sql) {
            switch (true) {
                case 0 === strncmp($sql, 'CREATE TABLE ', 13):
                    $return['CREATE'][md5($sql)] = $sql;
                    break;

                case 0 === strncmp($sql, 'DROP TABLE ', 11):
                    $return['DROP'][md5($sql)] = $sql;
                    break;

                case 0 === strncmp($sql, 'CREATE INDEX ', 13):
                case 0 === strncmp($sql, 'CREATE UNIQUE INDEX ', 20):
                case 0 === strncmp($sql, 'CREATE FULLTEXT INDEX ', 22):
                    $return['ALTER_ADD'][md5($sql)] = $sql;
                    break;

                case 0 === strncmp($sql, 'DROP INDEX', 10):
                    $return['ALTER_CHANGE'][md5($sql)] = $sql;
                    break;

                case preg_match('/^(ALTER TABLE [^ ]+) /', $sql, $matches):
                    $prefix = $matches[1];
                    $sql = substr($sql, \strlen($prefix));
                    $parts = array_reverse(array_map('trim', explode(',', $sql)));

                    for ($i = 0, $count = \count($parts); $i < $count; ++$i) {
                        $part = $parts[$i];
                        $command = $prefix.' '.$part;

                        switch (true) {
                            case 0 === strncmp($part, 'DROP ', 5):
                                $return['ALTER_DROP'][md5($command)] = $command;
                                break;

                            case 0 === strncmp($part, 'ADD ', 4):
                                $return['ALTER_ADD'][md5($command)] = $command;
                                break;

                            case 0 === strncmp($part, 'CHANGE ', 7):
                            case 0 === strncmp($part, 'RENAME ', 7):
                                $return['ALTER_CHANGE'][md5($command)] = $command;
                                break;

                            default:
                                $parts[$i + 1] = $parts[$i + 1].','.$part;
                                break;
                        }
                    }
                    break;

                default:
                    throw new \RuntimeException(sprintf('Unsupported SQL schema diff: %s', $sql));
            }
        }

        $this->checkEngineAndCollation($return, $fromSchema, $toSchema);

        $return = array_filter($return);

        // HOOK: allow third-party developers to modify the array (see #3281)
        if (isset($GLOBALS['TL_HOOKS']['sqlCompileCommands']) && \is_array($GLOBALS['TL_HOOKS']['sqlCompileCommands'])) {
            foreach ($GLOBALS['TL_HOOKS']['sqlCompileCommands'] as $callback) {
                $return = System::importStatic($callback[0])->{$callback[1]}($return);
            }
        }

        $this->commands = $return;
    }
private function compileCommands(): void
    {
        $return = [
            'CREATE' => [],
            'ALTER_TABLE' => [],
            'ALTER_CHANGE' => [],
            'ALTER_ADD' => [],
            'DROP' => [],
            'ALTER_DROP' => [],
        ];

        $config = $this->connection->getConfiguration();

        
        $previousFilter = $config->getFilterSchemaAssetsExpression();
        $config->setFilterSchemaAssetsExpression('/^tl_/');

        
        $fromSchema = $this->connection->getSchemaManager()->createSchema();
        $toSchema = $this->schemaProvider->createSchema();

        
        $config->setFilterSchemaAssetsExpression($previousFilter);

        $diff = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());

        foreach ($diff as $sql) {
            switch (true) {
                case 0 === strncmp($sql, 'CREATE TABLE ', 13):
                    $return['CREATE'][md5($sql)] = $sql;
                    break;

                case 0 === strncmp($sql, 'DROP TABLE ', 11):
                    $return['DROP'][md5($sql)] = $sql;
                    break;

                case 0 === strncmp($sql, 'CREATE INDEX ', 13):
                case 0 === strncmp($sql, 'CREATE UNIQUE INDEX ', 20):
                case 0 === strncmp($sql, 'CREATE FULLTEXT INDEX ', 22):
                    $return['ALTER_ADD'][md5($sql)] = $sql;
                    break;

                case 0 === strncmp($sql, 'DROP INDEX', 10):
                    $return['ALTER_CHANGE'][md5($sql)] = $sql;
                    break;

                case preg_match('/^(ALTER TABLE [^ ]+) /', $sql, $matches):
                    $prefix = $matches[1];
                    $sql = substr($sql, \strlen($prefix));
                    $parts = array_reverse(array_map('trim', explode(',', $sql)));

                    for ($i = 0, $count = \count($parts); $i < $count; ++$i) {
                        $part = $parts[$i];
                        $command = $prefix.' '.$part;

                        switch (true) {
                            case 0 === strncmp($part, 'DROP ', 5):
                                $return['ALTER_DROP'][md5($command)] = $command;
                                break;

                            case 0 === strncmp($part, 'ADD ', 4):
                                $return['ALTER_ADD'][md5($command)] = $command;
                                break;

                            case 0 === strncmp($part, 'CHANGE ', 7):
                            case 0 === strncmp($part, 'RENAME ', 7):
                                $return['ALTER_CHANGE'][md5($command)] = $command;
                                break;

                            default:
                                $parts[$i + 1] = $parts[$i + 1].','.$part;
                                break;
                        }
                    }
                    break;

                default:
                    throw new \RuntimeException(sprintf('Unsupported SQL schema diff: %s', $sql));
            }
        }

        $this->checkEngineAndCollation($return, $fromSchema, $toSchema);

        $return = array_filter($return);

        
        if (isset($GLOBALS['TL_HOOKS']['sqlCompileCommands']) && \is_array($GLOBALS['TL_HOOKS']['sqlCompileCommands'])) {
            foreach ($GLOBALS['TL_HOOKS']['sqlCompileCommands'] as $callback) {
                $return = System::importStatic($callback[0])->{$callback[1]}($return);
            }
        }

        $this->commands = $return;
    }
private function compileCommands ( ) : void { $ return = [ 'CREATE' => [ ] , 'ALTER_TABLE' => [ ] , 'ALTER_CHANGE' => [ ] , 'ALTER_ADD' => [ ] , 'DROP' => [ ] , 'ALTER_DROP' => [ ] , ] ; $ config = $ this -> connection -> getConfiguration ( ) ; // Overwrite the schema filter (see #78) $ previousFilter = $ config -> getFilterSchemaAssetsExpression ( ) ; $ config -> setFilterSchemaAssetsExpression ( '/^tl_/' ) ; // Create the from and to schema $ fromSchema = $ this -> connection -> getSchemaManager ( ) -> createSchema ( ) ; $ toSchema = $ this -> schemaProvider -> createSchema ( ) ; // Reset the schema filter $ config -> setFilterSchemaAssetsExpression ( $ previousFilter ) ; $ diff = $ fromSchema -> getMigrateToSql ( $ toSchema , $ this -> connection -> getDatabasePlatform ( ) ) ; foreach ( $ diff as $ sql ) { switch ( true ) { case 0 === strncmp ( $ sql , 'CREATE TABLE ' , 13 ) : $ return [ 'CREATE' ] [ md5 ( $ sql ) ] = $ sql ; break ; case 0 === strncmp ( $ sql , 'DROP TABLE ' , 11 ) : $ return [ 'DROP' ] [ md5 ( $ sql ) ] = $ sql ; break ; case 0 === strncmp ( $ sql , 'CREATE INDEX ' , 13 ) : case 0 === strncmp ( $ sql , 'CREATE UNIQUE INDEX ' , 20 ) : case 0 === strncmp ( $ sql , 'CREATE FULLTEXT INDEX ' , 22 ) : $ return [ 'ALTER_ADD' ] [ md5 ( $ sql ) ] = $ sql ; break ; case 0 === strncmp ( $ sql , 'DROP INDEX' , 10 ) : $ return [ 'ALTER_CHANGE' ] [ md5 ( $ sql ) ] = $ sql ; break ; case preg_match ( '/^(ALTER TABLE [^ ]+) /' , $ sql , $ matches ) : $ prefix = $ matches [ 1 ] ; $ sql = substr ( $ sql , \ strlen ( $ prefix ) ) ; $ parts = array_reverse ( array_map ( 'trim' , explode ( ',' , $ sql ) ) ) ; for ( $ i = 0 , $ count = \ count ( $ parts ) ; $ i < $ count ; ++ $ i ) { $ part = $ parts [ $ i ] ; $ command = $ prefix . ' ' . $ part ; switch ( true ) { case 0 === strncmp ( $ part , 'DROP ' , 5 ) : $ return [ 'ALTER_DROP' ] [ md5 ( $ command ) ] = $ command ; break ; case 0 === strncmp ( $ part , 'ADD ' , 4 ) : $ return [ 'ALTER_ADD' ] [ md5 ( $ command ) ] = $ command ; break ; case 0 === strncmp ( $ part , 'CHANGE ' , 7 ) : case 0 === strncmp ( $ part , 'RENAME ' , 7 ) : $ return [ 'ALTER_CHANGE' ] [ md5 ( $ command ) ] = $ command ; break ; default : $ parts [ $ i + 1 ] = $ parts [ $ i + 1 ] . ',' . $ part ; break ; } } break ; default : throw new \ RuntimeException ( sprintf ( 'Unsupported SQL schema diff: %s' , $ sql ) ) ; } } $ this -> checkEngineAndCollation ( $ return , $ fromSchema , $ toSchema ) ; $ return = array_filter ( $ return ) ; // HOOK: allow third-party developers to modify the array (see #3281) if ( isset ( $ GLOBALS [ 'TL_HOOKS' ] [ 'sqlCompileCommands' ] ) && \ is_array ( $ GLOBALS [ 'TL_HOOKS' ] [ 'sqlCompileCommands' ] ) ) { foreach ( $ GLOBALS [ 'TL_HOOKS' ] [ 'sqlCompileCommands' ] as $ callback ) { $ return = System :: importStatic ( $ callback [ 0 ] ) -> { $ callback [ 1 ] } ( $ return ) ; } } $ this -> commands = $ return ; }
Compiles the command required to update the database.
Compiles the command required to update the database .