You are here

public function SiteAuditCheckDatabaseSize::calculateScore in Site Audit 8.2

Same name and namespace in other branches
  1. 7 Check/Database/Size.php \SiteAuditCheckDatabaseSize::calculateScore()

Implements \SiteAudit\Check\Abstract\calculateScore().

Overrides SiteAuditCheckAbstract::calculateScore

File

Check/Database/Size.php, line 62
Contains \SiteAudit\Check\Database\Size.

Class

SiteAuditCheckDatabaseSize
Class SiteAuditCheckDatabaseSize.

Code

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();
  }
  try {
    $sql_query = 'SELECT SUM(TABLES.data_length + TABLES.index_length) ';
    $sql_query .= 'FROM information_schema.TABLES ';
    $sql_query .= 'WHERE TABLES.table_schema = :dbname ';
    $sql_query .= 'GROUP BY TABLES.table_schema ';
    $this->registry['rows_by_table'] = db_query($sql_query, array(
      ':dbname' => $db_spec['database'],
    ))
      ->fetchField();
    if (!$this->registry['rows_by_table']) {
      $this->abort = TRUE;
      return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
    }
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO;
  } catch (DatabaseExceptionWrapper $e) {

    // Error executing the query.
    $this->abort = TRUE;
    return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL;
  }
}