You are here

function optimizedb_optimize_batch_run in OptimizeDB 7

Same name and namespace in other branches
  1. 6 optimizedb.module \optimizedb_optimize_batch_run()

Batch callback: Optimization of a database table.

Parameters

string $table: Table name.

array $context: Reference to an array used for Batch API storage.

1 string reference to 'optimizedb_optimize_batch_run'
optimizedb_admin_optimize_table_submit in ./optimizedb.module
Form submission handler for optimizedb_admin().

File

./optimizedb.module, line 694
Database Optimization.

Code

function optimizedb_optimize_batch_run($table, &$context) {

  // Standard the status the result operation.
  $status = 'success';
  switch (db_driver()) {
    case 'mysql':
      try {
        $result = db_query('OPTIMIZE TABLE ' . $table)
          ->fetchObject();
        if (isset($result->Msg_type) && in_array(strtolower($result->Msg_type), array(
          'error',
          'warning',
        ))) {
          $status = 'error';
        }
      } catch (Exception $e) {
        $status = 'error';
      }
      break;
    case 'pgsql':
      try {
        db_query('VACUUM ANALYZE ' . $table);
      } catch (Exception $e) {
        $status = 'error';
      }
      break;
  }
  if (PHP_SAPI == 'cli') {
    drush_print(dt('Table "@name" been optimized.', array(
      '@name' => $table,
    )));
  }
  $context['results'][$status][] = $table;
}