Projet

Général

Profil

Révision b0dc3a2e

Ajouté par Julien Enselme il y a plus de 7 ans

Update to Drupal 7.52

Voir les différences:

drupal7/includes/database/mysql/database.inc
28 28

  
29 29
    $this->connectionOptions = $connection_options;
30 30

  
31
    $charset = 'utf8';
32
    // Check if the charset is overridden to utf8mb4 in settings.php.
33
    if ($this->utf8mb4IsActive()) {
34
      $charset = 'utf8mb4';
35
    }
36

  
31 37
    // The DSN should use either a socket or a host/port.
32 38
    if (isset($connection_options['unix_socket'])) {
33 39
      $dsn = 'mysql:unix_socket=' . $connection_options['unix_socket'];
......
39 45
    // Character set is added to dsn to ensure PDO uses the proper character
40 46
    // set when escaping. This has security implications. See
41 47
    // https://www.drupal.org/node/1201452 for further discussion.
42
    $dsn .= ';charset=utf8';
48
    $dsn .= ';charset=' . $charset;
43 49
    $dsn .= ';dbname=' . $connection_options['database'];
44 50
    // Allow PDO options to be overridden.
45 51
    $connection_options += array(
......
63 69
    // certain one has been set; otherwise, MySQL defaults to 'utf8_general_ci'
64 70
    // for UTF-8.
65 71
    if (!empty($connection_options['collation'])) {
66
      $this->exec('SET NAMES utf8 COLLATE ' . $connection_options['collation']);
72
      $this->exec('SET NAMES ' . $charset . ' COLLATE ' . $connection_options['collation']);
67 73
    }
68 74
    else {
69
      $this->exec('SET NAMES utf8');
75
      $this->exec('SET NAMES ' . $charset);
70 76
    }
71 77

  
72 78
    // Set MySQL init_commands if not already defined.  Default Drupal's MySQL
......
206 212
      }
207 213
    }
208 214
  }
215

  
216
  public function utf8mb4IsConfigurable() {
217
    return TRUE;
218
  }
219

  
220
  public function utf8mb4IsActive() {
221
    return isset($this->connectionOptions['charset']) && $this->connectionOptions['charset'] === 'utf8mb4';
222
  }
223

  
224
  public function utf8mb4IsSupported() {
225
    // Ensure that the MySQL driver supports utf8mb4 encoding.
226
    $version = $this->getAttribute(PDO::ATTR_CLIENT_VERSION);
227
    if (strpos($version, 'mysqlnd') !== FALSE) {
228
      // The mysqlnd driver supports utf8mb4 starting at version 5.0.9.
229
      $version = preg_replace('/^\D+([\d.]+).*/', '$1', $version);
230
      if (version_compare($version, '5.0.9', '<')) {
231
        return FALSE;
232
      }
233
    }
234
    else {
235
      // The libmysqlclient driver supports utf8mb4 starting at version 5.5.3.
236
      if (version_compare($version, '5.5.3', '<')) {
237
        return FALSE;
238
      }
239
    }
240

  
241
    // Ensure that the MySQL server supports large prefixes and utf8mb4.
242
    try {
243
      $this->query("CREATE TABLE {drupal_utf8mb4_test} (id VARCHAR(255), PRIMARY KEY(id(255))) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ROW_FORMAT=DYNAMIC ENGINE=INNODB");
244
    }
245
    catch (Exception $e) {
246
      return FALSE;
247
    }
248
    $this->query("DROP TABLE {drupal_utf8mb4_test}");
249
    return TRUE;
250
  }
209 251
}
210 252

  
211 253

  

Formats disponibles : Unified diff