protected function CleanerMySqlOptimizationController::mysqlOptimize in Cleaner 8
MySQL optimizer.
1 call to CleanerMySqlOptimizationController::mysqlOptimize()
- CleanerMySqlOptimizationController::execute in src/
Controller/ CleanerMySqlOptimizationController.php - Perform the operation.
File
- src/
Controller/ CleanerMySqlOptimizationController.php, line 49
Class
- CleanerMySqlOptimizationController
- Class CleanerMySqlOptimizationController.
Namespace
Drupal\cleaner\ControllerCode
protected function mysqlOptimize() {
$opt = \Drupal::config(CLEANER_SETTINGS)
->get(self::$configName);
if ($opt) {
// Set's the default log level - info.
static::$logLevel = LogLevel::INFO;
// Get database connection.
$this->connection = \Drupal::database();
// Get's the database driver name.
$db_type = $this->connection
->driver();
// Make sure the db type hasn't changed.
if ($db_type == 'mysql') {
// Gathering tables list.
$list = $this
->buildTablesList();
if (!empty($list)) {
// Run optimization timer.
Timer::start('cleaner_db_optimization');
// Perform optimization.
$this
->optimizeIt(static::getOptimizationQuery($opt, $list));
// Write a log about successful optimization into the watchdog.
// Convert tables list into a comma-separated list.
$list = implode(', ', $list);
// Get the timers's results.
$time = static::getTimerResult();
// Create a log message.
static::$logMessage = "Optimized tables: {$list}. This required {$time} seconds.";
}
else {
// Write a log about thing that optimization process is
// no tables which can to be optimized.
static::$logMessage = 'There is no tables which can to be optimized.';
}
}
else {
// Write a log(error) about thing that optimization process
// isn't allowed for non-MySQL databases into the watchdog.
// Change log level to an error.
static::$logLevel = LogLevel::ERROR;
static::$logMessage = "Database type ({$db_type}) not allowed to be optimized.";
}
// Write some logs.
\Drupal::service('cleaner_logger')
->log(static::$logLevel, static::$logMessage);
}
}