1 system.install _system_check_db_utf8mb4_requirements($phase)

Checks whether the requirements for multi-byte UTF-8 support are met.

Parameters

string $phase: The hook_requirements() stage.

Return value

array: A requirements array with the result of the charset check.

File

core/modules/system/system.install, line 707
Install, update and uninstall functions for the system module.

Code

function _system_check_db_utf8mb4_requirements($phase) {
  global $install_state;
  // In the requirements check of the installer, skip the utf8mb4 check unless
  // the database connection info has been preconfigured by hand with valid
  // information before running the installer, as otherwise we cannot get a
  // valid database connection object.
  if (isset($install_state['settings_verified']) && !$install_state['settings_verified']) {
    return array();
  }

  $connection = Database::getConnection();
  $t = get_t();
  $requirements['title'] = $t('MySQL Database 4-byte UTF-8 support');

  $utf8mb4_active = $connection->utf8mb4IsActive();
  $utf8mb4_supported = $connection->utf8mb4IsSupported();
  $documentation_url = 'https://docs.backdropcms.org/documentation/database-configuration';
  $upgrade_path = 'admin/config/development/utf8mb4-upgrade';

  $requirements['description'] = $t('4-byte UTF-8 support enables extended characters to be saved into the database, including emojis, Asian symbols and mathematical symbols.');

  if ($utf8mb4_active) {
    if ($utf8mb4_supported) {
      if ($phase != 'install' && $phase != 'update' && !state_get('database_utf8mb4_active', FALSE)) {
        // Supported, active, and configurable, but not all database tables
        // have been converted yet.
        $requirements['value'] = l($t('Database tables need conversion'), $upgrade_path);
        $requirements['description'] .= ' ' . $t('Your server supports this feature but not all tables have been converted to use it.');
        if ($_GET['q'] !== $upgrade_path) {
          $requirements['description'] .= ' ' . $t('After making a database backup, you should <a href="@url">convert existing tables</a>.', array('@url' => url($upgrade_path)));
        }
        $requirements['severity'] = REQUIREMENT_ERROR;
      }
      else {
        // Supported, active.
        $requirements['value'] = $t('Enabled');
        $requirements['severity'] = REQUIREMENT_OK;
      }
    }
    else {
      // Not supported, active.
      $requirements['value'] = $t('Not supported');
      $requirements['description'] .= ' ' . $t('This feature is enabled, but not supported on your system. Please turn this off in <code>settings.php</code>, or ensure that all database-related requirements are met. See the <a href="@url" target="_blank">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@url' => $documentation_url));
      $requirements['severity'] = REQUIREMENT_ERROR;
    }
  }
  else {
    if ($utf8mb4_supported) {
      // Supported, not active.
      $requirements['value'] = $t('Not enabled');
      $requirements['description'] .= ' ' . $t('This feature is not enabled, but it is supported on your system. See the <a href="@url" target="_blank">documentation on adding 4 byte UTF-8 support</a> for more information.', array('@url' => $documentation_url));
      $requirements['severity'] = REQUIREMENT_INFO;
    }
    else {
      // Not supported, not active.
      $requirements['value'] = $t('Not available');
      $requirements['description'] .= ' ' . $t('This feature is not supported on your system. See the <a href="@url" target="_blank">documentation on adding 4-byte UTF-8 support</a> for more information.', array('@url' => $documentation_url));
      $requirements['severity'] = REQUIREMENT_INFO;
    }
  }
  return $requirements;
}