function LoggerController::watchdogTop in MongoDB 8
Page callback for "admin/reports/[access-denied|page-not-found]".
Parameters
string $type:
Return value
array
File
- src/
Logger/ LoggerController.php, line 328 - Controller service for the MongoDB Watchdog reports.
Class
Namespace
Drupal\mongodb\LoggerCode
function watchdogTop($type) {
$ret = array();
$type_param = array(
'%type' => $type,
);
$limit = 50;
// Safety net
$types = array(
'page not found',
'access denied',
);
if (!in_array($type, $types)) {
drupal_set_message(t('Unknown top report type: %type', $type_param), 'error');
watchdog('mongodb_watchdog', 'Unknown top report type: %type', $type_param, WATCHDOG_WARNING);
$ret = '';
return $ret;
}
// Find _id for the error type.
$templates = $this->logger
->templatesCollection();
$criteria = array(
'type' => $type,
);
$fields = array(
'_id',
);
$template = $templates
->findOne($criteria, $fields);
// findOne() will return NULL if no row is found
if (empty($template)) {
$ret['empty'] = array(
'#markup' => t('No "%type" message found', $type_param),
'#prefix' => '<div class="mongodb-watchdog-message">',
'#suffix' => '</div>',
);
$ret = drupal_render($ret);
return $ret;
}
// Find occurrences of error type.
$event_collection = $this->logger
->eventCollection($template['_id']);
$key = 'variables.@param';
$keys = array(
$key => 1,
);
$initial = array(
'count' => 0,
);
$reduce = new \MongoCode(file_get_contents(__DIR__ . '/top_reductor.js'));
$counts = $event_collection
->group($keys, $initial, $reduce);
if (!$counts['ok']) {
drupal_set_message(t('No "%type" occurrence found', $type_param), 'error');
return '';
}
$counts = $counts['retval'];
usort($counts, array(
$this,
'sortTop',
));
$counts = array_slice($counts, 0, $limit);
$header = array(
t('#'),
t('Paths'),
);
$rows = array();
foreach ($counts as $count) {
$rows[] = array(
$count['count'],
$count[$key],
);
}
$ret = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
return $ret;
}