Issue #2242585 by filijonka: Fix file docs in bootstrap.inc
[project/drupal.git] / core / modules / user / user.install
1 <?php
2
3 /**
4 * @file
5 * Install, update and uninstall functions for the user module.
6 */
7
8 use Drupal\Core\Language\Language;
9 use Drupal\field\Field;
10
11 /**
12 * Implements hook_schema().
13 */
14 function user_schema() {
15 // The table name here is plural, despite Drupal table naming standards,
16 // because "user" is a reserved word in many databases.
17 $schema['users'] = array(
18 'description' => 'Stores user data.',
19 'fields' => array(
20 'uid' => array(
21 'type' => 'int',
22 'unsigned' => TRUE,
23 'not null' => TRUE,
24 'description' => 'Primary Key: Unique user ID.',
25 'default' => 0,
26 ),
27 'uuid' => array(
28 'description' => 'Unique Key: Universally unique identifier for this entity.',
29 'type' => 'varchar',
30 'length' => 128,
31 'not null' => FALSE,
32 ),
33 'name' => array(
34 'type' => 'varchar',
35 'length' => 60,
36 'not null' => TRUE,
37 'default' => '',
38 'description' => 'Unique user name.',
39 ),
40 'langcode' => array(
41 'type' => 'varchar',
42 'length' => 12,
43 'not null' => TRUE,
44 'default' => '',
45 'description' => "The {language}.langcode of the user's profile.",
46 ),
47 'pass' => array(
48 'type' => 'varchar',
49 'length' => 128,
50 'not null' => TRUE,
51 'default' => '',
52 'description' => "User's password (hashed).",
53 ),
54 'mail' => array(
55 'type' => 'varchar',
56 'length' => 254,
57 'not null' => FALSE,
58 'default' => '',
59 'description' => "User's e-mail address.",
60 ),
61 'signature' => array(
62 'type' => 'varchar',
63 'length' => 255,
64 'not null' => TRUE,
65 'default' => '',
66 'description' => "User's signature.",
67 ),
68 'signature_format' => array(
69 'type' => 'varchar',
70 'length' => 255,
71 'not null' => FALSE,
72 'description' => 'The filter format ID of the signature.',
73 ),
74 'created' => array(
75 'type' => 'int',
76 'not null' => TRUE,
77 'default' => 0,
78 'description' => 'Timestamp for when user was created.',
79 ),
80 'access' => array(
81 'type' => 'int',
82 'not null' => TRUE,
83 'default' => 0,
84 'description' => 'Timestamp for previous time user accessed the site.',
85 ),
86 'login' => array(
87 'type' => 'int',
88 'not null' => TRUE,
89 'default' => 0,
90 'description' => "Timestamp for user's last login.",
91 ),
92 'status' => array(
93 'type' => 'int',
94 'not null' => TRUE,
95 'default' => 0,
96 'size' => 'tiny',
97 'description' => 'Whether the user is active(1) or blocked(0).',
98 ),
99 'timezone' => array(
100 'type' => 'varchar',
101 'length' => 32,
102 'not null' => FALSE,
103 'description' => "User's time zone.",
104 ),
105 'preferred_langcode' => array(
106 'type' => 'varchar',
107 'length' => 12,
108 'not null' => TRUE,
109 'default' => '',
110 'description' => 'The {language}.langcode that the user prefers for receiving emails and viewing the site.',
111 ),
112 'preferred_admin_langcode' => array(
113 'type' => 'varchar',
114 'length' => 12,
115 'not null' => TRUE,
116 'default' => '',
117 'description' => 'The {language}.langcode that the user prefers for viewing administration pages.',
118 ),
119 'init' => array(
120 'type' => 'varchar',
121 'length' => 254,
122 'not null' => FALSE,
123 'default' => '',
124 'description' => 'E-mail address used for initial account creation.',
125 ),
126 ),
127 'indexes' => array(
128 'access' => array('access'),
129 'created' => array('created'),
130 'mail' => array('mail'),
131 ),
132 'unique keys' => array(
133 'uuid' => array('uuid'),
134 'name' => array('name'),
135 ),
136 'primary key' => array('uid'),
137 );
138
139 $schema['users_data'] = array(
140 'description' => 'Stores module data as key/value pairs per user.',
141 'fields' => array(
142 'uid' => array(
143 'description' => 'Primary key: {users}.uid for user.',
144 'type' => 'int',
145 'unsigned' => TRUE,
146 'not null' => TRUE,
147 'default' => 0,
148 ),
149 'module' => array(
150 'description' => 'The name of the module declaring the variable.',
151 'type' => 'varchar',
152 'length' => DRUPAL_EXTENSION_NAME_MAX_LENGTH,
153 'not null' => TRUE,
154 'default' => '',
155 ),
156 'name' => array(
157 'description' => 'The identifier of the data.',
158 'type' => 'varchar',
159 'length' => 128,
160 'not null' => TRUE,
161 'default' => '',
162 ),
163 'value' => array(
164 'description' => 'The value.',
165 'type' => 'blob',
166 'not null' => FALSE,
167 'size' => 'big',
168 ),
169 'serialized' => array(
170 'description' => 'Whether value is serialized.',
171 'type' => 'int',
172 'size' => 'tiny',
173 'unsigned' => TRUE,
174 'default' => 0,
175 ),
176 ),
177 'primary key' => array('uid', 'module', 'name'),
178 'indexes' => array(
179 'module' => array('module'),
180 'name' => array('name'),
181 ),
182 'foreign keys' => array(
183 'uid' => array('users' => 'uid'),
184 ),
185 );
186
187 $schema['users_roles'] = array(
188 'description' => 'Maps users to roles.',
189 'fields' => array(
190 'uid' => array(
191 'type' => 'int',
192 'unsigned' => TRUE,
193 'not null' => TRUE,
194 'default' => 0,
195 'description' => 'Primary Key: {users}.uid for user.',
196 ),
197 'rid' => array(
198 'type' => 'varchar',
199 'length' => 64,
200 'not null' => TRUE,
201 'description' => 'Primary Key: ID for the role.',
202 ),
203 ),
204 'primary key' => array('uid', 'rid'),
205 'indexes' => array(
206 'rid' => array('rid'),
207 ),
208 'foreign keys' => array(
209 'user' => array(
210 'table' => 'users',
211 'columns' => array('uid' => 'uid'),
212 ),
213 ),
214 );
215
216 return $schema;
217 }
218
219 /**
220 * Implements hook_install().
221 */
222 function user_install() {
223 // Insert a row for the anonymous user.
224 db_insert('users')
225 ->fields(array(
226 'uid' => 0,
227 'uuid' => \Drupal::service('uuid')->generate(),
228 'name' => '',
229 'mail' => '',
230 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id,
231 ))
232 ->execute();
233
234 // We need some placeholders here as name and mail are uniques.
235 // This will be changed by the settings form in the installer.
236 db_insert('users')
237 ->fields(array(
238 'uid' => 1,
239 'uuid' => \Drupal::service('uuid')->generate(),
240 'name' => 'placeholder-for-uid-1',
241 'mail' => 'placeholder-for-uid-1',
242 'created' => REQUEST_TIME,
243 'status' => 1,
244 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->id,
245 ))
246 ->execute();
247 }