diff --git a/core/modules/dblog/dblog.admin.inc b/core/modules/dblog/dblog.admin.inc index d67712a..ec0e5e9 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, @@ -71,120 +71,6 @@ function dblog_top($type) { } /** - * 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' => user_load($dblog->uid), - ); - $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 ''; - } -} - -/** - * Builds a query for database log administration filters based on session. - * - * @return array - * An associative array with keys 'where' and 'args'. - */ -function dblog_build_filter_query() { - if (empty($_SESSION['dblog_overview_filter'])) { - return; - } - - $filters = dblog_filters(); - - // Build query - $where = $args = array(); - foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) { - $filter_where = array(); - foreach ($filter as $value) { - $filter_where[] = $filters[$key]['where']; - $args[] = $value; - } - if (!empty($filter_where)) { - $where[] = '(' . implode(' OR ', $filter_where) . ')'; - } - } - $where = !empty($where) ? implode(' AND ', $where) : ''; - - return array( - 'where' => $where, - 'args' => $args, - ); -} - -/** * Creates a list of database log administration filters that can be applied. * * @return array 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..a010363 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php +++ b/core/modules/dblog/lib/Drupal/dblog/Controller/DbLogController.php @@ -8,9 +8,13 @@ namespace Drupal\dblog\Controller; use Drupal\Component\Utility\Unicode; +use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Xss; use Drupal\Core\Database\Connection; use Drupal\Core\Controller\ControllerInterface; +use Drupal\Core\Datetime\Date; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\user\UserStorageControllerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -33,12 +37,25 @@ class DbLogController implements ControllerInterface { protected $moduleHandler; /** + * The date service. + * + * @var \Drupal\Core\Datetime\Date + */ + protected $date; + /** + * @var \Drupal\user\UserStorageControllerInterface + */ + protected $userStorage; + + /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('database'), - $container->get('module_handler') + $container->get('module_handler'), + $container->get('date'), + $container->get('plugin.manager.entity')->getStorageController('user') ); } @@ -50,9 +67,11 @@ public static function create(ContainerInterface $container) { * @param ModuleHandlerInterface $module_handler * A module handler. */ - public function __construct(Connection $database, ModuleHandlerInterface $module_handler) { + public function __construct(Connection $database, ModuleHandlerInterface $module_handler, Date $date, UserStorageControllerInterface $user_storage) { $this->database = $database; $this->moduleHandler = $module_handler; + $this->date = $date; + $this->userStorage = $user_storage; } /** @@ -169,10 +188,10 @@ public function overview() { // Cells. array('class' => array('icon')), t($dblog->type), - format_date($dblog->timestamp, 'short'), + $this->date->format($dblog->timestamp, 'short'), $message, array('data' => $username), - filter_xss($dblog->link), + Xss::filter($dblog->link), ), // Attributes for table row. 'class' => array(drupal_html_class('dblog-' . $dblog->type), $classes[$dblog->severity]), @@ -193,6 +212,78 @@ 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)); + } + $username = array( + '#theme' => 'username', + '#account' => user_load($dblog->uid), + ); + $rows = array( + array( + array('data' => t('Type'), 'header' => TRUE), + t($dblog->type), + ), + array( + array('data' => t('Date'), 'header' => TRUE), + $this->date->format($dblog->timestamp, 'long'), + ), + array( + array('data' => t('User'), 'header' => TRUE), + array('data' => $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), + 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');