user.install 2.44 KB
Newer Older
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Install, update and uninstall functions for the user module.
 */

8
/**
9
 * Implements hook_schema().
10 11
 */
function user_schema() {
12
  $schema['users_data'] = [
13
    'description' => 'Stores module data as key/value pairs per user.',
14 15
    'fields' => [
      'uid' => [
16 17 18 19 20
        'description' => 'Primary key: {users}.uid for user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
21 22
      ],
      'module' => [
23
        'description' => 'The name of the module declaring the variable.',
24
        'type' => 'varchar_ascii',
25
        'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
26 27
        'not null' => TRUE,
        'default' => '',
28 29
      ],
      'name' => [
30
        'description' => 'The identifier of the data.',
31
        'type' => 'varchar_ascii',
32 33 34
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
35 36
      ],
      'value' => [
37 38 39 40
        'description' => 'The value.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
41 42
      ],
      'serialized' => [
43 44 45 46 47
        'description' => 'Whether value is serialized.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'default' => 0,
48 49 50 51 52 53 54 55 56 57 58
      ],
    ],
    'primary key' => ['uid', 'module', 'name'],
    'indexes' => [
      'module' => ['module'],
      'name' => ['name'],
    ],
    'foreign keys' => [
      'uid' => ['users' => 'uid'],
    ],
  ];
59

60 61 62
  return $schema;
}

63 64 65 66
/**
 * Implements hook_install().
 */
function user_install() {
67
  $storage = \Drupal::entityManager()->getStorage('user');
68
  // Insert a row for the anonymous user.
69
  $storage
70
    ->create([
71
      'uid' => 0,
72
      'status' => 0,
73
      'name' => '',
74
    ])
75
    ->save();
76

77
  // We need some placeholders here as name and mail are unique.
78
  // This will be changed by the settings form in the installer.
79
  $storage
80
    ->create([
81 82 83
      'uid' => 1,
      'name' => 'placeholder-for-uid-1',
      'mail' => 'placeholder-for-uid-1',
84
      'status' => TRUE,
85
    ])
86
    ->save();
87
}
88 89 90 91 92 93 94 95 96 97 98 99 100

/**
 * Fix invalid token in the status_blocked email body.
 */
function user_update_8100() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory->getEditable('user.mail');
  $mail = $config->get('status_blocked');
  if (strpos($mail['body'], '[site:account-name]') !== FALSE) {
    $mail['body'] = str_replace('[site:account-name]', '[site:name]', $mail['body']);
    $config->set('status_blocked', $mail)->save(TRUE);
  }
}