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

Line #Times calledCode
1
<?php
2
// $Id: user.install,v 1.12 2008/05/07 19:34:24 dries Exp $
3
4
/**
5
 * Implementation of hook_schema().
6
 */
780
function user_schema() {
877
  $schema['authmap'] = array(
977
    'description' => t('Stores distributed authentication mapping.'),
10
    'fields' => array(
11
      'aid' => array(
1277
        'description' => t('Primary Key: Unique authmap ID.'),
1377
        'type' => 'serial',
1477
        'unsigned' => TRUE,
1577
        'not null' => TRUE,
1677
      ),
17
      'uid' => array(
1877
        'type' => 'int',
1977
        'not null' => TRUE,
2077
        'default' => 0,
2177
        'description' => t("User's {users}.uid."),
2277
      ),
23
      'authname' => array(
2477
        'type' => 'varchar',
2577
        'length' => 128,
2677
        'not null' => TRUE,
2777
        'default' => '',
2877
        'description' => t('Unique authentication name.'),
2977
      ),
30
      'module' => array(
3177
        'type' => 'varchar',
3277
        'length' => 128,
3377
        'not null' => TRUE,
3477
        'default' => '',
3577
        'description' => t('Module which is controlling the
authentication.'),
3677
      ),
3777
    ),
38
    'unique keys' => array(
3977
      'authname' => array('authname'),
4077
    ),
4177
    'primary key' => array('aid'),
42
  );
43
4477
  $schema['role_permission'] = array(
4577
    'description' => t('Stores the permissions assigned to user roles.'),
46
    'fields' => array(
47
      'rid' => array(
4877
        'type' => 'int',
4977
        'unsigned' => TRUE,
5077
        'not null' => TRUE,
5177
        'description' => t('Foreign Key: {role}.rid.'),
5277
      ),
53
      'permission' => array(
5477
        'type' => 'varchar',
5577
        'length' => 64,
5677
        'not null' => TRUE,
5777
        'default' => '',
5877
        'description' => t('A single permission granted to the role
identified by rid.'),
5977
      ),
6077
    ),
6177
    'primary key' => array('rid', 'permission'),
62
    'indexes' => array(
6377
      'permission' => array('permission'),
6477
    ),
65
  );
66
6777
  $schema['role'] = array(
6877
    'description' => t('Stores user roles.'),
69
    'fields' => array(
70
      'rid' => array(
7177
        'type' => 'serial',
7277
        'unsigned' => TRUE,
7377
        'not null' => TRUE,
7477
        'description' => t('Primary Key: Unique role ID.'),
7577
      ),
76
      'name' => array(
7777
        'type' => 'varchar',
7877
        'length' => 64,
7977
        'not null' => TRUE,
8077
        'default' => '',
8177
        'description' => t('Unique role name.'),
8277
      ),
8377
    ),
84
    'unique keys' => array(
8577
      'name' => array('name'),
8677
    ),
8777
    'primary key' => array('rid'),
88
  );
89
9077
  $schema['users'] = array(
9177
    'description' => t('Stores user data.'),
92
    'fields' => array(
93
      'uid' => array(
9477
        'type' => 'serial',
9577
        'unsigned' => TRUE,
9677
        'not null' => TRUE,
9777
        'description' => t('Primary Key: Unique user ID.'),
9877
      ),
99
      'name' => array(
10077
        'type' => 'varchar',
10177
        'length' => 60,
10277
        'not null' => TRUE,
10377
        'default' => '',
10477
        'description' => t('Unique user name.'),
10577
      ),
106
      'pass' => array(
10777
        'type' => 'varchar',
10877
        'length' => 128,
10977
        'not null' => TRUE,
11077
        'default' => '',
11177
        'description' => t("User's password (hashed)."),
11277
      ),
113
      'mail' => array(
11477
        'type' => 'varchar',
11577
        'length' => 64,
11677
        'not null' => FALSE,
11777
        'default' => '',
11877
        'description' => t("User's email address."),
11977
      ),
120
      'theme' => array(
12177
        'type' => 'varchar',
12277
        'length' => 255,
12377
        'not null' => TRUE,
12477
        'default' => '',
12577
        'description' => t("User's default theme."),
12677
      ),
127
      'signature' => array(
12877
        'type' => 'varchar',
12977
        'length' => 255,
13077
        'not null' => TRUE,
13177
        'default' => '',
13277
        'description' => t("User's signature."),
13377
      ),
134
      'created' => array(
13577
        'type' => 'int',
13677
        'not null' => TRUE,
13777
        'default' => 0,
13877
        'description' => t('Timestamp for when user was created.'),
13977
      ),
140
      'access' => array(
14177
        'type' => 'int',
14277
        'not null' => TRUE,
14377
        'default' => 0,
14477
        'description' => t('Timestamp for previous time user accessed the
site.'),
14577
      ),
146
      'login' => array(
14777
        'type' => 'int',
14877
        'not null' => TRUE,
14977
        'default' => 0,
15077
        'description' => t("Timestamp for user's last login."),
15177
      ),
152
      'status' => array(
15377
        'type' => 'int',
15477
        'not null' => TRUE,
15577
        'default' => 0,
15677
        'size' => 'tiny',
15777
        'description' => t('Whether the user is active(1) or
blocked(0).'),
15877
      ),
159
      'timezone' => array(
16077
        'type' => 'varchar',
16177
        'length' => 8,
16277
        'not null' => FALSE,
16377
        'description' => t("User's timezone."),
16477
      ),
165
      'language' => array(
16677
        'type' => 'varchar',
16777
        'length' => 12,
16877
        'not null' => TRUE,
16977
        'default' => '',
17077
        'description' => t("User's default language."),
17177
      ),
172
      'picture' => array(
17377
        'type' => 'varchar',
17477
        'length' => 255,
17577
        'not null' => TRUE,
17677
        'default' => '',
17777
        'description' => t("Path to the user's uploaded picture."),
17877
      ),
179
      'init' => array(
18077
        'type' => 'varchar',
18177
        'length' => 64,
18277
        'not null' => FALSE,
18377
        'default' => '',
18477
        'description' => t('Email address used for initial account
creation.'),
18577
      ),
186
      'data' => array(
18777
        'type' => 'text',
18877
        'not null' => FALSE,
18977
        'size' => 'big',
19077
        'serialize' => TRUE,
19177
        '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.'),
19277
      ),
19377
    ),
194
    'indexes' => array(
19577
      'access' => array('access'),
19677
      'created' => array('created'),
19777
      'mail' => array('mail'),
19877
    ),
199
    'unique keys' => array(
20077
      'name' => array('name'),
20177
    ),
20277
    'primary key' => array('uid'),
203
  );
204
20577
  $schema['users_roles'] = array(
20677
    'description' => t('Maps users to roles.'),
207
    'fields' => array(
208
      'uid' => array(
20977
        'type' => 'int',
21077
        'unsigned' => TRUE,
21177
        'not null' => TRUE,
21277
        'default' => 0,
21377
        'description' => t('Primary Key: {users}.uid for user.'),
21477
      ),
215
      'rid' => array(
21677
        'type' => 'int',
21777
        'unsigned' => TRUE,
21877
        'not null' => TRUE,
21977
        'default' => 0,
22077
        'description' => t('Primary Key: {role}.rid for role.'),
22177
      ),
22277
    ),
22377
    'primary key' => array('uid', 'rid'),
224
    'indexes' => array(
22577
      'rid' => array('rid'),
22677
    ),
227
  );
228
22977
  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
 */
24380
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 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
28580
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
29980