Watchdog404.php in Site Audit 8.3
File
src/Plugin/SiteAuditCheck/Watchdog404.php
View source
<?php
namespace Drupal\site_audit\Plugin\SiteAuditCheck;
use Drupal\site_audit\Plugin\SiteAuditCheckBase;
class Watchdog404 extends SiteAuditCheckBase {
public function getResultFail() {
}
public function getResultInfo() {
return $this
->t('@count_404 pages not found (@percent_404%).', [
'@count_404' => $this->registry->count_404,
'@percent_404' => $this->registry->percent_404,
]);
}
public function getResultPass() {
return $this
->t('No 404 entries.');
}
public function getResultWarn() {
return $this
->getResultInfo();
}
public function getAction() {
if ($this->score == SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN) {
return $this
->t('Review the full report at admin/reports/page-not-found. If self-inflicted, fix the source. If a redirect is appropriate, visit admin/config/search/path and add URL aliases.');
}
}
public function calculateScore() {
if (empty($this->registry->count_entries)) {
$this
->checkInvokeCalculateScore('watchdog_count');
}
if (!$this->registry->watchdog_enabled) {
return;
}
$query = \Drupal::database()
->select('watchdog');
$query
->addExpression('COUNT(wid)', 'count');
$query
->condition('type', 'page not found');
$this->registry->count_404 = $query
->execute()
->fetchField();
$this->registry->percent_404 = 0;
if (!$this->registry->count_404) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_PASS;
}
$this->registry->percent_404 = round($this->registry->count_404 / $this->registry->count_entries * 100);
if ($this->registry->percent_404 >= 10) {
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_WARN;
}
return SiteAuditCheckBase::AUDIT_CHECK_SCORE_INFO;
}
}