public static function Cleaner::cleanerMysqlOptimizing in Cleaner 7
MySQL tables optimizing handler.
Parameters
int $opt: Operation flag.
2 calls to Cleaner::cleanerMysqlOptimizing()
- cleaner_cleaner_run in ./
cleaner.module - Implements hook_cleaner_run().
- hook_cleaner_run in ./
cleaner.api.php - Cleaner execution hook.
File
- ./
class.Cleaner.php, line 191 - Cleaner base class file.
Class
- Cleaner
- Class Cleaner.
Code
public static function cleanerMysqlOptimizing($opt = 0) {
$db_type = db_driver();
// Make sure the db type hasn't changed.
if ($db_type == 'mysql') {
// Gathering tables list.
$list = array();
foreach (db_query("SHOW TABLE STATUS") as $table) {
if ($table->Data_free) {
$list[] = $table->Name;
}
}
if (!empty($list)) {
// Run optimization timer.
timer_start('cleaner_db_optimization');
// Execute optimize query.
$query = 'OPTIMIZE ' . ($opt == 2 ? 'LOCAL ' : '');
$query .= 'TABLE {' . implode('}, {', $list) . '}';
db_query($query);
// Write a log about successful optimization into the watchdog.
self::cleanerLog('Optimized tables: !opts. This required !time seconds.', array(
'!opts' => implode(', ', $list),
'!time' => number_format(timer_read('cleaner_db_optimization') / 1000, 3),
));
}
else {
// Write a log about thing that optimization process is
// no tables which can to be optimized.
self::cleanerLog('There is no tables which can to be optimized.', array(), WATCHDOG_NOTICE);
}
}
else {
// Write a log about thing that optimization process isn't allowed
// for non-MySQL databases into the watchdog.
self::cleanerLog('Database type (!type) not allowed to be optimized.', array(
'!type' => $db_type,
), WATCHDOG_ERROR);
}
}