1 system.admin.inc system_utf8mb4_convert_form($form, &$form_state)

Form to convert existing database tables to utf8mb4 if supported.

File

core/modules/system/system.admin.inc, line 2413
Admin page callbacks for the system module.

Code

function system_utf8mb4_convert_form($form, &$form_state) {
  // Reuse the installation requirements checking and messages.
  module_load_install('system');
  $requirements = _system_check_db_utf8mb4_requirements('runtime');

  $connection = Database::getConnection();
  $utf8mb4_active = $connection->utf8mb4IsActive();
  $utf8mb4_supported = $connection->utf8mb4IsSupported();
  $utf8mb4_tables_converted = state_get('database_utf8mb4_active', FALSE);

  $form['help'] = array(
    '#type' => 'help',
    '#markup' => '<p>' . $requirements['description'] . '</p>',
  );

  // Not active and/or supported. Existing messages should be sufficient.
  if (!$utf8mb4_active || !$utf8mb4_supported) {
    return $form;
  }

  // Already active and supported. Indicate completion.
  if ($utf8mb4_active && $utf8mb4_supported && $utf8mb4_tables_converted) {
    $form['help']['#markup'] .= '<p>' . t('This feature is already enabled on your site, no further action is needed.') . '</p>';
    return $form;
  }

  $form['help']['#markup'] .= '<p>' . t('This operation is irreversible! Make sure that you have backed up your database before continuing. Your site will be put into maintenance mode during the upgrade. A site with hundreds of pieces of content should take a few minutes. Sites with thousands of pieces of content may take @minutes minutes or more.', array('@minutes' => 10)) . '</p>';

  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Upgrade database to 4 byte UTF-8'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'link',
    '#title' => t('Cancel'),
    '#href' => 'admin/reports/status',
  );

  return $form;
}