Commit 0fa25d56 authored by alexpott's avatar alexpott
Browse files

Issue #1956806 by amitgoyal, Cottser: Fixed DbLogController::overview() and...

Issue #1956806 by amitgoyal, Cottser: Fixed DbLogController::overview() and topLogMessages() logic and provide a formatMessage() method.
parent dd24d328
......@@ -169,21 +169,11 @@ public function overview() {
->execute();
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));
}
if (isset($dblog->wid)) {
// Truncate link_text to 56 chars of message.
$log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE);
$message = $this->l($log_text, 'dblog.event', array('event_id' => $dblog->wid), array('html' => TRUE));
}
$message = $this->formatMessage($dblog);
if ($message && isset($dblog->wid)) {
// Truncate link_text to 56 chars of message.
$log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE);
$message = $this->l($log_text, 'dblog.event', array('event_id' => $dblog->wid), array('html' => TRUE));
}
$username = array(
'#theme' => 'username',
......@@ -235,11 +225,7 @@ public function eventDetails($event_id) {
$build = array();
if ($dblog = $this->database->query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = :id', array(':id' => $event_id))->fetchObject()) {
$severity = watchdog_severity_levels();
// Check for required properties.
if (isset($dblog->message) && isset($dblog->variables)) {
// Inject variables into the message if required.
$message = $dblog->variables === 'N;' ? $dblog->message : $this->t($dblog->message, unserialize($dblog->variables));
}
$message = $this->formatMessage($dblog);
$username = array(
'#theme' => 'username',
'#account' => user_load($dblog->uid),
......@@ -330,6 +316,35 @@ protected function buildFilterQuery() {
);
}
/**
* Formats a database log message.
*
* @param stdClass $row
* The record from the watchdog table. The object properties are: wid, uid,
* severity, type, timestamp, message, variables, link, name.
*
* @return string|false
* The formatted log message or FALSE if the message or variables properties
* are not set.
*/
public function formatMessage($row) {
// Check for required properties.
if (isset($row->message) && isset($row->variables)) {
// Messages without variables or user specified text.
if ($row->variables === 'N;') {
$message = $row->message;
}
// Message to translate with injected variables.
else {
$message = $this->t($row->message, unserialize($row->variables));
}
}
else {
$message = FALSE;
}
return $message;
}
/**
* Shows the most frequent log messages of a given event type.
*
......@@ -370,18 +385,9 @@ public function topLogMessages($type) {
$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));
}
if ($message = $this->formatMessage($dblog)) {
$rows[] = array($dblog->count, $message);
}
$rows[] = array($dblog->count, $message);
}
$build['dblog_top_table'] = array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment