summaryrefslogtreecommitdiff
path: root/modules/user/user.install
blob: df4b2670d568766b88cdd7d163ce01128c50d020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
// $Id$

/**
 * Implementation of hook_schema().
 */
function user_schema() {
  $schema['authmap'] = array(
    'description' => t('Stores distributed authentication mapping.'),
    'fields' => array(
      'aid' => array(
        'description' => t('Primary Key: Unique authmap ID.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => t("User's {users}.uid."),
      ),
      'authname' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => t('Unique authentication name.'),
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => t('Module which is controlling the authentication.'),
      ),
    ),
    'unique keys' => array(
      'authname' => array('authname'),
    ),
    'primary key' => array('aid'),
  );

  $schema['role_permission'] = array(
    'description' => t('Stores the permissions assigned to user roles.'),
    'fields' => array(
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Foreign Key: {role}.rid.'),
      ),
      'permission' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => t('A single permission granted to the role identified by rid.'),
      ),
    ),
    'primary key' => array('rid', 'permission'),
    'indexes' => array(
      'permission' => array('permission'),
    ),
  );

  $schema['role'] = array(
    'description' => t('Stores user roles.'),
    'fields' => array(
      'rid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Primary Key: Unique role ID.'),
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => t('Unique role name.'),
      ),
    ),
    'unique keys' => array(
      'name' => array('name'),
    ),
    'primary key' => array('rid'),
  );

  $schema['users'] = array(
    'description' => t('Stores user data.'),
    'fields' => array(
      'uid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Primary Key: Unique user ID.'),
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 60,
        'not null' => TRUE,
        'default' => '',
        'description' => t('Unique user name.'),
      ),
      'pass' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => t("User's password (hashed)."),
      ),
      'mail' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
        'default' => '',
        'description' => t("User's email address."),
      ),
      'theme' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => t("User's default theme."),
      ),
      'signature' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => t("User's signature."),
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => t('Timestamp for when user was created.'),
      ),
      'access' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => t('Timestamp for previous time user accessed the site.'),
      ),
      'login' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => t("Timestamp for user's last login."),
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => t('Whether the user is active(1) or blocked(0).'),
      ),
      'timezone' => array(
        'type' => 'varchar',
        'length' => 8,
        'not null' => FALSE,
        'description' => t("User's timezone."),
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => t("User's default language."),
      ),
      'picture' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => t("Path to the user's uploaded picture."),
      ),
      'init' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
        'default' => '',
        'description' => t('Email address used for initial account creation.'),
      ),
      'data' => array(
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => t('A serialized array of name value pairs that are related to the user. Any form values posted during user edit are stored and are loaded into the $user object during user_load(). Use of this field is discouraged and it will likely disappear in a future version of Drupal.'),
      ),
    ),
    'indexes' => array(
      'access' => array('access'),
      'created' => array('created'),
      'mail' => array('mail'),
    ),
    'unique keys' => array(
      'name' => array('name'),
    ),
    'primary key' => array('uid'),
  );

  $schema['users_roles'] = array(
    'description' => t('Maps users to roles.'),
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('Primary Key: {users}.uid for user.'),
      ),
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('Primary Key: {role}.rid for role.'),
      ),
    ),
    'primary key' => array('uid', 'rid'),
    'indexes' => array(
      'rid' => array('rid'),
    ),
  );

  return $schema;
}

/**
 * @defgroup user-updates-6.x-to-7.x User updates from 6.x to 7.x
 * @{
 */

/**
 * Increase the length of the password field to accommodate better hashes.
 *
 * Also re-hashes all current passwords to improve security. This may be a
 * lengthy process, and is performed batch-wise.
 */
function user_update_7000(&$sandbox) {
  $ret = array('#finished' => 0);
  // Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
  $hash_count_log2 = 11;
  // Multi-part update.
  if (!isset($sandbox['user_from'])) {
    db_change_field($ret, 'users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
    $sandbox['user_from'] = 0;
    $sandbox['user_count'] = db_result(db_query("SELECT COUNT(uid) FROM {users}"));
  }
  else {
    require_once variable_get('password_inc', './includes/password.inc');
    //  Hash again all current hashed passwords.
    $has_rows = FALSE;
    // Update this many per page load.
    $count = 1000;
    $result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0 ORDER BY uid", $sandbox['user_from'], $count);
    while ($account = db_fetch_array($result)) {
       $has_rows = TRUE;
       $new_hash = user_hash_password($account['pass'], $hash_count_log2);
       if ($new_hash) {
         // Indicate an updated password.
         $new_hash  = 'U' . $new_hash;
         db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $new_hash, $account['uid']);
       }
    }
    $ret['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
    $sandbox['user_from'] += $count;
    if (!$has_rows) {
      $ret['#finished'] = 1;
      $ret[] = array('success' => TRUE, 'query' => "UPDATE {users} SET pass = 'U' . user_hash_password(pass) WHERE uid > 0");
    }
  }
  return $ret;
}

/**
 * Remove the 'threshold', 'mode' and 'sort' columns from the {user} table.
 *
 * These fields were previously used to store per-user comment settings.
 */

function user_update_7001() {
  $ret = array();
  db_drop_field($ret, 'users', 'threshold');
  db_drop_field($ret, 'users', 'mode');
  db_drop_field($ret, 'users', 'sort');

  return $ret;
}

/**
 * @} End of "defgroup user-updates-6.x-to-7.x"
 * The next series of updates should start at 8000.
 */