class ImageMissingStyleSensorPlugin in Monitoring 8
Monitors image derivate creation errors from dblog.
@SensorPlugin( id = "image_style_missing", label = @Translation("Image Missing Style"), description = @Translation("Monitors image derivate creation errors from database log."), provider = "image", addable = FALSE ),
Displays image derivate with highest occurrence as message.
Hierarchy
- class \Drupal\monitoring\SensorPlugin\SensorPluginBase implements SensorPluginInterface uses MessengerTrait, StringTranslationTrait
- class \Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface uses DependencyTrait
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\WatchdogAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ImageMissingStyleSensorPlugin
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\WatchdogAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface
- class \Drupal\monitoring\Plugin\monitoring\SensorPlugin\DatabaseAggregatorSensorPlugin implements ExtendedInfoSensorPluginInterface uses DependencyTrait
- class \Drupal\monitoring\SensorPlugin\DatabaseAggregatorSensorPluginBase
Expanded class hierarchy of ImageMissingStyleSensorPlugin
File
- src/
Plugin/ monitoring/ SensorPlugin/ ImageMissingStyleSensorPlugin.php, line 29 - Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ImageMissingStyleSensorPlugin.
Namespace
Drupal\monitoring\Plugin\monitoring\SensorPluginView source
class ImageMissingStyleSensorPlugin extends WatchdogAggregatorSensorPlugin {
/**
* {@inheritdoc}
*/
protected $configurableConditions = FALSE;
/**
* {@inheritdoc}
*/
protected $configurableVerboseOutput = FALSE;
/**
* {@inheritdoc}
*/
public function getAggregateQuery() {
// Extends the watchdog query.
$query = parent::getAggregateQuery();
$query
->addField('watchdog', 'variables');
$query
->groupBy('variables');
$query
->orderBy('records_count', 'DESC');
return $query;
}
/**
* {@inheritdoc}
*/
public function runSensor(SensorResultInterface $result) {
parent::runSensor($result);
if (!empty($this->fetchedObject)) {
$variables = unserialize($this->fetchedObject->variables);
if (isset($variables['%source_image_path'])) {
$result
->addStatusMessage($variables['%source_image_path']);
}
}
}
/**
* {@inheritdoc}
*/
public function resultVerbose(SensorResultInterface $result) {
// The unaggregated result in a fieldset.
$output = parent::resultVerbose($result);
// The result aggregated per user.
$this
->verboseResultCounting($output);
return $output;
}
/**
* Get the aggregated table verbose output.
*
* @param array $output
* The output array, at which we will add the aggregated table
* verbose output.
*
* @return array
* Aggregated result table.
*/
public function verboseResultCounting(array &$output) {
if ($this->sensorConfig
->getSetting('verbose_fields')) {
// Fetch the top 20 matching entries, aggregated.
$query = $this
->getAggregateQuery();
// Also get the latest occurrence (highest timestamp).
$query
->addExpression('MAX(timestamp)', 'timestamp');
$query_result = $query
->range(0, 20)
->execute();
$this->queryString = $query_result
->getQueryString();
$rows = $this
->buildTableRows($query_result
->fetchAll());
$results = [];
foreach ($rows as $key => $row) {
$results[$key] = [];
$variables = unserialize($row['variables']);
$results[$key]['file'] = $variables['%source_image_path'];
$results[$key]['count'] = $row['records_count'];
$file = \Drupal::entityQuery('file')
->condition('uri', $variables['%source_image_path'])
->execute();
if (!empty($file)) {
$file = File::load(array_shift($file));
/** @var \Drupal\file\FileUsage\FileUsageInterface $usage */
$list_usages = \Drupal::service('file.usage')
->listUsage($file);
$usages = 0;
foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($list_usages)) as $sub) {
$usages += (int) $sub;
}
$results[$key]['usages'] = Link::fromTextAndUrl(\Drupal::translation()
->formatPlural($usages, '1 place', '@count places'), Url::fromUserInput('/admin/content/files/usage/' . $file
->id()));
}
else {
$results[$key]['usages'] = [
'#markup' => '',
];
}
$results[$key]['timestamp'] = \Drupal::service('date.formatter')
->format($row['timestamp'], 'short');
}
$output['aggregated_result'] = array(
'#type' => 'verbose_table_result',
'#title' => t('Aggregated result'),
'#header' => $this
->buildTableHeader($results),
'#rows' => $results,
'#query' => $query_result
->getQueryString(),
'#query_args' => $query
->getArguments(),
);
}
return $output;
}
/**
* {@inheritdoc}
*/
public function verboseResultUnaggregated(array &$output) {
parent::verboseResultUnaggregated($output);
foreach ($output['verbose_sensor_result']['#rows'] as $key => $row) {
/** @var \Drupal\Component\Render\FormattableMarkup $message */
$message = $row['message'];
$tmp_str = substr($message
->jsonSerialize(), strpos($message
->jsonSerialize(), '>') + 1);
$output['verbose_sensor_result']['#rows'][$key]['path'] = substr($tmp_str, 0, strpos($tmp_str, '<'));
unset($output['verbose_sensor_result']['#rows'][$key]['message']);
unset($output['verbose_sensor_result']['#rows'][$key]['timestamp']);
$output['verbose_sensor_result']['#rows'][$key]['timestamp'] = $row['timestamp'];
}
$output['verbose_sensor_result']['#header']['path'] = 'image path';
unset($output['verbose_sensor_result']['#header']['message']);
unset($output['verbose_sensor_result']['#header']['timestamp']);
$output['verbose_sensor_result']['#header']['timestamp'] = 'timestamp';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DatabaseAggregatorSensorPlugin:: |
protected | property | The arguments of the executed query. | |
DatabaseAggregatorSensorPlugin:: |
protected | property | The fetched object from the query result. | |
DatabaseAggregatorSensorPlugin:: |
protected | property | The arguments of the executed query. | |
DatabaseAggregatorSensorPlugin:: |
protected | property | The query string of the executed query. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Adds the aggregate expression to the select query. | 2 |
DatabaseAggregatorSensorPlugin:: |
public | function | Add row to table when pressing 'Add another condition' and rebuild. | |
DatabaseAggregatorSensorPlugin:: |
public | function | Adds another field to the keys table when pressing 'Add another key'. | |
DatabaseAggregatorSensorPlugin:: |
public | function |
Adds UI for variables table, conditions and keys. Overrides DatabaseAggregatorSensorPluginBase:: |
1 |
DatabaseAggregatorSensorPlugin:: |
protected | function | Builds the header for a table based on rows. | 3 |
DatabaseAggregatorSensorPlugin:: |
protected | function | Builds the rows of a table. | 1 |
DatabaseAggregatorSensorPlugin:: |
public | function |
Calculates dependencies for the configured plugin. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPlugin:: |
public | function | Returns the updated 'conditions' fieldset for replacement by ajax. | |
DatabaseAggregatorSensorPlugin:: |
public | function | Returns the updated 'output_table' fieldset for replacement by ajax. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Provides list of operators for conditions. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Builds history query over one db table. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Get the timestamp of the oldest entry that fits owr conditions. | |
DatabaseAggregatorSensorPlugin:: |
protected | function | Builds the query for verbose output. | 4 |
DatabaseAggregatorSensorPlugin:: |
public | function |
Form submission handler. Overrides DatabaseAggregatorSensorPluginBase:: |
|
DatabaseAggregatorSensorPlugin:: |
protected | function | Translates the string operators to SQL equivalents. | |
DatabaseAggregatorSensorPlugin:: |
public | function |
Form validation handler. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPluginBase:: |
protected | property |
Allows plugins to control if the value type can be configured. Overrides SensorPluginBase:: |
|
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets conditions to be used in the select query. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets the time field. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Returns time interval options. | |
DatabaseAggregatorSensorPluginBase:: |
protected | function | Gets the time interval value. | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
ImageMissingStyleSensorPlugin:: |
protected | property |
Allows plugins to control if the conditions table should be shown. Overrides DatabaseAggregatorSensorPlugin:: |
|
ImageMissingStyleSensorPlugin:: |
protected | property |
Allows plugins to control if the verbose output table should be shown. Overrides DatabaseAggregatorSensorPlugin:: |
|
ImageMissingStyleSensorPlugin:: |
public | function |
Builds simple aggregate query over one db table. Overrides DatabaseAggregatorSensorPlugin:: |
|
ImageMissingStyleSensorPlugin:: |
public | function |
Provide additional info about sensor call. Overrides DatabaseAggregatorSensorPlugin:: |
|
ImageMissingStyleSensorPlugin:: |
public | function |
Runs the sensor, updating $sensor_result. Overrides DatabaseAggregatorSensorPlugin:: |
|
ImageMissingStyleSensorPlugin:: |
public | function | Get the aggregated table verbose output. | |
ImageMissingStyleSensorPlugin:: |
public | function |
Adds unaggregated verbose output to the render array $output. Overrides WatchdogAggregatorSensorPlugin:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
SensorPluginBase:: |
protected | property | The plugin implementation definition. | |
SensorPluginBase:: |
protected | property | The plugin_id. | |
SensorPluginBase:: |
protected | property | Current sensor config object. | |
SensorPluginBase:: |
protected | property | ||
SensorPluginBase:: |
public | function |
Service setter. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public static | function |
Creates an instance of the sensor with config. Overrides SensorPluginInterface:: |
7 |
SensorPluginBase:: |
public | function |
Configurable value type. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
SensorPluginBase:: |
public | function |
Gets sensor name (not the label). Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
@todo: Replace with injection Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
public | function |
Determines if sensor is enabled. Overrides SensorPluginInterface:: |
|
SensorPluginBase:: |
function | Instantiates a sensor object. | 8 | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WatchdogAggregatorSensorPlugin:: |
protected | property |
Allows plugins to control if the table can be configured. Overrides DatabaseAggregatorSensorPlugin:: |
|
WatchdogAggregatorSensorPlugin:: |
protected | property |
Allows plugins to control if a timestamp field can be configured. Overrides DatabaseAggregatorSensorPluginBase:: |
|
WatchdogAggregatorSensorPlugin:: |
public | function |
Default configuration for a sensor. Overrides DatabaseAggregatorSensorPlugin:: |
|
WatchdogAggregatorSensorPlugin:: |
public | function |
Adds history verbose output to the render array $output. Overrides DatabaseAggregatorSensorPlugin:: |