annotate 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
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Install, update and uninstall functions for the dblog module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Implements hook_schema().
Chris@0 10 */
Chris@0 11 function dblog_schema() {
Chris@0 12 $schema['watchdog'] = [
Chris@0 13 'description' => 'Table that contains logs of all system events.',
Chris@0 14 'fields' => [
Chris@0 15 'wid' => [
Chris@0 16 'type' => 'serial',
Chris@0 17 'not null' => TRUE,
Chris@0 18 'description' => 'Primary Key: Unique watchdog event ID.',
Chris@0 19 ],
Chris@0 20 'uid' => [
Chris@0 21 'type' => 'int',
Chris@0 22 'unsigned' => TRUE,
Chris@0 23 'not null' => TRUE,
Chris@0 24 'default' => 0,
Chris@0 25 'description' => 'The {users}.uid of the user who triggered the event.',
Chris@0 26 ],
Chris@0 27 'type' => [
Chris@0 28 'type' => 'varchar_ascii',
Chris@0 29 'length' => 64,
Chris@0 30 'not null' => TRUE,
Chris@0 31 'default' => '',
Chris@0 32 'description' => 'Type of log message, for example "user" or "page not found."',
Chris@0 33 ],
Chris@0 34 'message' => [
Chris@0 35 'type' => 'text',
Chris@0 36 'not null' => TRUE,
Chris@0 37 'size' => 'big',
Chris@0 38 'description' => 'Text of log message to be passed into the t() function.',
Chris@0 39 ],
Chris@0 40 'variables' => [
Chris@0 41 'type' => 'blob',
Chris@0 42 'not null' => TRUE,
Chris@0 43 'size' => 'big',
Chris@0 44 'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
Chris@0 45 ],
Chris@0 46 'severity' => [
Chris@0 47 'type' => 'int',
Chris@0 48 'unsigned' => TRUE,
Chris@0 49 'not null' => TRUE,
Chris@0 50 'default' => 0,
Chris@0 51 'size' => 'tiny',
Chris@0 52 'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
Chris@0 53 ],
Chris@0 54 'link' => [
Chris@0 55 'type' => 'text',
Chris@0 56 'not null' => FALSE,
Chris@0 57 'description' => 'Link to view the result of the event.',
Chris@0 58 ],
Chris@0 59 'location' => [
Chris@0 60 'type' => 'text',
Chris@0 61 'not null' => TRUE,
Chris@0 62 'description' => 'URL of the origin of the event.',
Chris@0 63 ],
Chris@0 64 'referer' => [
Chris@0 65 'type' => 'text',
Chris@0 66 'not null' => FALSE,
Chris@0 67 'description' => 'URL of referring page.',
Chris@0 68 ],
Chris@0 69 'hostname' => [
Chris@0 70 'type' => 'varchar_ascii',
Chris@0 71 'length' => 128,
Chris@0 72 'not null' => TRUE,
Chris@0 73 'default' => '',
Chris@0 74 'description' => 'Hostname of the user who triggered the event.',
Chris@0 75 ],
Chris@0 76 'timestamp' => [
Chris@0 77 'type' => 'int',
Chris@0 78 'not null' => TRUE,
Chris@0 79 'default' => 0,
Chris@0 80 'description' => 'Unix timestamp of when event occurred.',
Chris@0 81 ],
Chris@0 82 ],
Chris@0 83 'primary key' => ['wid'],
Chris@0 84 'indexes' => [
Chris@0 85 'type' => ['type'],
Chris@0 86 'uid' => ['uid'],
Chris@0 87 'severity' => ['severity'],
Chris@0 88 ],
Chris@0 89 ];
Chris@0 90
Chris@0 91 return $schema;
Chris@0 92 }
Chris@0 93
Chris@0 94 /**
Chris@0 95 * Use standard plugin for wid and uid fields. Use dblog_types for type filter.
Chris@0 96 */
Chris@0 97 function dblog_update_8400() {
Chris@0 98 $config_factory = \Drupal::configFactory();
Chris@0 99
Chris@0 100 foreach ($config_factory->listAll('views.view.') as $view_config_name) {
Chris@0 101 $view = $config_factory->getEditable($view_config_name);
Chris@0 102 if ($view->get('base_table') != 'watchdog') {
Chris@0 103 continue;
Chris@0 104 }
Chris@0 105
Chris@0 106 $save = FALSE;
Chris@0 107 foreach ($view->get('display') as $display_name => $display) {
Chris@0 108 // Iterate through all the fields of watchdog views based tables.
Chris@0 109 if (isset($display['display_options']['fields'])) {
Chris@0 110 foreach ($display['display_options']['fields'] as $field_name => $field) {
Chris@0 111 // We are only interested in wid and uid fields from the watchdog
Chris@0 112 // table that still use the numeric id.
Chris@0 113 if (isset($field['table']) &&
Chris@0 114 $field['table'] === 'watchdog' &&
Chris@0 115 $field['plugin_id'] == 'numeric' &&
Chris@0 116 in_array($field['field'], ['wid', 'uid'])) {
Chris@0 117
Chris@0 118 $save = TRUE;
Chris@0 119 $new_value = $field;
Chris@0 120 $new_value['plugin_id'] = 'standard';
Chris@0 121
Chris@0 122 // Delete all the attributes related to numeric fields.
Chris@0 123 unset(
Chris@0 124 $new_value['set_precision'],
Chris@0 125 $new_value['precision'],
Chris@0 126 $new_value['decimal'],
Chris@0 127 $new_value['separator'],
Chris@0 128 $new_value['format_plural'],
Chris@0 129 $new_value['format_plural_string'],
Chris@0 130 $new_value['prefix'],
Chris@0 131 $new_value['suffix']
Chris@0 132 );
Chris@0 133 $view->set("display.$display_name.display_options.fields.$field_name", $new_value);
Chris@0 134 }
Chris@0 135 }
Chris@0 136 }
Chris@0 137
Chris@0 138 // Iterate all filters looking for type filters to update.
Chris@0 139 if (isset($display['display_options']['filters'])) {
Chris@0 140 foreach ($display['display_options']['filters'] as $filter_name => $filter) {
Chris@0 141 if (isset($filter['table']) &&
Chris@0 142 $filter['table'] === 'watchdog' &&
Chris@0 143 $filter['plugin_id'] == 'in_operator' &&
Chris@0 144 $filter['field'] == 'type') {
Chris@0 145
Chris@0 146 $save = TRUE;
Chris@0 147 $filter['plugin_id'] = 'dblog_types';
Chris@0 148 $view->set("display.$display_name.display_options.filters.$filter_name", $filter);
Chris@0 149 }
Chris@0 150 }
Chris@0 151 }
Chris@0 152 }
Chris@0 153
Chris@0 154 if ($save) {
Chris@0 155 $view->save();
Chris@0 156 }
Chris@0 157 }
Chris@0 158 }