Same filename and directory in other branches
  1. 10 core/modules/dblog/dblog.install
  2. 9 core/modules/dblog/dblog.install

Install, update and uninstall functions for the dblog module.

File

core/modules/dblog/dblog.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the dblog module.
 */

/**
 * Implements hook_schema().
 */
function dblog_schema() {
  $schema['watchdog'] = [
    'description' => 'Table that contains logs of all system events.',
    'fields' => [
      'wid' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique watchdog event ID.',
      ],
      'uid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The {users}.uid of the user who triggered the event.',
      ],
      'type' => [
        'type' => 'varchar_ascii',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Type of log message, for example "user" or "page not found."',
      ],
      'message' => [
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Text of log message to be passed into the t() function.',
      ],
      'variables' => [
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
      ],
      'severity' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
      ],
      'link' => [
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Link to view the result of the event.',
      ],
      'location' => [
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'URL of the origin of the event.',
      ],
      'referer' => [
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'URL of referring page.',
      ],
      'hostname' => [
        'type' => 'varchar_ascii',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Hostname of the user who triggered the event.',
      ],
      'timestamp' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Unix timestamp of when event occurred.',
      ],
    ],
    'primary key' => [
      'wid',
    ],
    'indexes' => [
      'type' => [
        'type',
      ],
      'uid' => [
        'uid',
      ],
      'severity' => [
        'severity',
      ],
    ],
  ];
  return $schema;
}

/**
 * Use standard plugin for wid and uid fields. Use dblog_types for type filter.
 */
function dblog_update_8400() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('views.view.') as $view_config_name) {
    $view = $config_factory
      ->getEditable($view_config_name);
    if ($view
      ->get('base_table') != 'watchdog') {
      continue;
    }
    $save = FALSE;
    foreach ($view
      ->get('display') as $display_name => $display) {

      // Iterate through all the fields of watchdog views based tables.
      if (isset($display['display_options']['fields'])) {
        foreach ($display['display_options']['fields'] as $field_name => $field) {

          // We are only interested in wid and uid fields from the watchdog
          // table that still use the numeric id.
          if (isset($field['table']) && $field['table'] === 'watchdog' && $field['plugin_id'] == 'numeric' && in_array($field['field'], [
            'wid',
            'uid',
          ])) {
            $save = TRUE;
            $new_value = $field;
            $new_value['plugin_id'] = 'standard';

            // Delete all the attributes related to numeric fields.
            unset($new_value['set_precision'], $new_value['precision'], $new_value['decimal'], $new_value['separator'], $new_value['format_plural'], $new_value['format_plural_string'], $new_value['prefix'], $new_value['suffix']);
            $view
              ->set("display.{$display_name}.display_options.fields.{$field_name}", $new_value);
          }
        }
      }

      // Iterate all filters looking for type filters to update.
      if (isset($display['display_options']['filters'])) {
        foreach ($display['display_options']['filters'] as $filter_name => $filter) {
          if (isset($filter['table']) && $filter['table'] === 'watchdog' && $filter['plugin_id'] == 'in_operator' && $filter['field'] == 'type') {
            $save = TRUE;
            $filter['plugin_id'] = 'dblog_types';
            $view
              ->set("display.{$display_name}.display_options.filters.{$filter_name}", $filter);
          }
        }
      }
    }
    if ($save) {
      $view
        ->save();
    }
  }
}

/**
 * Change 'No logs message available.' area plugin type.
 */
function dblog_update_8600() {
  $config_factory = \Drupal::configFactory();
  $view = \Drupal::configFactory()
    ->getEditable('views.view.watchdog');
  if (empty($view)) {
    return;
  }
  $empty_text = $view
    ->get('display.default.display_options.empty');
  if (!isset($empty_text['area']['content']['value'])) {
    return;
  }

  // Only update the empty text if is untouched from the original version.
  if ($empty_text['area']['id'] == 'area' && $empty_text['area']['plugin_id'] == 'text' && $empty_text['area']['field'] == 'area' && $empty_text['area']['content']['value'] == 'No log messages available.') {
    $new_config = [
      'id' => 'area_text_custom',
      'table' => 'views',
      'field' => 'area_text_custom',
      'relationship' => 'none',
      'group_type' => 'group',
      'admin_label' => 'No log messages available.',
      'empty' => TRUE,
      'tokenize' => FALSE,
      'content' => 'No log messages available.',
      'plugin_id' => 'text_custom',
    ];
    $view
      ->set('display.default.display_options.empty.area', $new_config);
    $view
      ->save();
  }
}

Functions

Namesort descending Description
dblog_schema Implements hook_schema().
dblog_update_8400 Use standard plugin for wid and uid fields. Use dblog_types for type filter.
dblog_update_8600 Change 'No logs message available.' area plugin type.