diff --git a/core/modules/dblog/dblog.routing.yml b/core/modules/dblog/dblog.routing.yml index 310d798..4ff9a4f 100644 --- a/core/modules/dblog/dblog.routing.yml +++ b/core/modules/dblog/dblog.routing.yml @@ -4,3 +4,9 @@ _content: '\Drupal\dblog\Controller\DbLogController::overview' requirements: _permission: 'access site reports' +dblog_event: + pattern: 'admin/reports/event/{event_id}' + defaults: + _content: '\Drupal\dblog\Controller\DbLogController::eventDetails' + requirements: + _permission: 'access site reports' \ No newline at end of file diff --git a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php index f416c41..b5ecbe0 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php +++ b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php @@ -8,6 +8,7 @@ namespace Drupal\dblog\Controller; use Drupal\Component\Utility\Unicode; +use Drupal\Component\Utility\String; use Drupal\Core\Database\Connection; use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -193,7 +194,76 @@ return $build; } + + /** + * Displays details about a specific database log message. + * + * @param int $event_id + * Unique ID of the database log message. + * + * @return array + * If the ID is located in the Database Logging table, a build array in the + * format expected by drupal_render(); + * + * @see dblog_menu() + */ + 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 : t($dblog->message, unserialize($dblog->variables)); + } + $rows = array( + array( + array('data' => t('Type'), 'header' => TRUE), + t($dblog->type), + ), + array( + array('data' => t('Date'), 'header' => TRUE), + format_date($dblog->timestamp, 'long'), + ), + array( + array('data' => t('User'), 'header' => TRUE), + theme('username', array('account' => $dblog)), + ), + array( + array('data' => t('Location'), 'header' => TRUE), + l($dblog->location, $dblog->location), + ), + array( + array('data' => t('Referrer'), 'header' => TRUE), + l($dblog->referer, $dblog->referer), + ), + array( + array('data' => t('Message'), 'header' => TRUE), + $message, + ), + array( + array('data' => t('Severity'), 'header' => TRUE), + $severity[$dblog->severity], + ), + array( + array('data' => t('Hostname'), 'header' => TRUE), + String::checkPlain($dblog->hostname), + ), + array( + array('data' => t('Operations'), 'header' => TRUE), + $dblog->link, + ), + ); + $build['dblog_table'] = array( + '#theme' => 'table', + '#rows' => $rows, + '#attributes' => array('class' => array('dblog-event')), + ); + } + return $build; + } + /** * Builds a query for database log administration filters based on session. * diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php index e619fff..6c80dee 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php @@ -187,7 +187,8 @@ } // View the database log event page. - $this->drupalGet('admin/reports/event/1'); + $wid = db_query('SELECT MIN(wid) FROM {watchdog}')->fetchField(); + $this->drupalGet('admin/reports/event/' . $wid); $this->assertResponse($response); if ($response == 200) { $this->assertText(t('Details'), 'DBLog event node was displayed');