5 * Install, update and uninstall functions for the dblog module.
9 * Implements hook_schema().
11 function dblog_schema() {
12 $schema['watchdog'] = [
13 'description' => 'Table that contains logs of all system events.',
18 'description' => 'Primary Key: Unique watchdog event ID.',
25 'description' => 'The {users}.uid of the user who triggered the event.',
28 'type' => 'varchar_ascii',
32 'description' => 'Type of log message, for example "user" or "page not found."',
38 'description' => 'Text of log message to be passed into the t() function.',
44 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
52 'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
57 'description' => 'Link to view the result of the event.',
62 'description' => 'URL of the origin of the event.',
67 'description' => 'URL of referring page.',
70 'type' => 'varchar_ascii',
74 'description' => 'Hostname of the user who triggered the event.',
80 'description' => 'Unix timestamp of when event occurred.',
83 'primary key' => ['wid'],
87 'severity' => ['severity'],
95 * Use standard plugin for wid and uid fields. Use dblog_types for type filter.
97 function dblog_update_8400() {
98 $config_factory = \Drupal::configFactory();
100 foreach ($config_factory->listAll('views.view.') as $view_config_name) {
101 $view = $config_factory->getEditable($view_config_name);
102 if ($view->get('base_table') != 'watchdog') {
107 foreach ($view->get('display') as $display_name => $display) {
108 // Iterate through all the fields of watchdog views based tables.
109 if (isset($display['display_options']['fields'])) {
110 foreach ($display['display_options']['fields'] as $field_name => $field) {
111 // We are only interested in wid and uid fields from the watchdog
112 // table that still use the numeric id.
113 if (isset($field['table']) &&
114 $field['table'] === 'watchdog' &&
115 $field['plugin_id'] == 'numeric' &&
116 in_array($field['field'], ['wid', 'uid'])) {
120 $new_value['plugin_id'] = 'standard';
122 // Delete all the attributes related to numeric fields.
124 $new_value['set_precision'],
125 $new_value['precision'],
126 $new_value['decimal'],
127 $new_value['separator'],
128 $new_value['format_plural'],
129 $new_value['format_plural_string'],
130 $new_value['prefix'],
133 $view->set("display.$display_name.display_options.fields.$field_name", $new_value);
138 // Iterate all filters looking for type filters to update.
139 if (isset($display['display_options']['filters'])) {
140 foreach ($display['display_options']['filters'] as $filter_name => $filter) {
141 if (isset($filter['table']) &&
142 $filter['table'] === 'watchdog' &&
143 $filter['plugin_id'] == 'in_operator' &&
144 $filter['field'] == 'type') {
147 $filter['plugin_id'] = 'dblog_types';
148 $view->set("display.$display_name.display_options.filters.$filter_name", $filter);