Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/dblog/dblog.install @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Install, update and uninstall functions for the dblog module. | |
6 */ | |
7 | |
8 /** | |
9 * Implements hook_schema(). | |
10 */ | |
11 function dblog_schema() { | |
12 $schema['watchdog'] = [ | |
13 'description' => 'Table that contains logs of all system events.', | |
14 'fields' => [ | |
15 'wid' => [ | |
16 'type' => 'serial', | |
17 'not null' => TRUE, | |
18 'description' => 'Primary Key: Unique watchdog event ID.', | |
19 ], | |
20 'uid' => [ | |
21 'type' => 'int', | |
22 'unsigned' => TRUE, | |
23 'not null' => TRUE, | |
24 'default' => 0, | |
25 'description' => 'The {users}.uid of the user who triggered the event.', | |
26 ], | |
27 'type' => [ | |
28 'type' => 'varchar_ascii', | |
29 'length' => 64, | |
30 'not null' => TRUE, | |
31 'default' => '', | |
32 'description' => 'Type of log message, for example "user" or "page not found."', | |
33 ], | |
34 'message' => [ | |
35 'type' => 'text', | |
36 'not null' => TRUE, | |
37 'size' => 'big', | |
38 'description' => 'Text of log message to be passed into the t() function.', | |
39 ], | |
40 'variables' => [ | |
41 'type' => 'blob', | |
42 'not null' => TRUE, | |
43 'size' => 'big', | |
44 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.', | |
45 ], | |
46 'severity' => [ | |
47 'type' => 'int', | |
48 'unsigned' => TRUE, | |
49 'not null' => TRUE, | |
50 'default' => 0, | |
51 'size' => 'tiny', | |
52 'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)', | |
53 ], | |
54 'link' => [ | |
55 'type' => 'text', | |
56 'not null' => FALSE, | |
57 'description' => 'Link to view the result of the event.', | |
58 ], | |
59 'location' => [ | |
60 'type' => 'text', | |
61 'not null' => TRUE, | |
62 'description' => 'URL of the origin of the event.', | |
63 ], | |
64 'referer' => [ | |
65 'type' => 'text', | |
66 'not null' => FALSE, | |
67 'description' => 'URL of referring page.', | |
68 ], | |
69 'hostname' => [ | |
70 'type' => 'varchar_ascii', | |
71 'length' => 128, | |
72 'not null' => TRUE, | |
73 'default' => '', | |
74 'description' => 'Hostname of the user who triggered the event.', | |
75 ], | |
76 'timestamp' => [ | |
77 'type' => 'int', | |
78 'not null' => TRUE, | |
79 'default' => 0, | |
80 'description' => 'Unix timestamp of when event occurred.', | |
81 ], | |
82 ], | |
83 'primary key' => ['wid'], | |
84 'indexes' => [ | |
85 'type' => ['type'], | |
86 'uid' => ['uid'], | |
87 'severity' => ['severity'], | |
88 ], | |
89 ]; | |
90 | |
91 return $schema; | |
92 } | |
93 | |
94 /** | |
95 * Use standard plugin for wid and uid fields. Use dblog_types for type filter. | |
96 */ | |
97 function dblog_update_8400() { | |
98 $config_factory = \Drupal::configFactory(); | |
99 | |
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') { | |
103 continue; | |
104 } | |
105 | |
106 $save = FALSE; | |
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'])) { | |
117 | |
118 $save = TRUE; | |
119 $new_value = $field; | |
120 $new_value['plugin_id'] = 'standard'; | |
121 | |
122 // Delete all the attributes related to numeric fields. | |
123 unset( | |
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'], | |
131 $new_value['suffix'] | |
132 ); | |
133 $view->set("display.$display_name.display_options.fields.$field_name", $new_value); | |
134 } | |
135 } | |
136 } | |
137 | |
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') { | |
145 | |
146 $save = TRUE; | |
147 $filter['plugin_id'] = 'dblog_types'; | |
148 $view->set("display.$display_name.display_options.filters.$filter_name", $filter); | |
149 } | |
150 } | |
151 } | |
152 } | |
153 | |
154 if ($save) { | |
155 $view->save(); | |
156 } | |
157 } | |
158 } |