diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2017-05-08 12:18:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-08 12:18:40 +0200 |
commit | 4d101ca2bec2f8b799535b35188755dbb01e9641 (patch) | |
tree | 93463513a8a0b9ae976cc3561627052cded91819 /lib | |
parent | 7cc750fe376a0b676818d06ec00837f655f4a51e (diff) | |
parent | 3afad7fe407ad6c5ef772d0e89f3f3cc06111a36 (diff) | |
download | nextcloud-server-4d101ca2bec2f8b799535b35188755dbb01e9641.tar.gz nextcloud-server-4d101ca2bec2f8b799535b35188755dbb01e9641.zip |
Merge pull request #4514 from nextcloud/automatic-mysql-4byte-detection
Automatic mysql 4byte detection
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/DB/MySqlTools.php | 49 | ||||
-rw-r--r-- | lib/private/Setup/MySQL.php | 8 |
4 files changed, 59 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 2151aeff33b..703d624397c 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -488,6 +488,7 @@ return array( 'OC\\DB\\MigrationException' => $baseDir . '/lib/private/DB/MigrationException.php', 'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php', 'OC\\DB\\MySQLMigrator' => $baseDir . '/lib/private/DB/MySQLMigrator.php', + 'OC\\DB\\MySqlTools' => $baseDir . '/lib/private/DB/MySqlTools.php', 'OC\\DB\\NoCheckMigrator' => $baseDir . '/lib/private/DB/NoCheckMigrator.php', 'OC\\DB\\OCSqlitePlatform' => $baseDir . '/lib/private/DB/OCSqlitePlatform.php', 'OC\\DB\\OracleConnection' => $baseDir . '/lib/private/DB/OracleConnection.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index ec5190bc71d..ff7118e5bb1 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -518,6 +518,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\DB\\MigrationException' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationException.php', 'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php', 'OC\\DB\\MySQLMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/MySQLMigrator.php', + 'OC\\DB\\MySqlTools' => __DIR__ . '/../../..' . '/lib/private/DB/MySqlTools.php', 'OC\\DB\\NoCheckMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/NoCheckMigrator.php', 'OC\\DB\\OCSqlitePlatform' => __DIR__ . '/../../..' . '/lib/private/DB/OCSqlitePlatform.php', 'OC\\DB\\OracleConnection' => __DIR__ . '/../../..' . '/lib/private/DB/OracleConnection.php', diff --git a/lib/private/DB/MySqlTools.php b/lib/private/DB/MySqlTools.php new file mode 100644 index 00000000000..32f1de887c3 --- /dev/null +++ b/lib/private/DB/MySqlTools.php @@ -0,0 +1,49 @@ +<?php +/** + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\DB; + +use OCP\IDBConnection; + +/** +* Various MySQL specific helper functions. +*/ +class MySqlTools { + + /** + * @param Connection $connection + * @return bool + */ + public function supports4ByteCharset(IDBConnection $connection) { + foreach (['innodb_file_format' => 'Barracuda', 'innodb_large_prefix' => 'ON', 'innodb_file_per_table' => 'ON'] as $var => $val) { + $result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'"); + $rows = $result->fetch(); + $result->closeCursor(); + if ($rows === false) { + return false; + } + if (strcasecmp($rows['Value'], $val) !== 0) { + return false; + } + } + return true; + } +} diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 9998ca401d9..8290d675500 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -27,6 +27,7 @@ */ namespace OC\Setup; +use OC\DB\MySqlTools; use OCP\IDBConnection; class MySQL extends AbstractDatabase { @@ -36,6 +37,13 @@ class MySQL extends AbstractDatabase { //check if the database user has admin right $connection = $this->connect(['dbname' => null]); + // detect mb4 + $tools = new MySqlTools(); + if ($tools->supports4ByteCharset($connection)) { + $this->config->setValue('mysql.utf8mb4', true); + $connection = $this->connect(); + } + $this->createSpecificUser($username, $connection); //create the database |