public function ContentLogController::topLogMessages in Content Synchronization 8
Same name and namespace in other branches
- 8.2 src/Controller/ContentLogController.php \Drupal\content_sync\Controller\ContentLogController::topLogMessages()
- 3.0.x src/Controller/ContentLogController.php \Drupal\content_sync\Controller\ContentLogController::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.
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().
File
- src/
Controller/ ContentLogController.php, line 378
Class
- ContentLogController
- Returns responses for content_sync routes.
Namespace
Drupal\content_sync\ControllerCode
public function topLogMessages($type) {
$header = [
[
'data' => $this
->t('Count'),
'field' => 'count',
'sort' => 'desc',
],
[
'data' => $this
->t('Message'),
'field' => 'message',
],
];
$count_query = $this->database
->select('cs_logs');
$count_query
->addExpression('COUNT(DISTINCT(message))');
$count_query
->condition('type', $type);
$query = $this->database
->select('cs_logs', 'w')
->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->addExpression('COUNT(csid)', 'count');
$query = $query
->fields('w', [
'message',
'variables',
])
->condition('w.type', $type)
->groupBy('message')
->groupBy('variables')
->limit(30)
->orderByHeader($header);
$query
->setCountQuery($count_query);
$result = $query
->execute();
$rows = [];
foreach ($result as $cs_log) {
if ($message = $this
->formatMessage($cs_log)) {
$rows[] = [
$cs_log->count,
$message,
];
}
}
$build['cs_log_top_table'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this
->t('No log messages available.'),
'#attached' => [
'library' => [
'cs_log/drupal.cslog',
],
],
];
$build['cs_log_top_pager'] = [
'#type' => 'pager',
];
return $build;
}