You are here

function optimizedb_list_tables in OptimizeDB 7

Same name and namespace in other branches
  1. 6 optimizedb.module \optimizedb_list_tables()

List of tables in the database with the size and sorting.

See also

optimizedb_list_tables_check_tables_submit()

optimizedb_list_tables_repair_tables_submit()

optimizedb_list_tables_optimize_tables_submit()

1 string reference to 'optimizedb_list_tables'
optimizedb_menu in ./optimizedb.module
Implements hook_menu().

File

./optimizedb.module, line 330
Database Optimization.

Code

function optimizedb_list_tables($form, &$form_state) {
  if ($message = optimizedb_check_works()) {
    $form['error'] = array(
      '#markup' => $message,
    );
    return $form;
  }
  $headers = array(
    'name' => array(
      'data' => t('Table name'),
    ),
    'size' => array(
      'data' => t('Table size'),
      'field' => 'size',
      'sort' => 'desc',
    ),
  );
  $tables = _optimizedb_tables_list();

  // Desc or asc.
  $sort = tablesort_get_sort($headers);
  $sort_table =& drupal_static('_optimizedb_list_tables_sort:sort');
  $sort_table = $sort;

  // Sort descending and ascending.
  usort($tables, '_optimizedb_list_tables_sort');
  $rows = array();
  foreach ($tables as $table) {

    // Parameter "size_byte" us only needed to sort, now his unit to remove.
    unset($table['size_byte']);
    $rows[$table['name']] = $table;
  }
  $operations_tables_result = isset($_SESSION['optimizedb_list_tables_operations']) ? $_SESSION['optimizedb_list_tables_operations'] : NULL;
  if (!is_null($operations_tables_result)) {
    if ($operations_tables_result == array()) {
      drupal_set_message(t('The operation completed successfully.'));
    }
    else {
      $form['operations_tables'] = array(
        '#type' => 'fieldset',
        '#title' => t('Errors that arose during the operation:'),
      );
      $form['operations_tables']['errors'] = array(
        '#markup' => theme('table', array(
          'header' => array(
            array(
              'data' => t('Table name'),
            ),
            array(
              'data' => t('Type of problem'),
            ),
            array(
              'data' => t('Information about the problem'),
            ),
          ),
          'rows' => $operations_tables_result,
        )),
      );
    }
  }
  $_SESSION['optimizedb_list_tables_operations'] = NULL;
  if (db_driver() == 'mysql') {
    $form['operations'] = array(
      '#type' => 'fieldset',
      '#title' => t('Operations with tables:'),
    );
    $form['operations']['check_tables'] = array(
      '#type' => 'submit',
      '#value' => t('Check tables'),
      '#submit' => array(
        'optimizedb_list_tables_check_tables_submit',
      ),
    );
    $form['operations']['repair_tables'] = array(
      '#type' => 'submit',
      '#value' => t('Repair tables'),
      '#submit' => array(
        'optimizedb_list_tables_repair_tables_submit',
      ),
    );
    $form['operations']['optimize_tables'] = array(
      '#type' => 'submit',
      '#value' => t('Optimize tables'),
      '#submit' => array(
        'optimizedb_list_tables_optimize_tables_submit',
      ),
    );
  }
  $form['tables'] = array(
    '#type' => 'tableselect',
    '#header' => $headers,
    '#options' => $rows,
    '#empty' => t('No content available.'),
  );
  return $form;
}