DatabaseSize.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/DatabaseSize.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\Core\Database\Database;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class DatabaseSize extends SiteAuditCheckBase {
public function getResultFail() {
return $this
->t('Empty, or unable to determine the size due to a permission error.');
}
public function getResultInfo() {
return $this
->t('Total size: @size_in_mbMB', [
'@size_in_mb' => number_format($this->registry->table_size / 1048576, 2),
]);
}
public function getResultPass() {
}
public function getResultWarn() {
}
public function getAction() {
}
public function calculateScore() {
$connection = Database::getConnection();
try {
$query = \Drupal::database()
->select('information_schema.TABLES', 'ist');
$query
->addExpression('SUM(ist.data_length + ist.index_length)');
$query
->condition('ist.table_schema', $connection
->getConnectionOptions()['database']);
$query
->groupBy('ist.table_schema');
$this->registry->table_size = $query
->execute()
->fetchField();
if (!$this->registry->table_size) {
$this->abort = TRUE;
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO;
} catch (Exception $e) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL;
}
}
}