Skip to content

Commit

Permalink
During setup of a mysql database we try to detect if charset 'utf8mb4…
Browse files Browse the repository at this point in the history
…' can be used
  • Loading branch information
DeepDiver1975 authored and rullzer committed Apr 28, 2017
1 parent 3fd75e2 commit aa22f93
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/private/Setup/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
namespace OC\Setup;

use OC\DB\ConnectionFactory;
use OCP\IDBConnection;

class MySQL extends AbstractDatabase {
Expand All @@ -36,6 +37,12 @@ public function setupDatabase($username) {
//check if the database user has admin right
$connection = $this->connect(['dbname' => null]);

// detect mb4
if (is_null($this->config->getSValue('mysql.utf8mb4', null)) && $this->supports4ByteCharset($connection)) {
$this->config->setValue('mysql.utf8mb4', true);
$connection = $this->connect();
}

$this->createSpecificUser($username, $connection);

//create the database
Expand Down Expand Up @@ -162,4 +169,23 @@ private function createSpecificUser($username, $connection) {
'dbpassword' => $this->dbPassword,
]);
}

/**
* @param IDBConnection $connection
* @return bool
*/
private 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;
}
}

0 comments on commit aa22f93

Please sign in to comment.