You are here

Engine.php in Site Audit 8.2

Same filename and directory in other branches
  1. 7 Check/Database/Engine.php

Contains \SiteAudit\Check\Database\Engine.

File

Check/Database/Engine.php
View source
<?php

/**
 * @file
 * Contains \SiteAudit\Check\Database\Engine.
 */

/**
 * Class SiteAuditCheckDatabaseEngine.
 */
class SiteAuditCheckDatabaseEngine extends SiteAuditCheckAbstract {

  /**
   * Implements \SiteAudit\Check\Abstract\getLabel().
   */
  public function getLabel() {
    return dt('Storage Engines');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getDescription().
   */
  public function getDescription() {
    return dt('Check to see if there are any tables that aren\'t using InnoDB.');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultFail().
   */
  public function getResultFail() {
    if (drush_get_option('html')) {
      $ret_val = '<table class="table table-condensed">';
      $ret_val .= '<thead><tr><th>Table Name</th><th>Engine</th></tr></thead>';
      $ret_val .= '<tbody>';
      foreach ($this->registry['engine_tables'] as $name => $engine) {
        $ret_val .= '<tr>';
        $ret_val .= '<td>' . $name . '</td>';
        $ret_val .= '<td>' . $engine . '</td>';
        $ret_val .= '</tr>';
      }
      $ret_val .= '</tbody>';
      $ret_val .= '</table>';
    }
    else {
      $ret_val = 'Table Name: Engine' . PHP_EOL;
      if (!drush_get_option('json')) {
        $ret_val .= str_repeat(' ', 4);
      }
      $ret_val .= '---------------------';
      foreach ($this->registry['engine_tables'] as $name => $engine) {
        $ret_val .= PHP_EOL;
        if (!drush_get_option('json')) {
          $ret_val .= str_repeat(' ', 4);
        }
        $ret_val .= "{$name}: {$engine}";
      }
    }
    return $ret_val;
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultInfo().
   */
  public function getResultInfo() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultPass().
   */
  public function getResultPass() {
    return dt('Every table is using InnoDB.');
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getResultWarn().
   */
  public function getResultWarn() {
  }

  /**
   * Implements \SiteAudit\Check\Abstract\getAction().
   */
  public function getAction() {
    if ($this->score != SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS) {
      return dt('Change the Storage Engine to InnoDB. See @url for details.', array(
        '@url' => 'http://dev.mysql.com/doc/refman/5.6/en/converting-tables-to-innodb.html',
      ));
    }
  }

  /**
   * Implements \SiteAudit\Check\Abstract\calculateScore().
   */
  public function calculateScore() {
    if (version_compare(DRUSH_VERSION, 7, '>=')) {
      $sql = drush_sql_get_class();
      $db_spec = $sql
        ->db_spec();
    }
    else {
      $db_spec = _drush_sql_get_db_spec();
    }
    $sql_query = 'SELECT TABLE_NAME AS name ';
    $sql_query .= ', ENGINE ';
    $sql_query .= 'FROM information_schema.TABLES ';
    $sql_query .= 'WHERE TABLES.table_schema = :dbname ';
    $sql_query .= 'AND ENGINE != :engine ';
    $result = db_query($sql_query, array(
      ':dbname' => $db_spec['database'],
      ':engine' => 'InnoDB',
    ));
    $count = 0;
    foreach ($result as $row) {
      $count++;
      $this->registry['engine_tables'][$row->name] = $row->ENGINE;
    }
    if ($count === 0) {
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
    }
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
  }

}

Classes

Namesort descending Description
SiteAuditCheckDatabaseEngine Class SiteAuditCheckDatabaseEngine.