function apdqc_admin_operations_form in Asynchronous Prefetch Database Query Cache 7
Form builder; perform apdqc operations.
See also
1 call to apdqc_admin_operations_form()
- apdqc_requirements in ./
apdqc.install - Implements hook_requirements().
1 string reference to 'apdqc_admin_operations_form'
- apdqc_menu in ./
apdqc.module - Implements hook_menu().
File
- ./
apdqc.admin.inc, line 112 - Admin page callbacks for the apdqc module.
Code
function apdqc_admin_operations_form($form, $form_state) {
apdqc_admin_set_message_if_needed();
if (!empty($form) || !empty($form_state)) {
drupal_set_title(t('APDQC: Operations'));
}
// Check semaphore table.
// Get MySQL version.
$conversion = apdqc_semaphore_conversion();
if ($conversion == 1) {
$form['convert_semaphore_table'] = array(
'#type' => 'fieldset',
'#title' => t('Convert semaphore table'),
'#description' => t('For older versions of MySQL (5.5 and lower) using the memory engine for the semaphore table is recommended.'),
);
$form['convert_semaphore_table']['convert_table_to_memory'] = array(
'#type' => 'submit',
'#value' => t('Convert semaphore table to MEMORY'),
'#submit' => array(
'apdqc_admin_convert_table_to_memory',
),
);
}
elseif ($conversion == 2) {
$form['convert_semaphore_table'] = array(
'#type' => 'fieldset',
'#title' => t('Convert semaphore table'),
'#description' => t('For newer versions of MySQL (5.6 and higher) the InnoDB engine for the semaphore table is recommended.'),
);
$form['convert_semaphore_table']['convert_table_to_innodb'] = array(
'#type' => 'submit',
'#value' => t('Convert semaphore table to InnoDB'),
'#submit' => array(
'apdqc_admin_convert_semaphore_table_to_innodb',
),
);
}
$lock_inc = variable_get('lock_inc', 'includes/lock.inc');
$semaphore_update = apdqc_admin_semaphore_table_need_update();
if (stripos($lock_inc, 'apdqc.lock.inc') !== FALSE && $semaphore_update) {
$form['convert_semaphore_table_schema'] = array(
'#type' => 'fieldset',
'#title' => t('Semaphore table schema update'),
'#description' => t('Will make the primary key be name, value, expire; have the name and value columns use ascii_bin.'),
);
$form['convert_semaphore_table_schema']['semaphore_table_update_schema'] = array(
'#type' => 'submit',
'#value' => t('Semaphore table schema update'),
'#submit' => array(
'apdqc_admin_semaphore_table_update_schema',
),
);
}
$session = variable_get('session_inc', 'includes/session.inc');
$session_update = apdqc_admin_sessions_table_need_update();
$session_update_duplicates = apdqc_admin_sessions_table_duplicates(FALSE, FALSE);
if (stripos($session, 'apdqc.session.inc') !== FALSE && (!empty($session_update) || !empty($session_update_duplicates))) {
$form['convert_sessions_table_schema'] = array(
'#type' => 'fieldset',
'#title' => t('Sessions table schema update'),
'#description' => t('Will make sid and ssid be char(43); hostname varchar(45); sid, ssid, and hostname be ascii_bin. This can sometimes take a little while.'),
);
$form['convert_sessions_table_schema']['sessions_table_update_schema'] = array(
'#type' => 'submit',
'#value' => t('Sessions table schema update'),
'#submit' => array(
'apdqc_admin_sessions_table_update_schema',
),
);
}
// Check collation.
$results_utf8 = apdqc_admin_change_table_collation(FALSE, 'utf8_bin');
$results_ascii = apdqc_admin_change_table_collation(FALSE, 'ascii_bin');
$collation = variable_get('apdqc_table_collations', APDQC_TABLE_COLLATIONS);
$cache_tables = apdqc_get_cache_tables(TRUE, FALSE);
$charset = 'ASCII';
$non_ascii_tables = array();
foreach ($cache_tables as $table_name) {
if (db_table_exists($table_name)) {
$results = db_query("SELECT COUNT(*) AS bad_translation FROM {{$table_name}} WHERE cid <> CONVERT(cid USING {$charset})")
->fetchAssoc();
if (!empty($results['bad_translation'])) {
$non_ascii_tables[] = $table_name;
}
}
}
$cache_page = array();
if (module_exists('locale')) {
$cache_page = array(
'cache_page',
'cache_page__truncated_table',
);
}
$ascii_tables = array();
foreach ($results_utf8 as $table => $values) {
foreach ($values as $current_collation) {
if ($current_collation === 'ascii_bin') {
$ascii_tables[] = $table;
}
}
}
$utf8_tables = array();
foreach ($results_ascii as $table => $values) {
foreach ($values as $current_collation) {
if ($current_collation === 'utf8_bin') {
$utf8_tables[] = $table;
}
}
}
$not_using_ascii = array_diff($cache_tables, $ascii_tables, $cache_page, $non_ascii_tables);
$not_using_utf8 = array_diff($cache_tables, $utf8_tables, $cache_page, $non_ascii_tables);
if (!empty($results_utf8) && (empty($not_using_ascii) || $collation === 'utf8_bin')) {
if (empty($results_ascii) || $collation === 'ascii_bin') {
$form['convert_cache_tables_collation_utf8'] = array(
'#type' => 'fieldset',
'#title' => t('Convert cache tables collations to utf8 from ascii'),
'#description' => t('You are currently using ascii_bin which is faster but may not be as accurate when matching cache ids. Using the utf8_bin collation can be more accurate when matching cache ids. In reality ascii_bin is usually ok and causes no issues, thus you should not convert these tables back to utf8_bin unless you have a reason to.'),
);
if ($collation === 'ascii_bin') {
$form['convert_cache_tables_collation_utf8'] += array(
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 100,
);
}
}
else {
$form['convert_cache_tables_collation_utf8'] = array(
'#type' => 'fieldset',
'#title' => t('Convert cache tables collations to utf8'),
'#description' => t('Using the utf8_bin collation is faster and more accurate when matching cache ids since no unicode normalization is done to cache queries. Tables not using utf8_bin: @tables', array(
'@tables' => implode(', ', $not_using_utf8),
)),
'#raw_data' => $not_using_utf8,
);
}
$form['convert_cache_tables_collation_utf8']['convert_table_collations_to_utf8_bin'] = array(
'#type' => 'submit',
'#value' => t('Convert cache tables collations'),
'#submit' => array(
'apdqc_admin_convert_table_collations_to_utf8_bin',
),
);
}
if (!empty($results_ascii) && (empty($not_using_utf8) || $collation === 'ascii_bin')) {
$description = t('No cache tables where found that contain non ascii characters; conversion should be safe.');
if (!empty($non_ascii_tables)) {
$description = t('The following tables contain non ascii characters and will not be converted: @tables.', array(
'@tables' => implode(', ', $non_ascii_tables),
));
}
if (empty($results_utf8) || $collation === TRUE || $collation === 'utf8_bin') {
$form['convert_cache_tables_collation_ascii'] = array(
'#type' => 'fieldset',
'#title' => t('Convert cache tables collations to ascii from utf8'),
'#description' => t('You are currently using utf8_bin which is slightly slower but accurate when matching cache ids. Using the ascii_bin collation is faster but it could cause issues. @extra', array(
'@extra' => $description,
)),
);
if ($collation === 'utf8_bin') {
$form['convert_cache_tables_collation_ascii'] += array(
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 100,
);
}
}
else {
$form['convert_cache_tables_collation_ascii'] = array(
'#type' => 'fieldset',
'#title' => t('Convert cache tables collations to ascii'),
'#description' => t('Using the ascii_bin collation is very fast but it could cause issues. Tables not using ascii_bin: @tables. @extra', array(
'@tables' => implode(', ', $not_using_ascii),
'@extra' => $description,
)),
'#raw_data' => $not_using_ascii,
);
}
$form['convert_cache_tables_collation_ascii']['convert_table_collations_to_ascii_bin'] = array(
'#type' => 'submit',
'#value' => t('Convert cache tables collations'),
'#submit' => array(
'apdqc_admin_convert_table_collations_to_ascii_bin',
),
);
}
// Check engine.
$results = apdqc_admin_change_table_engine();
if (!empty($results)) {
$form['convert_cache_tables_engine'] = array(
'#type' => 'fieldset',
'#title' => t('Convert cache tables engine'),
'#description' => t('Using the InnoDB engine is faster and recommended'),
);
$form['convert_cache_tables_collation']['convert_table_engine_to_innodb'] = array(
'#type' => 'submit',
'#value' => t('Convert cache tables engine'),
'#submit' => array(
'apdqc_admin_convert_table_engine_to_innodb',
),
);
}
// Check cache indexes.
$cache_table_indexes = apdqc_get_cache_table_indexes();
$missing_expire_created_index = FALSE;
foreach ($cache_table_indexes as $indexes) {
if (!isset($indexes['expire_created'])) {
$missing_expire_created_index = TRUE;
break;
}
}
if (!empty($missing_expire_created_index)) {
$form['convert_cache_tables_indexes'] = array(
'#type' => 'fieldset',
'#title' => t('Convert cache tables indexes'),
'#description' => t('Garbage collection of the cache bins use the created column. This allows for proper enforcement of the minimum cache lifetime. There needs to be an index on created otherwise garbage collection will be slow.'),
);
$form['convert_cache_tables_indexes']['convert_table_collations_to_utf8_bin'] = array(
'#type' => 'submit',
'#value' => t('Convert cache tables indexes'),
'#submit' => array(
'apdqc_admin_convert_tables_indexes',
),
);
}
// Check if tables need to be put into individual files.
$results = array();
$results += db_query("SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table'")
->fetchAllKeyed();
if (variable_get('apdqc_innodb_file_per_table', APDQC_INNODB_FILE_PER_TABLE) === 'OFF' && $results['innodb_file_per_table'] === 'ON' || $results['innodb_file_per_table'] == 1) {
$form['all_db_tables_own_file'] = array(
'#type' => 'fieldset',
'#title' => t('Make every database table a file'),
'#description' => t('Once the innodb_file_per_table variable has been changed the tables need to be rebuilt so they live in their own file.'),
);
$form['all_db_tables_own_file']['convert_innodb_tables_to_files'] = array(
'#type' => 'submit',
'#value' => t('Make every database table a file'),
'#submit' => array(
'apdqc_admin_convert_innodb_tables_to_files',
),
);
}
if (empty($form)) {
// Explain what can be done on this page.
$form['tip'] = array(
'#markup' => '<p>' . t('Nothing needs to be done.') . '</p>',
'#weight' => -10,
);
}
else {
if (!variable_get('maintenance_mode', 0)) {
apdqc_disable_form($form);
$form['maintenance-mode-tip'] = array(
'#markup' => '<p>' . t('You need to put the site into <a href="@url">maintenance mode</a> in order to perform the operations below.', array(
'@url' => url('admin/config/development/maintenance'),
)) . '</p>',
'#weight' => -9,
);
}
// Explain what can be done on this page.
$form['tip'] = array(
'#markup' => '<p>' . t('This is a collection of commands to control the cache*, semaphore, and session tables and to manage testing of this module. There are no configuration options here.') . '</p>',
'#weight' => -10,
);
}
return $form;
}