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 replica databases, they will have changes replicated
      // to them automatically. Only update mysql/mysqli-based connections.
      $no_driver = !isset($database['driver']);
      $no_mysql_driver = strpos($database['driver'], 'mysql') !== 0;
      if ($target === 'replica' || $no_driver || $no_mysql_driver) {
        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 https://docs.backdropcms.org/documentation/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;
}