UsersCountAll.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/UsersCountAll.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class UsersCountAll extends SiteAuditCheckBase {
public function getResultFail() {
return $this
->t('There are no users!');
}
public function getResultInfo() {
return $this
->formatPlural($this->registry->count_users_all, 'There is one user.', 'There are @count users.');
}
public function getResultPass() {
}
public function getResultWarn() {
}
public function getAction() {
}
public function calculateScore() {
$query = \Drupal::database()
->select('users');
$query
->addExpression('COUNT(*)', 'count');
$query
->condition('uid', 0, '<>');
try {
$this->registry->count_users_all = $query
->execute()
->fetchField();
if (!$this->registry->count_users_all) {
$this->abort = TRUE;
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO;
} catch (DatabaseExceptionWrapper $e) {
$this->abort = TRUE;
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_FAIL;
}
}
}