Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Install, update and uninstall functions for the user module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Implements hook_schema().
|
Chris@0
|
10 */
|
Chris@0
|
11 function user_schema() {
|
Chris@0
|
12 $schema['users_data'] = [
|
Chris@0
|
13 'description' => 'Stores module data as key/value pairs per user.',
|
Chris@0
|
14 'fields' => [
|
Chris@0
|
15 'uid' => [
|
Chris@18
|
16 'description' => 'The {users}.uid this record affects.',
|
Chris@0
|
17 'type' => 'int',
|
Chris@0
|
18 'unsigned' => TRUE,
|
Chris@0
|
19 'not null' => TRUE,
|
Chris@0
|
20 'default' => 0,
|
Chris@0
|
21 ],
|
Chris@0
|
22 'module' => [
|
Chris@0
|
23 'description' => 'The name of the module declaring the variable.',
|
Chris@0
|
24 'type' => 'varchar_ascii',
|
Chris@0
|
25 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
|
Chris@0
|
26 'not null' => TRUE,
|
Chris@0
|
27 'default' => '',
|
Chris@0
|
28 ],
|
Chris@0
|
29 'name' => [
|
Chris@0
|
30 'description' => 'The identifier of the data.',
|
Chris@0
|
31 'type' => 'varchar_ascii',
|
Chris@0
|
32 'length' => 128,
|
Chris@0
|
33 'not null' => TRUE,
|
Chris@0
|
34 'default' => '',
|
Chris@0
|
35 ],
|
Chris@0
|
36 'value' => [
|
Chris@0
|
37 'description' => 'The value.',
|
Chris@0
|
38 'type' => 'blob',
|
Chris@0
|
39 'not null' => FALSE,
|
Chris@0
|
40 'size' => 'big',
|
Chris@0
|
41 ],
|
Chris@0
|
42 'serialized' => [
|
Chris@0
|
43 'description' => 'Whether value is serialized.',
|
Chris@0
|
44 'type' => 'int',
|
Chris@0
|
45 'size' => 'tiny',
|
Chris@0
|
46 'unsigned' => TRUE,
|
Chris@0
|
47 'default' => 0,
|
Chris@0
|
48 ],
|
Chris@0
|
49 ],
|
Chris@0
|
50 'primary key' => ['uid', 'module', 'name'],
|
Chris@0
|
51 'indexes' => [
|
Chris@0
|
52 'module' => ['module'],
|
Chris@0
|
53 'name' => ['name'],
|
Chris@0
|
54 ],
|
Chris@0
|
55 'foreign keys' => [
|
Chris@18
|
56 'data_user' => [
|
Chris@18
|
57 'table' => 'users',
|
Chris@18
|
58 'columns' => [
|
Chris@18
|
59 'uid' => 'uid',
|
Chris@18
|
60 ],
|
Chris@18
|
61 ],
|
Chris@0
|
62 ],
|
Chris@0
|
63 ];
|
Chris@0
|
64
|
Chris@0
|
65 return $schema;
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 /**
|
Chris@0
|
69 * Implements hook_install().
|
Chris@0
|
70 */
|
Chris@0
|
71 function user_install() {
|
Chris@0
|
72 $storage = \Drupal::entityManager()->getStorage('user');
|
Chris@0
|
73 // Insert a row for the anonymous user.
|
Chris@0
|
74 $storage
|
Chris@0
|
75 ->create([
|
Chris@0
|
76 'uid' => 0,
|
Chris@0
|
77 'status' => 0,
|
Chris@0
|
78 'name' => '',
|
Chris@0
|
79 ])
|
Chris@0
|
80 ->save();
|
Chris@0
|
81
|
Chris@0
|
82 // We need some placeholders here as name and mail are unique.
|
Chris@0
|
83 // This will be changed by the settings form in the installer.
|
Chris@0
|
84 $storage
|
Chris@0
|
85 ->create([
|
Chris@0
|
86 'uid' => 1,
|
Chris@0
|
87 'name' => 'placeholder-for-uid-1',
|
Chris@0
|
88 'mail' => 'placeholder-for-uid-1',
|
Chris@0
|
89 'status' => TRUE,
|
Chris@0
|
90 ])
|
Chris@0
|
91 ->save();
|
Chris@0
|
92 }
|
Chris@0
|
93
|
Chris@0
|
94 /**
|
Chris@0
|
95 * Fix invalid token in the status_blocked email body.
|
Chris@0
|
96 */
|
Chris@0
|
97 function user_update_8100() {
|
Chris@0
|
98 $config_factory = \Drupal::configFactory();
|
Chris@0
|
99 $config = $config_factory->getEditable('user.mail');
|
Chris@0
|
100 $mail = $config->get('status_blocked');
|
Chris@0
|
101 if (strpos($mail['body'], '[site:account-name]') !== FALSE) {
|
Chris@0
|
102 $mail['body'] = str_replace('[site:account-name]', '[site:name]', $mail['body']);
|
Chris@0
|
103 $config->set('status_blocked', $mail)->save(TRUE);
|
Chris@0
|
104 }
|
Chris@0
|
105 }
|