SensorImageMissingStyle.php in Monitoring 7
File
lib/Drupal/monitoring/Sensor/Sensors/SensorImageMissingStyle.php
View source
<?php
namespace Drupal\monitoring\Sensor\Sensors;
use Drupal\monitoring\Result\SensorResultInterface;
class SensorImageMissingStyle extends SensorDatabaseAggregator {
protected $sourceImagePath;
public function buildQuery() {
$query = parent::buildQuery();
$query
->addField('watchdog', 'variables');
$query
->groupBy('variables');
$query
->orderBy('records_count', 'DESC');
return $query;
}
public function runSensor(SensorResultInterface $result) {
parent::runSensor($result);
$query_result = $this
->fetchObject();
if (!empty($query_result)) {
$variables = unserialize($query_result->variables);
if (isset($variables['%source_image_path'])) {
$result
->addStatusMessage($variables['%source_image_path']);
$this->sourceImagePath = $variables['%source_image_path'];
}
}
}
public function resultVerbose(SensorResultInterface $result) {
$verbose = parent::resultVerbose($result);
if ($result
->getValue() == 0) {
return $verbose;
}
if (empty($this->sourceImagePath)) {
$message = t('Source image path is empty, cannot query file_managed table');
}
$file = db_query('SELECT * FROM file_managed WHERE uri = :uri', array(
':uri' => $this->sourceImagePath,
))
->fetchObject();
if (!empty($file)) {
$message = t('File managed records: <pre>@file_managed</pre>', array(
'@file_managed' => var_export(file_usage_list($file), TRUE),
));
}
if (empty($message)) {
$message = t('File @file record not found in the file_managed table.', array(
'@file' => $result
->getMessage(),
));
}
$verbose .= ' ' . $message;
return $verbose;
}
}