diff --git a/core/modules/dblog/dblog.admin.inc b/core/modules/dblog/dblog.admin.inc index d3cc328..920577e 100644 --- a/core/modules/dblog/dblog.admin.inc +++ b/core/modules/dblog/dblog.admin.inc @@ -59,7 +59,7 @@ $rows[] = array($dblog->count, $message); } - $build['dblog_top_table'] = array( + $build['dblog_top_table'] = array( '#theme' => 'table', '#header' => $header, '#rows' => $rows, @@ -68,87 +68,6 @@ $build['dblog_top_pager'] = array('#theme' => 'pager'); return $build; -} - -/** - * Page callback: Displays details about a specific database log message. - * - * @param int $id - * Unique ID of the database log message. - * - * @return array|string - * If the ID is located in the Database Logging table, a build array in the - * format expected by drupal_render(); otherwise, an empty string. - * - * @see dblog_menu() - */ -function dblog_event($id) { - $severity = watchdog_severity_levels(); - $result = db_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' => $id))->fetchObject(); - if ($dblog = $result) { - // 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)); - } - } - $username = array( - '#theme' => 'username', - '#account' => $dblog, - ); - $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), - drupal_render($username), - ), - 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), - check_plain($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; - } - else { - return ''; - } } /** 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 @@ ); $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 @@ _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 f416c41..3e14c1b 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; @@ -195,6 +196,74 @@ } /** + * 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 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');