Code coverage for /20081101/modules/user/user.install

Line #Times calledCode
1
<?php
2
// $Id: user.install,v 1.13 2008/09/20 20:22:25 webchick Exp $
3
4
/**
5
 * Implementation of hook_schema().
6
 */
712
function user_schema() {
8134
  $schema['authmap'] = array(
9134
    'description' => t('Stores distributed authentication mapping.'),
10
    'fields' => array(
11
      'aid' => array(
12134
        'description' => t('Primary Key: Unique authmap ID.'),
13134
        'type' => 'serial',
14134
        'unsigned' => TRUE,
15134
        'not null' => TRUE,
16134
      ),
17
      'uid' => array(
18134
        'type' => 'int',
19134
        'not null' => TRUE,
20134
        'default' => 0,
21134
        'description' => t("User's {users}.uid."),
22134
      ),
23
      'authname' => array(
24134
        'type' => 'varchar',
25134
        'length' => 128,
26134
        'not null' => TRUE,
27134
        'default' => '',
28134
        'description' => t('Unique authentication name.'),
29134
      ),
30
      'module' => array(
31134
        'type' => 'varchar',
32134
        'length' => 128,
33134
        'not null' => TRUE,
34134
        'default' => '',
35134
        'description' => t('Module which is controlling the
authentication.'),
36134
      ),
37134
    ),
38
    'unique keys' => array(
39134
      'authname' => array('authname'),
40134
    ),
41134
    'primary key' => array('aid'),
42
  );
43
44134
  $schema['role_permission'] = array(
45134
    'description' => t('Stores the permissions assigned to user roles.'),
46
    'fields' => array(
47
      'rid' => array(
48134
        'type' => 'int',
49134
        'unsigned' => TRUE,
50134
        'not null' => TRUE,
51134
        'description' => t('Foreign Key: {role}.rid.'),
52134
      ),
53
      'permission' => array(
54134
        'type' => 'varchar',
55134
        'length' => 64,
56134
        'not null' => TRUE,
57134
        'default' => '',
58134
        'description' => t('A single permission granted to the role
identified by rid.'),
59134
      ),
60134
    ),
61134
    'primary key' => array('rid', 'permission'),
62
    'indexes' => array(
63134
      'permission' => array('permission'),
64134
    ),
65
  );
66
67134
  $schema['role'] = array(
68134
    'description' => t('Stores user roles.'),
69
    'fields' => array(
70
      'rid' => array(
71134
        'type' => 'serial',
72134
        'unsigned' => TRUE,
73134
        'not null' => TRUE,
74134
        'description' => t('Primary Key: Unique role ID.'),
75134
      ),
76
      'name' => array(
77134
        'type' => 'varchar',
78134
        'length' => 64,
79134
        'not null' => TRUE,
80134
        'default' => '',
81134
        'description' => t('Unique role name.'),
82134
      ),
83134
    ),
84
    'unique keys' => array(
85134
      'name' => array('name'),
86134
    ),
87134
    'primary key' => array('rid'),
88
  );
89
90134
  $schema['users'] = array(
91134
    'description' => t('Stores user data.'),
92
    'fields' => array(
93
      'uid' => array(
94134
        'type' => 'serial',
95134
        'unsigned' => TRUE,
96134
        'not null' => TRUE,
97134
        'description' => t('Primary Key: Unique user ID.'),
98134
      ),
99
      'name' => array(
100134
        'type' => 'varchar',
101134
        'length' => 60,
102134
        'not null' => TRUE,
103134
        'default' => '',
104134
        'description' => t('Unique user name.'),
105134
      ),
106
      'pass' => array(
107134
        'type' => 'varchar',
108134
        'length' => 128,
109134
        'not null' => TRUE,
110134
        'default' => '',
111134
        'description' => t("User's password (hashed)."),
112134
      ),
113
      'mail' => array(
114134
        'type' => 'varchar',
115134
        'length' => 64,
116134
        'not null' => FALSE,
117134
        'default' => '',
118134
        'description' => t("User's email address."),
119134
      ),
120
      'theme' => array(
121134
        'type' => 'varchar',
122134
        'length' => 255,
123134
        'not null' => TRUE,
124134
        'default' => '',
125134
        'description' => t("User's default theme."),
126134
      ),
127
      'signature' => array(
128134
        'type' => 'varchar',
129134
        'length' => 255,
130134
        'not null' => TRUE,
131134
        'default' => '',
132134
        'description' => t("User's signature."),
133134
      ),
134
      'created' => array(
135134
        'type' => 'int',
136134
        'not null' => TRUE,
137134
        'default' => 0,
138134
        'description' => t('Timestamp for when user was created.'),
139134
      ),
140
      'access' => array(
141134
        'type' => 'int',
142134
        'not null' => TRUE,
143134
        'default' => 0,
144134
        'description' => t('Timestamp for previous time user accessed the
site.'),
145134
      ),
146
      'login' => array(
147134
        'type' => 'int',
148134
        'not null' => TRUE,
149134
        'default' => 0,
150134
        'description' => t("Timestamp for user's last login."),
151134
      ),
152
      'status' => array(
153134
        'type' => 'int',
154134
        'not null' => TRUE,
155134
        'default' => 0,
156134
        'size' => 'tiny',
157134
        'description' => t('Whether the user is active(1) or blocked(0).'),
158134
      ),
159
      'timezone' => array(
160134
        'type' => 'varchar',
161134
        'length' => 8,
162134
        'not null' => FALSE,
163134
        'description' => t("User's timezone."),
164134
      ),
165
      'language' => array(
166134
        'type' => 'varchar',
167134
        'length' => 12,
168134
        'not null' => TRUE,
169134
        'default' => '',
170134
        'description' => t("User's default language."),
171134
      ),
172
      'picture' => array(
173134
        'type' => 'varchar',
174134
        'length' => 255,
175134
        'not null' => TRUE,
176134
        'default' => '',
177134
        'description' => t("Path to the user's uploaded picture."),
178134
      ),
179
      'init' => array(
180134
        'type' => 'varchar',
181134
        'length' => 64,
182134
        'not null' => FALSE,
183134
        'default' => '',
184134
        'description' => t('Email address used for initial account
creation.'),
185134
      ),
186
      'data' => array(
187134
        'type' => 'text',
188134
        'not null' => FALSE,
189134
        'size' => 'big',
190134
        'serialize' => TRUE,
191134
        '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.'),
192134
      ),
193134
    ),
194
    'indexes' => array(
195134
      'access' => array('access'),
196134
      'created' => array('created'),
197134
      'mail' => array('mail'),
198134
    ),
199
    'unique keys' => array(
200134
      'name' => array('name'),
201134
    ),
202134
    'primary key' => array('uid'),
203
  );
204
205134
  $schema['users_roles'] = array(
206134
    'description' => t('Maps users to roles.'),
207
    'fields' => array(
208
      'uid' => array(
209134
        'type' => 'int',
210134
        'unsigned' => TRUE,
211134
        'not null' => TRUE,
212134
        'default' => 0,
213134
        'description' => t('Primary Key: {users}.uid for user.'),
214134
      ),
215
      'rid' => array(
216134
        'type' => 'int',
217134
        'unsigned' => TRUE,
218134
        'not null' => TRUE,
219134
        'default' => 0,
220134
        'description' => t('Primary Key: {role}.rid for role.'),
221134
      ),
222134
    ),
223134
    'primary key' => array('uid', 'rid'),
224
    'indexes' => array(
225134
      'rid' => array('rid'),
226134
    ),
227
  );
228
229134
  return $schema;
2300
}
231
232
/**
233
 * @defgroup user-updates-6.x-to-7.x User updates from 6.x to 7.x
234
 * @{
235
 */
236
237
/**
238
 * Increase the length of the password field to accommodate better hashes.
239
 *
240
 * Also re-hashes all current passwords to improve security. This may be a
241
 * lengthy process, and is performed batch-wise.
242
 */
24312
function user_update_7000(&$sandbox) {
2440
  $ret = array('#finished' => 0);
245
  // Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable
speed.
2460
  $hash_count_log2 = 11;
247
  // Multi-part update.
2480
  if (!isset($sandbox['user_from'])) {
2490
    db_change_field($ret, 'users', 'pass', 'pass', array('type' =>
'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
2500
    $sandbox['user_from'] = 0;
2510
    $sandbox['user_count'] = db_result(db_query("SELECT COUNT(uid) FROM
{users}"));
2520
  }
253
  else {
2540
    require_once DRUPAL_ROOT . '/' . variable_get('password_inc',
'includes/password.inc');
255
    //  Hash again all current hashed passwords.
2560
    $has_rows = FALSE;
257
    // Update this many per page load.
2580
    $count = 1000;
2590
    $result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0
ORDER BY uid", $sandbox['user_from'], $count);
2600
    while ($account = db_fetch_array($result)) {
2610
       $has_rows = TRUE;
2620
       $new_hash = user_hash_password($account['pass'], $hash_count_log2);
2630
       if ($new_hash) {
264
         // Indicate an updated password.
2650
         $new_hash  = 'U' . $new_hash;
2660
         db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d",
$new_hash, $account['uid']);
2670
       }
2680
    }
2690
    $ret['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
2700
    $sandbox['user_from'] += $count;
2710
    if (!$has_rows) {
2720
      $ret['#finished'] = 1;
2730
      $ret[] = array('success' => TRUE, 'query' => "UPDATE {users} SET pass
= 'U' . user_hash_password(pass) WHERE uid > 0");
2740
    }
275
  }
2760
  return $ret;
2770
}
278
279
/**
280
 * Remove the 'threshold', 'mode' and 'sort' columns from the {user} table.
281
 *
282
 * These fields were previously used to store per-user comment settings.
283
 */
284
28512
function user_update_7001() {
2860
  $ret = array();
2870
  db_drop_field($ret, 'users', 'threshold');
2880
  db_drop_field($ret, 'users', 'mode');
2890
  db_drop_field($ret, 'users', 'sort');
290
2910
  return $ret;
2920
}
293
294
/**
295
 * @} End of "defgroup user-updates-6.x-to-7.x"
296
 * The next series of updates should start at 8000.
297
 */
298
29912