diff --git a/core/modules/dblog/dblog.admin.inc b/core/modules/dblog/dblog.admin.inc index d67712a..f194878 100644 --- a/core/modules/dblog/dblog.admin.inc +++ b/core/modules/dblog/dblog.admin.inc @@ -59,7 +59,7 @@ function dblog_top($type) { $rows[] = array($dblog->count, $message); } - $build['dblog_top_table'] = array( + $build['dblog_top_table'] = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 202cfcf..608429a 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -63,10 +63,7 @@ function dblog_menu() { ); $items['admin/reports/event/%'] = array( 'title' => 'Details', - 'page callback' => 'dblog_event', - 'page arguments' => array(3), - 'access arguments' => array('access site reports'), - 'file' => 'dblog.admin.inc', + 'route_name' => 'dblog_event', ); if (module_exists('search')) { diff --git a/core/modules/dblog/dblog.routing.yml b/core/modules/dblog/dblog.routing.yml index 310d798..388348d 100644 --- a/core/modules/dblog/dblog.routing.yml +++ b/core/modules/dblog/dblog.routing.yml @@ -4,3 +4,10 @@ dblog_overview: _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' diff --git a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php index 3119a1b..74f2122 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,6 +194,74 @@ public function overview() { } /** + * 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(); + * + */ + 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 : 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. * * @return array diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/DbLogTest.php index 5e3f663..87976b4 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 @@ private function verifyReports($response = 200) { } // 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');