public function SiteAuditCheckDatabaseFragmentation::calculateScore in Site Audit 8.2
Implements \SiteAudit\Check\Abstract\calculateScore().
Overrides SiteAuditCheckAbstract::calculateScore
File
- Check/
Database/ Fragmentation.php, line 90 - Contains \SiteAudit\Check\Database\Fragmentation.
Class
- SiteAuditCheckDatabaseFragmentation
- Class SiteAuditCheckDatabaseFragmentation.
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();
}
$sql_query = 'SELECT TABLE_NAME AS name';
$sql_query .= ', ROUND(DATA_LENGTH / 1024 / 1024) AS data_length';
$sql_query .= ', ROUND(INDEX_LENGTH / 1024 / 1024) AS index_length';
$sql_query .= ', ROUND(DATA_FREE / 1024 / 1024) AS data_free';
$sql_query .= ' FROM information_schema.TABLES ';
$sql_query .= ' WHERE TABLES.DATA_FREE > 0 ';
$sql_query .= ' AND TABLES.table_schema = :dbname ';
$result = db_query($sql_query, array(
':dbname' => $db_spec['database'],
));
foreach ($result as $row) {
$data = $row->data_length + $row->index_length;
if ($data != 0) {
$free = $row->data_free;
$fragmentation_ratio = $free / $data;
if ($fragmentation_ratio > 0.05) {
$this->registry['database_fragmentation'][$row->name] = $fragmentation_ratio;
}
}
}
if (empty($this->registry['database_fragmentation'])) {
return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS;
}
return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN;
}