DatabaseRowCount.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/DatabaseRowCount.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\Core\Database\Database;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class DatabaseRowCount extends SiteAuditCheckBase {
public function getResultFail() {
}
public function getResultInfo() {
if (empty($this->registry->rows_by_table)) {
return $this
->t('No tables with more than 1000 rows.');
}
$table_rows = [];
foreach ($this->registry->rows_by_table as $table_name => $rows) {
$table_rows[] = [
$table_name,
$rows,
];
}
$header = [
$this
->t('Table Name'),
$this
->t('Rows'),
];
return [
'#theme' => 'table',
'#class' => 'table-condensed',
'#header' => $header,
'#rows' => $table_rows,
];
}
public function getResultPass() {
}
public function getResultWarn() {
return $this
->getResultInfo();
}
public function getAction() {
}
public function calculateScore() {
$connection = Database::getConnection();
$this->registry->rows_by_table = [];
$warning = FALSE;
$query = \Drupal::database()
->select('information_schema.TABLES', 'ist');
$query
->fields('ist', [
'TABLE_NAME',
'TABLE_ROWS',
]);
$query
->condition('ist.TABLE_ROWS', 1000, '>');
$query
->condition('ist.table_schema', $connection
->getConnectionOptions()['database']);
$query
->orderBy('TABLE_ROWS', 'DESC');
$result = $query
->execute()
->fetchAllKeyed();
foreach ($result as $table => $rows) {
if ($rows > 1000) {
$warning = TRUE;
}
$this->registry->rows_by_table[$table] = $rows;
}
if ($warning) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO;
}
}