You are here

public function DbLogController::topLogMessages in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/dblog/src/Controller/DbLogController.php \Drupal\dblog\Controller\DbLogController::topLogMessages()

Shows the most frequent log messages of a given event type.

Messages are not truncated on this page because events detailed herein do not have links to a detailed view.

Use one of the above *Report() methods.

Parameters

string $type: Type of database log events to display (e.g., 'search').

Return value

array A build array in the format expected by drupal_render().

1 string reference to 'DbLogController::topLogMessages'
dblog.routing.yml in core/modules/dblog/dblog.routing.yml
core/modules/dblog/dblog.routing.yml

File

core/modules/dblog/src/Controller/DbLogController.php, line 382
Contains \Drupal\dblog\Controller\DbLogController.

Class

DbLogController
Returns responses for dblog routes.

Namespace

Drupal\dblog\Controller

Code

public function topLogMessages($type) {
  $header = array(
    array(
      'data' => $this
        ->t('Count'),
      'field' => 'count',
      'sort' => 'desc',
    ),
    array(
      'data' => $this
        ->t('Message'),
      'field' => 'message',
    ),
  );
  $count_query = $this->database
    ->select('watchdog');
  $count_query
    ->addExpression('COUNT(DISTINCT(message))');
  $count_query
    ->condition('type', $type);
  $query = $this->database
    ->select('watchdog', 'w')
    ->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->addExpression('COUNT(wid)', 'count');
  $query = $query
    ->fields('w', array(
    'message',
    'variables',
  ))
    ->condition('w.type', $type)
    ->groupBy('message')
    ->groupBy('variables')
    ->limit(30)
    ->orderByHeader($header);
  $query
    ->setCountQuery($count_query);
  $result = $query
    ->execute();
  $rows = array();
  foreach ($result as $dblog) {
    if ($message = $this
      ->formatMessage($dblog)) {
      $rows[] = array(
        $dblog->count,
        $message,
      );
    }
  }
  $build['dblog_top_table'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No log messages available.'),
    '#attached' => array(
      'library' => array(
        'dblog/drupal.dblog',
      ),
    ),
  );
  $build['dblog_top_pager'] = array(
    '#type' => 'pager',
  );
  return $build;
}