Issue #1982954 by mdrummond, cbiggins, disasm, googletorp, dawehner, andypost, sidharthap, Xano: Convert dblog_top() to a controller.
parent
2e764efb55
commit
7acc578c9d
|
@ -5,75 +5,6 @@
|
||||||
* Administrative page callbacks for the Database Logging module.
|
* Administrative page callbacks for the Database Logging module.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* Page callback: 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.
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
* Type of database log events to display (e.g., 'search').
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
* A build array in the format expected by drupal_render().
|
|
||||||
*
|
|
||||||
* @see dblog_menu()
|
|
||||||
*
|
|
||||||
* @deprecated Use \Drupal\dblog\Controller\DblogController::pageNotFound(),
|
|
||||||
* \Drupal\dblog\Controller\DblogController::accessDenied(), or
|
|
||||||
* \Drupal\dblog\Controller\DblogController::search()
|
|
||||||
*/
|
|
||||||
function dblog_top($type) {
|
|
||||||
|
|
||||||
$header = array(
|
|
||||||
array('data' => t('Count'), 'field' => 'count', 'sort' => 'desc'),
|
|
||||||
array('data' => t('Message'), 'field' => 'message')
|
|
||||||
);
|
|
||||||
$count_query = db_select('watchdog');
|
|
||||||
$count_query->addExpression('COUNT(DISTINCT(message))');
|
|
||||||
$count_query->condition('type', $type);
|
|
||||||
|
|
||||||
$query = db_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) {
|
|
||||||
// Check for required properties.
|
|
||||||
if (isset($dblog->message) && isset($dblog->variables)) {
|
|
||||||
// Messages without variables or user specified text.
|
|
||||||
if ($dblog->variables === 'N;') {
|
|
||||||
$message = $dblog->message;
|
|
||||||
}
|
|
||||||
// Message to translate with injected variables.
|
|
||||||
else {
|
|
||||||
$message = t($dblog->message, unserialize($dblog->variables));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$rows[] = array($dblog->count, $message);
|
|
||||||
}
|
|
||||||
|
|
||||||
$build['dblog_top_table'] = array(
|
|
||||||
'#theme' => 'table',
|
|
||||||
'#header' => $header,
|
|
||||||
'#rows' => $rows,
|
|
||||||
'#empty' => t('No log messages available.'),
|
|
||||||
);
|
|
||||||
$build['dblog_top_pager'] = array('#theme' => 'pager');
|
|
||||||
|
|
||||||
return $build;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a list of database log administration filters that can be applied.
|
* Creates a list of database log administration filters that can be applied.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,7 +18,8 @@ dblog.page_not_found:
|
||||||
path: '/admin/reports/page-not-found'
|
path: '/admin/reports/page-not-found'
|
||||||
defaults:
|
defaults:
|
||||||
_title: "Top 'page not found' errors"
|
_title: "Top 'page not found' errors"
|
||||||
_content: '\Drupal\dblog\Controller\DbLogController::pageNotFound'
|
_content: '\Drupal\dblog\Controller\DbLogController::topLogMessages'
|
||||||
|
type: 'page not found'
|
||||||
requirements:
|
requirements:
|
||||||
_permission: 'access site reports'
|
_permission: 'access site reports'
|
||||||
|
|
||||||
|
@ -26,15 +27,17 @@ dblog.access_denied:
|
||||||
path: '/admin/reports/access-denied'
|
path: '/admin/reports/access-denied'
|
||||||
defaults:
|
defaults:
|
||||||
_title: "Top 'access denied' errors"
|
_title: "Top 'access denied' errors"
|
||||||
_content: '\Drupal\dblog\Controller\DbLogController::accessDenied'
|
_content: '\Drupal\dblog\Controller\DbLogController::topLogMessages'
|
||||||
|
type: 'access denied'
|
||||||
requirements:
|
requirements:
|
||||||
_permission: 'access site reports'
|
_permission: 'access site reports'
|
||||||
|
|
||||||
dblog.search:
|
dblog.search:
|
||||||
path: '/admin/reports/search'
|
path: '/admin/reports/search'
|
||||||
defaults:
|
defaults:
|
||||||
_content: '\Drupal\dblog\Controller\DbLogController::search'
|
_content: '\Drupal\dblog\Controller\DbLogController::topLogMessages'
|
||||||
_title: 'Top search phrases'
|
_title: 'Top search phrases'
|
||||||
|
type: 'search'
|
||||||
requirements:
|
requirements:
|
||||||
_module_dependencies: 'search'
|
_module_dependencies: 'search'
|
||||||
_permission: 'access site reports'
|
_permission: 'access site reports'
|
||||||
|
|
|
@ -129,27 +129,27 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
// Icon column.
|
// Icon column.
|
||||||
'',
|
'',
|
||||||
array(
|
array(
|
||||||
'data' => t('Type'),
|
'data' => $this->t('Type'),
|
||||||
'field' => 'w.type',
|
'field' => 'w.type',
|
||||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
|
'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
|
||||||
array(
|
array(
|
||||||
'data' => t('Date'),
|
'data' => $this->t('Date'),
|
||||||
'field' => 'w.wid',
|
'field' => 'w.wid',
|
||||||
'sort' => 'desc',
|
'sort' => 'desc',
|
||||||
'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
||||||
t('Message'),
|
$this->t('Message'),
|
||||||
array(
|
array(
|
||||||
'data' => t('User'),
|
'data' => $this->t('User'),
|
||||||
'field' => 'u.name',
|
'field' => 'u.name',
|
||||||
'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
|
'class' => array(RESPONSIVE_PRIORITY_MEDIUM)),
|
||||||
array(
|
array(
|
||||||
'data' => t('Operations'),
|
'data' => $this->t('Operations'),
|
||||||
'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
||||||
);
|
);
|
||||||
|
|
||||||
$query = $this->database->select('watchdog', 'w')
|
$query = $this->database->select('watchdog', 'w')
|
||||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
->extend('\Drupal\Core\Database\Query\PagerSelectExtender')
|
||||||
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
->extend('\Drupal\Core\Database\Query\TableSortExtender');
|
||||||
$query->fields('w', array(
|
$query->fields('w', array(
|
||||||
'wid',
|
'wid',
|
||||||
'uid',
|
'uid',
|
||||||
|
@ -178,7 +178,7 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
}
|
}
|
||||||
// Message to translate with injected variables.
|
// Message to translate with injected variables.
|
||||||
else {
|
else {
|
||||||
$message = t($dblog->message, unserialize($dblog->variables));
|
$message = $this->t($dblog->message, unserialize($dblog->variables));
|
||||||
}
|
}
|
||||||
if (isset($dblog->wid)) {
|
if (isset($dblog->wid)) {
|
||||||
// Truncate link_text to 56 chars of message.
|
// Truncate link_text to 56 chars of message.
|
||||||
|
@ -194,7 +194,7 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
'data' => array(
|
'data' => array(
|
||||||
// Cells.
|
// Cells.
|
||||||
array('class' => array('icon')),
|
array('class' => array('icon')),
|
||||||
t($dblog->type),
|
$this->t($dblog->type),
|
||||||
$this->date->format($dblog->timestamp, 'short'),
|
$this->date->format($dblog->timestamp, 'short'),
|
||||||
$message,
|
$message,
|
||||||
array('data' => $username),
|
array('data' => $username),
|
||||||
|
@ -210,7 +210,7 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
'#header' => $header,
|
'#header' => $header,
|
||||||
'#rows' => $rows,
|
'#rows' => $rows,
|
||||||
'#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')),
|
'#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')),
|
||||||
'#empty' => t('No log messages available.'),
|
'#empty' => $this->t('No log messages available.'),
|
||||||
);
|
);
|
||||||
$build['dblog_pager'] = array('#theme' => 'pager');
|
$build['dblog_pager'] = array('#theme' => 'pager');
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
// Check for required properties.
|
// Check for required properties.
|
||||||
if (isset($dblog->message) && isset($dblog->variables)) {
|
if (isset($dblog->message) && isset($dblog->variables)) {
|
||||||
// Inject variables into the message if required.
|
// Inject variables into the message if required.
|
||||||
$message = $dblog->variables === 'N;' ? $dblog->message : t($dblog->message, unserialize($dblog->variables));
|
$message = $dblog->variables === 'N;' ? $dblog->message : $this->t($dblog->message, unserialize($dblog->variables));
|
||||||
}
|
}
|
||||||
$username = array(
|
$username = array(
|
||||||
'#theme' => 'username',
|
'#theme' => 'username',
|
||||||
|
@ -244,39 +244,39 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
);
|
);
|
||||||
$rows = array(
|
$rows = array(
|
||||||
array(
|
array(
|
||||||
array('data' => t('Type'), 'header' => TRUE),
|
array('data' => $this->t('Type'), 'header' => TRUE),
|
||||||
t($dblog->type),
|
$this->t($dblog->type),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Date'), 'header' => TRUE),
|
array('data' => $this->t('Date'), 'header' => TRUE),
|
||||||
$this->date->format($dblog->timestamp, 'long'),
|
$this->date->format($dblog->timestamp, 'long'),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('User'), 'header' => TRUE),
|
array('data' => $this->t('User'), 'header' => TRUE),
|
||||||
array('data' => $username),
|
array('data' => $username),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Location'), 'header' => TRUE),
|
array('data' => $this->t('Location'), 'header' => TRUE),
|
||||||
l($dblog->location, $dblog->location),
|
l($dblog->location, $dblog->location),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Referrer'), 'header' => TRUE),
|
array('data' => $this->t('Referrer'), 'header' => TRUE),
|
||||||
l($dblog->referer, $dblog->referer),
|
l($dblog->referer, $dblog->referer),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Message'), 'header' => TRUE),
|
array('data' => $this->t('Message'), 'header' => TRUE),
|
||||||
$message,
|
$message,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Severity'), 'header' => TRUE),
|
array('data' => $this->t('Severity'), 'header' => TRUE),
|
||||||
$severity[$dblog->severity],
|
$severity[$dblog->severity],
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Hostname'), 'header' => TRUE),
|
array('data' => $this->t('Hostname'), 'header' => TRUE),
|
||||||
String::checkPlain($dblog->hostname),
|
String::checkPlain($dblog->hostname),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
array('data' => t('Operations'), 'header' => TRUE),
|
array('data' => $this->t('Operations'), 'header' => TRUE),
|
||||||
$dblog->link,
|
$dblog->link,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -326,27 +326,68 @@ class DbLogController extends ControllerBase implements ContainerInjectionInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Remove dblog_top().
|
* 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.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* Type of database log events to display (e.g., 'search').
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* A build array in the format expected by drupal_render().
|
||||||
*/
|
*/
|
||||||
public function pageNotFound() {
|
public function topLogMessages($type) {
|
||||||
module_load_include('admin.inc', 'dblog');
|
$header = array(
|
||||||
return dblog_top('page not found');
|
array('data' => $this->t('Count'), 'field' => 'count', 'sort' => 'desc'),
|
||||||
}
|
array('data' => $this->t('Message'), 'field' => 'message'),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
$count_query = $this->database->select('watchdog');
|
||||||
* @todo Remove dblog_top().
|
$count_query->addExpression('COUNT(DISTINCT(message))');
|
||||||
*/
|
$count_query->condition('type', $type);
|
||||||
public function accessDenied() {
|
|
||||||
module_load_include('admin.inc', 'dblog');
|
|
||||||
return dblog_top('access denied');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$query = $this->database->select('watchdog', 'w')
|
||||||
* @todo Remove dblog_top().
|
->extend('\Drupal\Core\Database\Query\PagerSelectExtender')
|
||||||
*/
|
->extend('\Drupal\Core\Database\Query\TableSortExtender');
|
||||||
public function search() {
|
$query->addExpression('COUNT(wid)', 'count');
|
||||||
module_load_include('admin.inc', 'dblog');
|
$query = $query
|
||||||
return dblog_top('search');
|
->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) {
|
||||||
|
// Check for required properties.
|
||||||
|
if (isset($dblog->message) && isset($dblog->variables)) {
|
||||||
|
// Messages without variables or user specified text.
|
||||||
|
if ($dblog->variables === 'N;') {
|
||||||
|
$message = $dblog->message;
|
||||||
|
}
|
||||||
|
// Message to translate with injected variables.
|
||||||
|
else {
|
||||||
|
$message = $this->t($dblog->message, unserialize($dblog->variables));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$rows[] = array($dblog->count, $message);
|
||||||
|
}
|
||||||
|
|
||||||
|
$build['dblog_top_table'] = array(
|
||||||
|
'#theme' => 'table',
|
||||||
|
'#header' => $header,
|
||||||
|
'#rows' => $rows,
|
||||||
|
'#empty' => $this->t('No log messages available.'),
|
||||||
|
);
|
||||||
|
$build['dblog_top_pager'] = array('#theme' => 'pager');
|
||||||
|
|
||||||
|
return $build;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue