You are here

public function ImageMissingStyleSensorPlugin::verboseResultCounting in Monitoring 8

Get the aggregated table verbose output.

Parameters

array $output: The output array, at which we will add the aggregated table verbose output.

Return value

array Aggregated result table.

1 call to ImageMissingStyleSensorPlugin::verboseResultCounting()
ImageMissingStyleSensorPlugin::resultVerbose in src/Plugin/monitoring/SensorPlugin/ImageMissingStyleSensorPlugin.php
Provide additional info about sensor call.

File

src/Plugin/monitoring/SensorPlugin/ImageMissingStyleSensorPlugin.php, line 89
Contains \Drupal\monitoring\Plugin\monitoring\SensorPlugin\ImageMissingStyleSensorPlugin.

Class

ImageMissingStyleSensorPlugin
Monitors image derivate creation errors from dblog.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

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;
}