SensorCoreRequirements.php in Monitoring 7
File
lib/Drupal/monitoring/Sensor/Sensors/SensorCoreRequirements.php
View source
<?php
namespace Drupal\monitoring\Sensor\Sensors;
use Drupal\monitoring\Result\SensorResultInterface;
use Drupal\monitoring\Sensor\Sensor;
class SensorCoreRequirements extends Sensor {
protected $requirements;
public function runSensor(SensorResultInterface $result) {
$requirements = $this
->getRequirements($this->info
->getSetting('module'));
foreach ($this->info
->getSetting('exclude keys', array()) as $exclude_key) {
if (isset($requirements[$exclude_key])) {
unset($requirements[$exclude_key]);
}
}
$this
->processRequirements($result, $requirements);
}
protected function getHighestSeverity(&$requirements) {
$severity = REQUIREMENT_INFO;
foreach ($requirements as $requirement) {
if (isset($requirement['severity'])) {
$severity = max($severity, $requirement['severity']);
}
}
return $severity;
}
protected function getRequirements($module) {
module_load_include('install', $module);
$function = $module . '_requirements';
if (!function_exists($function)) {
throw new \RuntimeException(format_string('Requirement function @function not found', array(
'@function' => $function,
)));
}
return (array) $function('runtime');
}
protected function processRequirements(SensorResultInterface $result, $requirements) {
$severity = $this
->getHighestSeverity($requirements);
if ($severity == REQUIREMENT_ERROR) {
$result
->setStatus(SensorResultInterface::STATUS_CRITICAL);
}
elseif ($severity == REQUIREMENT_WARNING) {
$result
->setStatus(SensorResultInterface::STATUS_WARNING);
}
else {
$result
->setStatus(SensorResultInterface::STATUS_OK);
}
if (!empty($requirements)) {
foreach ($requirements as $requirement) {
if (!isset($requirement['severity']) || $requirement['severity'] != $severity) {
continue;
}
if (!empty($requirement['title'])) {
$result
->addStatusMessage($requirement['title']);
}
if (!empty($requirement['description'])) {
$result
->addStatusMessage($requirement['description']);
}
if (!empty($requirement['value'])) {
$result
->addStatusMessage($requirement['value']);
}
}
}
else {
$result
->addStatusMessage('Requirements check OK');
}
}
}