DatabaseEngine.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/DatabaseEngine.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\Core\Database\Database;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class DatabaseEngine extends SiteAuditCheckBase {
public function getResultFail() {
if (TRUE) {
$ret_val = '<table class="table table-condensed">';
$ret_val .= '<thead><tr><th>' . $this
->t('Table Name') . '</th><th>' . $this
->t('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 (!$this->options['json']) {
$ret_val .= str_repeat(' ', 4);
}
$ret_val .= '---------------------';
foreach ($this->registry->engine_tables as $name => $engine) {
$ret_val .= PHP_EOL;
if (!$this->options['json']) {
$ret_val .= str_repeat(' ', 4);
}
$ret_val .= "{$name}: {$engine}";
}
}
return $ret_val;
}
public function getResultInfo() {
}
public function getResultPass() {
return $this
->t('Every table is using InnoDB.');
}
public function getResultWarn() {
}
public function getAction() {
if ($this->score != SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS) {
return $this
->t('Change the Storage Engine to InnoDB. See @url for details.', [
'@url' => 'http://dev.mysql.com/doc/refman/5.6/en/converting-tables-to-innodb.html',
]);
}
}
public function calculateScore() {
$connection = Database::getConnection();
$query = \Drupal::database()
->select('information_schema.TABLES', 'ist');
$query
->addField('ist', 'TABLE_NAME', 'name');
$query
->addField('ist', 'ENGINE', 'engine');
$query
->condition('ist.ENGINE', 'InnoDB', '<>');
$query
->condition('ist.table_schema', $connection
->getConnectionOptions()['database']);
$result = $query
->execute();
$count = 0;
while ($row = $result
->fetchAssoc()) {
$count++;
$this->registry->engine_tables[$row['name']] = $row['engine'];
}
if ($count === 0) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL;
}
}