You are here

function data_ui_adjust_form in Data 7

Same name and namespace in other branches
  1. 6 data_ui/data_ui.admin.inc \data_ui_adjust_form()

Adjust table schema form: Present the user with the difference between schema information and the actual schema in the Database and offer three options:

  • Adjust schema info,
  • adjust database or
  • leave it.
1 string reference to 'data_ui_adjust_form'
data_ui_menu in data_ui/data_ui.module
Implements hook_menu().

File

data_ui/data_ui.admin.inc, line 119
Admin UI functions.

Code

function data_ui_adjust_form($form, &$form_state, $table) {
  $table = data_get_table($table);
  drupal_set_title(t('Adjust !table', array(
    '!table' => $table
      ->get('name'),
  )));
  $comparison = $table
    ->compareSchema();
  $form = array();
  $form_state['#redirect'] = 'admin/structure/data/compare';
  $form['#table'] = $table;
  $form['#comparison'] = $comparison;
  $form['comparison'] = array(
    '#type' => 'fieldset',
    '#title' => t('Comparison'),
  );
  $form['comparison']['comparison']['#value'] = theme('data_ui_schema_compare_table', array(
    'comparison' => $comparison,
  ));
  if ($comparison['status'] == 'different') {
    $form['update_schema'] = array(
      '#type' => 'fieldset',
      '#title' => t('Option 1: Update schema information'),
    );
    $form['update_schema']['description'] = array(
      '#markup' => t('<p>This option will update the schema information about this table.</p>'),
    );
    $form['update_schema']['submit'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'data_ui_adjust_form_submit_update_schema',
      ),
      '#value' => t('Update schema information'),
    );
    $form['alter_table'] = array(
      '#type' => 'fieldset',
      '#title' => t('Option 2: Alter table'),
    );
    $form['alter_table']['description'] = array(
      '#markup' => t('<p>Review the changes above carefully!
        This option will alter the database table and can very
        easily cause data loss.</p>'),
    );
    $form['alter_table']['submit'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'data_ui_adjust_form_submit_alter_table',
      ),
      '#value' => t('Alter table'),
    );
  }
  elseif ($comparison['status'] == 'missing') {
    $form['alter_table'] = array(
      '#type' => 'fieldset',
      '#title' => t('Create table'),
    );
    $form['alter_table']['description'] = array(
      '#markup' => t('<p>Create a new table from schema information.</p>'),
    );
    $form['alter_table']['submit'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'data_ui_adjust_form_submit_create_table',
      ),
      '#value' => t('Create table'),
    );
  }
  $form['cancel'] = array(
    '#type' => 'fieldset',
    '#title' => t('Don\'t change anything'),
  );
  $form['cancel']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  return $form;
}