Commit 4ed1267b authored by Thomas Bosviel's avatar Thomas Bosviel Committed by helmo

Issue #2764111 by helmo, Thomas Bosviel: Support for utf8mb4

parent c1ec7762
......@@ -21,13 +21,8 @@ class Provision_Config_Drupal_Settings extends Provision_Config {
$this->data['file_directory_temp_var'] = 'file_temporary_path';
$this->data['file_directory_private_var'] = 'file_private_path';
$this->data['drupal_hash_salt_var'] = 'empty';
// Multi-byte UTF-8 support in Drupal 7
// https://www.drupal.org/node/2754539
if (version_compare(drush_drupal_version(), '7.50', '>=') && drush_get_option('utf8mb4IsSupported', FALSE)) {
$this->data['utf8mb4IsSupported'] = TRUE;
}
$this->data['utf8mb4_is_configurable'] = version_compare(drush_drupal_version(), '7.50', '>=');
$this->data['utf8mb4_is_supported'] = $this->db_server->utf8mb4_is_supported;
}
else {
$this->data['file_directory_path_var'] = 'file_directory_path';
......
......@@ -48,11 +48,9 @@ if (isset($_SERVER['db_name'])) {
* should probably be fixed in Drush.
*/
'port' => (string) $_SERVER['db_port'],
<?php if ($utf8mb4IsSupported): ?>
<?php if ($utf8mb4_is_configurable && $utf8mb4_is_supported): ?>
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
<?php else: ?>
// ... not adding charset utf8mb4, add "$options['utf8mb4IsSupported'] = TRUE;" to /etc/drush/drushrc.php to enable.
<?php endif; ?>
);
$db_url['default'] = $_SERVER['db_type'] . '://' . $_SERVER['db_user'] . ':' . $_SERVER['db_passwd'] . '@' . $_SERVER['db_host'] . ':' . $_SERVER['db_port'] . '/' . $_SERVER['db_name'];
......
......@@ -21,11 +21,17 @@ class Provision_Service_db extends Provision_Service {
function init_server() {
parent::init_server();
$this->server->setProperty('master_db');
$this->server->setProperty('utf8mb4_is_supported', FALSE);
$this->creds = array_map('urldecode', parse_url($this->server->master_db));
return TRUE;
}
function save_server() {
// Check database 4 byte UTF-8 support and save it for later.
$this->server->utf8mb4_is_supported = $this->utf8mb4_is_supported();
}
/**
* Verifies database connection and commands
*/
......@@ -43,6 +49,12 @@ class Provision_Service_db extends Provision_Service {
else {
drush_set_error('PROVISION_GRANT_DB_USER_FAILED');
}
if ($this->server->utf8mb4_is_supported) {
drush_log(dt('Provision can activate multi-byte UTF-8 support on Drupal 7 sites.'), 'success');
}
else {
drush_log(dt('Multi-byte UTF-8 for Drupal 7 is not supported on your system. See the <a href="@url">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@url' => 'https://www.drupal.org/node/2754539')), 'warning');
}
} else {
drush_set_error('PROVISION_CONNECT_DB_FAILED');
}
......@@ -240,4 +252,15 @@ class Provision_Service_db extends Provision_Service {
function grant_host(Provision_Context_server $server) {
return $server->remote_host;
}
/**
* Checks whether utf8mb4 support is available on the current database system.
*
* @return bool
*/
function utf8mb4_is_supported() {
// By default we assume that the database backend may not support 4 byte
// UTF-8.
return FALSE;
}
}
......@@ -303,4 +303,37 @@ port=%s
}
return ($return_value == 0);
}
function utf8mb4_is_supported() {
// Ensure that provision can connect to the database.
if (!$this->connect()) {
return FALSE;
}
// Ensure that the MySQL driver supports utf8mb4 encoding.
$version = $this->conn->getAttribute(PDO::ATTR_CLIENT_VERSION);
if (strpos($version, 'mysqlnd') !== FALSE) {
// The mysqlnd driver supports utf8mb4 starting at version 5.0.9.
$version = preg_replace('/^\D+([\d.]+).*/', '$1', $version);
if (version_compare($version, '5.0.9', '<')) {
return FALSE;
}
}
else {
// The libmysqlclient driver supports utf8mb4 starting at version 5.5.3.
if (version_compare($version, '5.5.3', '<')) {
return FALSE;
}
}
// Ensure that the MySQL server supports large prefixes and utf8mb4.
$dbname = uniqid(drush_get_option('aegir_db_prefix', 'site_'));
$this->create_database($dbname);
$success = $this->query("CREATE TABLE `%s`.`drupal_utf8mb4_test` (id VARCHAR(255), PRIMARY KEY(id(255))) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ROW_FORMAT=DYNAMIC", $dbname);
if (!$this->drop_database($dbname)) {
drush_log(dt("Failed to drop database @dbname", array('@dbname' => $dbname)), 'warning');
}
return ($success !== FALSE);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment