function optimizedb_admin in OptimizeDB 7
Same name and namespace in other branches
- 6 optimizedb.module \optimizedb_admin()
Configuring the module.
See also
optimizedb_admin_clear_table_submit()
optimizedb_admin_clear_table_all_submit()
optimizedb_admin_optimize_table_submit()
1 string reference to 'optimizedb_admin'
- optimizedb_menu in ./
optimizedb.module - Implements hook_menu().
File
- ./
optimizedb.module, line 110 - Database Optimization.
Code
function optimizedb_admin($form, &$form_state) {
if ($message = optimizedb_check_works()) {
$form['error'] = array(
'#markup' => $message,
);
return $form;
}
$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(
'#markup' => 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),
);
$form['optimizedb_auto']['optimizedb_clear_limit'] = array(
'#type' => 'select',
'#title' => t('Remove for one time'),
'#description' => t('The number of deleted records from cache_form table at a time.'),
'#default_value' => variable_get('optimizedb_clear_limit', 0),
'#options' => array(
0 => t('Without limits'),
1000 => 1000,
5000 => 5000,
10000 => 10000,
50000 => 50000,
100000 => 100000,
500000 => 500000,
),
'#states' => array(
'visible' => array(
'select[name="optimizedb_clear_type"]' => array(
'value' => '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'),
),
);
$time_array = array(
t('Disabled'),
);
foreach (range(0, 23, OPTIMIZEDB_CLEAR_PERIOD_STEP) as $time) {
$time_finish = $time + OPTIMIZEDB_CLEAR_PERIOD_STEP;
$time_format = number_format($time, 2, ':', '') . ' - ' . number_format($time_finish, 2, ':', '');
$time_array[$time_finish] = $time_format;
}
$form['optimizedb_auto']['optimizedb_clear_period_time'] = array(
'#type' => 'select',
'#title' => t('The period of time when you need to clean'),
'#default_value' => variable_get('optimizedb_clear_period_time', 0),
'#options' => $time_array,
'#description' => t('<b>Warning!</b> If Cron will not be executed in the selected time period, the cleaning is not going to happen.'),
);
// Default values.
$table_length = new stdClass();
$table_length->Data_length = 0;
$table_length->Index_length = 0;
switch (db_driver()) {
case 'mysql':
$table_name = Database::getConnection()
->prefixTables('{cache_form}');
$quote_char = variable_get('mysql_identifier_quote_character', MYSQL_IDENTIFIER_QUOTE_CHARACTER_DEFAULT);
$table_name = str_replace($quote_char, '', $table_name);
$table_length = db_query('SHOW TABLE STATUS LIKE :table_name', array(
':table_name' => db_like($table_name),
))
->fetchObject();
break;
case 'pgsql':
$table_length = db_query("SELECT pg_total_relation_size('{cache_form}') AS \"Data_length\",\n 0 AS \"Index_length\"")
->fetchObject();
break;
}
$table_length = $table_length->Data_length + $table_length->Index_length;
$form['optimizedb_auto']['length'] = array(
'#markup' => t('The current size of the table <strong>@length</strong>.', array(
'@length' => 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 = format_size(variable_get('optimizedb_tables_size', 0));
$form['optimize_table']['tables'] = array(
'#type' => 'item',
'#title' => t('Current information on all database tables.'),
'#markup' => 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/config/development/optimizedb/list_tables'),
)),
);
return system_settings_form($form);
}