1 charset_converter.inc public DatabaseCharsetConverter::convertAllDatabases(array $databases)

Convert the MySQL Backdrop databases character set and collation.

Parameters

array $databases: The Backdrop database info array.

Throws

Exception

PDOException

File

core/includes/database/charset_converter.inc, line 83

Class

DatabaseCharsetConverter
Character set converter for database tables.

Code

public function convertAllDatabases(array $databases) {
  $success = FALSE;
  foreach ($databases as $database_key => $database_values) {
    foreach ($database_values as $target => $database) {
      // Do not update slave databases, they will have changes replicated
      // to them automatically. Only update mysql/mysqli-based connections.
      if ($target === 'slave' || !isset($database['driver']) || strpos($database['driver'], 'mysql') !== 0) {
        continue;
      }

      // Connect to next database.
      $connection = Database::getConnection($target, $database_key);
      if ($this->charset == 'utf8mb4' && !$connection->utf8mb4IsSupported()) {
        // Intentionally no translation here in the event this is used
        // outside a full Backdrop bootstrap (e.g. a command line tool).
        throw new Exception('The ' . $database_key . ':' . $target . ' MySQL database does not support UTF8MB4! Ensure that the conditions listed in settings.php related to innodb_large_prefix, the server version, and the MySQL driver version are met. See http://api.backdropcms.org/database-configuration for more information.');
        continue;
      }
      // For each database:
      $this->setConnection($connection);
      $this->convertDatabase($database['database']);

      // Build the list of tables to convert.
      $like = '';
      if ($database['prefix']) {
        $like = ' LIKE "' . $database['prefix'] . '%"';
      }
      $tables = $connection->query('SHOW TABLES' . $like)->fetchAllKeyed();
      $this->convertTables($tables);

      $success = TRUE;
    }
  }
  return $success;
}