Neos\Flow\Command\DatabaseCommandController::convertToCharacterSetAndCollation PHP Метод

convertToCharacterSetAndCollation() защищенный Метод

Convert the tables in the current database to use given character set and collation.
protected convertToCharacterSetAndCollation ( string $characterSet = 'utf8', string $collation = 'utf8_unicode_ci', string $outputPathAndFilename = null, boolean $verbose = false )
$characterSet string Character set to convert to
$collation string Collation to set, must be compatible with the character set
$outputPathAndFilename string
$verbose boolean
    protected function convertToCharacterSetAndCollation($characterSet = 'utf8', $collation = 'utf8_unicode_ci', $outputPathAndFilename = null, $verbose = false)
    {
        $statements = ['SET foreign_key_checks = 0'];
        $statements[] = 'ALTER DATABASE ' . $this->connection->quoteIdentifier($this->persistenceSettings['backendOptions']['dbname']) . ' CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
        $tableNames = $this->connection->getSchemaManager()->listTableNames();
        foreach ($tableNames as $tableName) {
            $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
            $statements[] = 'ALTER TABLE ' . $this->connection->quoteIdentifier($tableName) . ' CONVERT TO CHARACTER SET ' . $characterSet . ' COLLATE ' . $collation;
        }
        $statements[] = 'SET foreign_key_checks = 1';
        if ($outputPathAndFilename === null) {
            try {
                $this->connection->beginTransaction();
                foreach ($statements as $statement) {
                    if ($verbose) {
                        $this->outputLine($statement);
                    }
                    $this->connection->exec($statement);
                }
                $this->connection->commit();
            } catch (\Exception $exception) {
                $this->connection->rollBack();
                $this->outputLine($exception->getMessage());
                $this->outputLine('[ERROR] The transaction was rolled back.');
            }
        } else {
            file_put_contents($outputPathAndFilename, implode(';' . PHP_EOL, $statements) . ';');
        }
    }