You are here

function optimizedb_admin in OptimizeDB 6

Same name and namespace in other branches
  1. 7 optimizedb.module \optimizedb_admin()

Configuring the module.

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

File

./optimizedb.module, line 68
Database Optimization.

Code

function optimizedb_admin() {
  $form = array();
  $form['executing_commands'] = array(
    '#type' => 'fieldset',
    '#title' => t('Executing commands manually'),
  );
  $form['executing_commands']['clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear cache_form table'),
    '#submit' => array(
      'optimizedb_admin_clear_table_submit',
    ),
  );
  $form['executing_commands']['clear_all'] = array(
    '#type' => 'submit',
    '#value' => t('Clear an entire table cache_form'),
    '#submit' => array(
      'optimizedb_admin_clear_table_all_submit',
    ),
  );
  $form['executing_commands']['optimize'] = array(
    '#type' => 'submit',
    '#value' => t('Optimize tables'),
    '#submit' => array(
      'optimizedb_admin_optimize_table_submit',
    ),
  );
  $form['executing_commands']['info'] = array(
    '#value' => t('<strong>Clear cache_form table</strong> - clear the cache in a table cache_form, which has expired.<br /><strong>Clear an entire table cache_form</strong> - deleting all the cache in a table cache_form.'),
    '#prefix' => '<div class="clearfix"></div>',
  );
  $form['optimizedb_auto'] = array(
    '#type' => 'fieldset',
    '#title' => t('Automatic clear cache_form table.'),
  );
  $form['optimizedb_auto']['optimizedb_clear_type'] = array(
    '#type' => 'select',
    '#title' => t('Cache removal option'),
    '#options' => array(
      0 => t('Delete cache which expired'),
      1 => t('Delete entire cache'),
    ),
    '#default_value' => variable_get('optimizedb_clear_type', 0),
  );
  $last_clear = variable_get('optimizedb_last_clear', 0);
  $form['optimizedb_auto']['optimizedb_clear_period'] = array(
    '#type' => 'select',
    '#title' => t('Clear cache_form table every'),
    '#description' => t('Last run: @date ago.', array(
      '@date' => _optimizedb_date($last_clear),
    )),
    '#default_value' => variable_get('optimizedb_clear_period', 0),
    '#options' => array(
      0 => t('Disabled'),
      100 => t('When performing Cron'),
      1 => t('@count day', array(
        '@count' => 1,
      )),
      2 => t('2 day'),
      7 => t('7 days'),
      14 => t('14 days'),
      30 => t('30 days'),
      60 => t('60 days'),
    ),
  );
  switch (optimizedb_db_driver()) {
    case 'mysql':
      $table_length = db_fetch_object(db_query("SHOW TABLE STATUS LIKE '{cache_form}';"));
      break;
    case 'pgsql':
      $table_length = db_fetch_object(db_query("SELECT pg_total_relation_size('{cache_form}') AS \"Data_length\",\n        0 AS \"Index_length\""));
      break;
  }
  $table_length = $table_length->Data_length + $table_length->Index_length;
  $form['optimizedb_auto']['lenght'] = array(
    '#value' => t('The current size of the table <strong>@length</strong>.', array(
      '@length' => _optimizedb_format_size($table_length),
    )),
  );
  $form['optimize_table'] = array(
    '#type' => 'fieldset',
    '#title' => t('Optimization settings database'),
  );
  $last_optimization = variable_get('optimizedb_last_optimization', 0);
  $form['optimize_table']['optimizedb_optimization_period'] = array(
    '#type' => 'select',
    '#title' => t('Receive notification of the need to optimize the database, every'),
    '#description' => t('Last run: @date ago.', array(
      '@date' => _optimizedb_date($last_optimization),
    )),
    '#default_value' => variable_get('optimizedb_optimization_period', 0),
    '#options' => array(
      0 => t('Disabled'),
      1 => t('@count day', array(
        '@count' => 1,
      )),
      2 => t('2 day'),
      7 => t('7 days'),
      14 => t('14 days'),
      30 => t('30 days'),
      60 => t('60 days'),
    ),
  );
  $size_tables = _optimizedb_format_size(variable_get('optimizedb_tables_size', 0));
  $form['optimize_table']['tables'] = array(
    '#type' => 'item',
    '#title' => t('Current information on all database tables'),
    '#value' => t('The size of all tables in the database: <b>@size</b>. View the size of the tables separately, you can on the page - <a href="@url">List of tables in the database</a>.', array(
      '@size' => $size_tables,
      '@url' => url('admin/settings/optimizedb/list_tables'),
    )),
  );
  return system_settings_form($form);
}