diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 63e2b8f..56ca3af 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -134,7 +134,7 @@ function _dblog_get_message_types() { $types[] = $object->type; } - return $types; + return drupal_map_assoc($types); } /** diff --git a/core/modules/dblog/dblog.views.inc b/core/modules/dblog/dblog.views.inc new file mode 100644 index 0000000..2b48e3e --- /dev/null +++ b/core/modules/dblog/dblog.views.inc @@ -0,0 +1,223 @@ + 'wid', + 'title' => t('Watchdog events'), + 'help' => t('Contains a list of log entries.'), + ); + + $data['watchdog']['wid'] = array( + 'title' => t('WID'), + 'help' => t('Unique watchdog event ID.'), + 'field' => array( + 'id' => 'numeric', + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'sort' => array( + 'id' => 'standard', + ), + 'search' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['uid'] = array( + 'title' => t('UID'), + 'help' => t('The user ID of the user on which the log entry was written..'), + 'field' => array( + 'id' => 'numeric', + ), + 'filter' => array( + 'id' => 'numeric', + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'search' => array( + 'id' => 'standard', + ), + 'relationship' => array( + 'title' => t('User'), + 'help' => t('The user on which the log entry as written.'), + 'base' => 'users', + 'base field' => 'uid', + 'id' => 'standard', + ), + ); + + $data['watchdog']['type'] = array( + 'title' => t('Type'), + 'help' => t('The of the log entry, for example "user" or "page not found.".'), + 'field' => array( + 'id' => 'standard', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'in_operator', + 'options callback' => '_dblog_get_message_types', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['message'] = array( + 'title' => t('Message'), + 'help' => t('The actual message of the log entry.'), + 'field' => array( + 'id' => 'dblog_message', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['variables'] = array( + 'title' => t('Variables'), + 'help' => t('The variables of the log entry in a serialized format.'), + 'field' => array( + 'id' => 'serialized', + 'click sortable' => FALSE, + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['severity'] = array( + 'title' => t('Severity level'), + 'help' => t('The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).'), + 'field' => array( + 'id' => 'machine_name', + 'options callback' => 'Drupal\dblog\Controller\DbLogController::getLogLevelClassMap', + ), + 'filter' => array( + 'id' => 'in_operator', + 'options callback' => 'Drupal\dblog\Controller\DbLogController::getLogLevelClassMap', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['link'] = array( + 'title' => t('Operations'), + 'help' => t('Operation links for the event.'), + 'field' => array( + 'id' => 'dblog_operations', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['location'] = array( + 'title' => t('Location'), + 'help' => t('URL of the origin of the event.'), + 'field' => array( + 'id' => 'standard', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['referer'] = array( + 'title' => t('Referer'), + 'help' => t('URL of the previous page.'), + 'field' => array( + 'id' => 'standard', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['hostname'] = array( + 'title' => t('Hostname'), + 'help' => t('Hostname of the user who triggered the event.'), + 'field' => array( + 'id' => 'standard', + ), + 'argument' => array( + 'id' => 'string', + ), + 'filter' => array( + 'id' => 'string', + ), + 'sort' => array( + 'id' => 'standard', + ), + ); + + $data['watchdog']['timestamp'] = array( + 'title' => t('Timestamp'), + 'help' => t('Date when the event occurred.'), + 'field' => array( + 'id' => 'date', + ), + 'argument' => array( + 'id' => 'date', + ), + 'filter' => array( + 'id' => 'date', + ), + 'sort' => array( + 'id' => 'date', + ), + ); + + return $data; +} diff --git a/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogMessage.php b/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogMessage.php new file mode 100644 index 0000000..953fee4 --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogMessage.php @@ -0,0 +1,75 @@ +options['replace_variables']) { + $this->additional_fields['variables'] = 'variables'; + } + } + + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::defineOptions(). + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['replace_variables'] = array('default' => TRUE, 'bool' => TRUE); + + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm(). + */ + public function buildOptionsForm(&$form, &$form_state) { + parent::buildOptionsForm($form, $form_state); + + $form['replace_variables'] = array( + '#title' => t('Replace variables'), + '#type' => 'checkbox', + '#default_value' => $this->options['replace_variables'], + ); + } + + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::FieldPluginBase(). + */ + public function render($values) { + $value = $this->get_value($values); + + if ($this->options['replace_variables']) { + $variables = unserialize($this->get_value($values, 'variables')); + return format_string($value, (array) $variables); + } + else { + return $this->sanitizeValue($value); + } + } + +} diff --git a/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogOperations.php b/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogOperations.php new file mode 100644 index 0000000..a4c80ce --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/Plugin/views/field/DblogOperations.php @@ -0,0 +1,39 @@ +get_value($values); + return $this->sanitizeValue($value, 'xss_admin'); + } + +} diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php new file mode 100644 index 0000000..3261178 --- /dev/null +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/Views/ViewsIntegrationTest.php @@ -0,0 +1,105 @@ + 'Dblog Integration', + 'description' => 'Tests the views integration of dblog module.', + 'group' => 'Views module integration' + ); + } + + protected function setUp() { + parent::setUp(); + + $this->enableModules(array('system', 'dblog')); + $this->installSchema('dblog', array('watchdog')); + + ViewTestData::importTestViews(get_class($this), array('dblog_test_views')); + } + + /** + * Tests the integration. + */ + public function testIntegration() { + + // Remove the watchdog entries added by the potential batch process. + $this->container->get('database')->truncate('watchdog')->execute(); + + $entries = array(); + // Setup a watchdog entry without tokens. + $entries[] = array( + 'message' => $this->randomName(), + 'variables' => array(), + 'link' => l('Link', 'node/1'), + ); + // Setup a watchdog entry with one token. + $entries[] = array( + 'message' => '@token1', + 'variables' => array('@token1' => $this->randomName()), + 'link' => l('Link', 'node/2'), + ); + // Setup a watchdog entry with two tokens. + $entries[] = array( + 'message' => '@token1 !token2', + 'variables' => array('@token1' => $this->randomName(), '!token2' => $this->randomName()), + // Setup a link with a tag which is filtered by filter_xss_admin. + 'link' => l('Link', 'node/2', array('html' => TRUE)), + ); + foreach ($entries as $entry) { + $entry += array( + 'type' => 'test-views', + 'severity' => WATCHDOG_NOTICE, + ); + watchdog($entry['type'], $entry['message'], $entry['variables'], $entry['severity'], $entry['link']); + } + + $view = views_get_view('test_dblog'); + $this->executeView($view); + $view->initStyle(); + + foreach ($entries as $index => $entry) { + $this->assertEqual($view->style_plugin->get_field($index, 'message'), format_string($entry['message'], $entry['variables'])); + $this->assertEqual($view->style_plugin->get_field($index, 'link'), filter_xss_admin($entry['link'])); + } + + // Disable replacing variables and check that the tokens aren't replaced. + $view->destroy(); + $view->initHandlers(); + $this->executeView($view); + $view->initStyle(); + $view->field['message']->options['replace_variables'] = FALSE; + foreach ($entries as $index => $entry) { + $this->assertEqual($view->style_plugin->get_field($index, 'message'), $entry['message']); + } + } + +} diff --git a/core/modules/dblog/tests/modules/dblog_test_views/dblog_test_views.info b/core/modules/dblog/tests/modules/dblog_test_views/dblog_test_views.info new file mode 100644 index 0000000..56fb11f --- /dev/null +++ b/core/modules/dblog/tests/modules/dblog_test_views/dblog_test_views.info @@ -0,0 +1,8 @@ +name = Dblog test views +description = Provides default views for views dblog tests. +package = Testing +version = VERSION +core = 8.x +dependencies[] = dblog +dependencies[] = views +hidden = TRUE diff --git a/core/modules/dblog/tests/modules/dblog_test_views/dblog_test_views.module b/core/modules/dblog/tests/modules/dblog_test_views/dblog_test_views.module new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/core/modules/dblog/tests/modules/dblog_test_views/dblog_test_views.module @@ -0,0 +1 @@ +