DbLog.php in Production check & Production monitor 8
File
src/Plugin/ProdCheck/Server/DbLog.php
View source
<?php
namespace Drupal\prod_check\Plugin\ProdCheck\Server;
use Drupal\prod_check\Plugin\ProdCheck\ProdCheckBase;
class DbLog extends ProdCheckBase {
public $errorLevel;
public $threshold;
public $result;
public function init() {
$this->errorLevel = 0;
$this->threshold = 0;
$this->result = \Drupal::database()
->query('SELECT COUNT(*) FROM (SELECT count(wid) FROM {watchdog} WHERE type = :type AND severity <= :severity GROUP BY variables HAVING COUNT(wid) >= :threshold) subquery', [
':type' => 'php',
':severity' => $this->errorLevel,
':threshold' => $this->threshold,
])
->fetchField();
}
public function state() {
return !$this->result;
}
public function successMessages() {
return [
'value' => $this
->t('No PHP errors reported.'),
'description' => $this
->t('Status is OK for production use.'),
];
}
public function failMessages() {
$link_array = $this
->generateLinkArray($this
->title(), 'dblog.overview');
return [
'value' => $this
->t('PHP errors reported.'),
'description' => $this
->formatPlural($this->result, '@count PHP error occuring more than @threshold time(s) has been reported! Check the %link for details!', '@count PHP errors occuring more than @threshold time(s) have been reported! Check the %link for details!', [
'%link' => implode($link_array),
'@threshold' => $this->threshold,
]),
];
}
}