Spike PHPCoverage Details: user.install

Line #FrequencySource Line
1 <?php
2 // $Id: user.install,v 1.8 2008/03/31 20:50:05 dries Exp $
3 
4 /**
5  * Implementation of hook_schema().
6  */
7 function user_schema() {
8   $schema['access'] = array(
91    'description' => t('Stores site access rules.'),
10     'fields' => array(
11       'aid' => array(
12         'type' => 'serial',
13         'not null' => TRUE,
14         'description' => t('Primary Key: Unique access ID.'),
15       ),
16       'mask' => array(
17         'type' => 'varchar',
18         'length' => 255,
19         'not null' => TRUE,
20         'default' => '',
21         'description' => t('Text mask used for filtering access.'),
22       ),
23       'type' => array(
24         'type' => 'varchar',
25         'length' => 255,
26         'not null' => TRUE,
27         'default' => '',
28         'description' => t('Type of access rule: name, mail or host.'),
29       ),
30       'status' => array(
31         'type' => 'int',
32         'not null' => TRUE,
33         'default' => 0,
34         'size' => 'tiny',
35         'description' => t('Whether rule is to allow(1) or deny(0) access.'),
36       ),
37     ),
38     'primary key' => array('aid'),
39   );
40 
41   $schema['authmap'] = array(
421    'description' => t('Stores distributed authentication mapping.'),
43     'fields' => array(
44       'aid' => array(
45         'description' => t('Primary Key: Unique authmap ID.'),
46         'type' => 'serial',
47         'unsigned' => TRUE,
48         'not null' => TRUE,
49       ),
50       'uid' => array(
51         'type' => 'int',
52         'not null' => TRUE,
53         'default' => 0,
54         'description' => t("User's {users}.uid."),
55       ),
56       'authname' => array(
57         'type' => 'varchar',
58         'length' => 128,
59         'not null' => TRUE,
60         'default' => '',
61         'description' => t('Unique authentication name.'),
62       ),
63       'module' => array(
64         'type' => 'varchar',
65         'length' => 128,
66         'not null' => TRUE,
67         'default' => '',
68         'description' => t('Module which is controlling the authentication.'),
69       ),
70     ),
71     'unique keys' => array(
72       'authname' => array('authname'),
73     ),
74     'primary key' => array('aid'),
75   );
76 
77   $schema['permission'] = array(
781    'description' => t('Stores permissions for users.'),
79     'fields' => array(
80       'pid' => array(
81         'type' => 'serial',
82         'not null' => TRUE,
83         'description' => t('Primary Key: Unique permission ID.'),
84       ),
85       'rid' => array(
86         'type' => 'int',
87         'unsigned' => TRUE,
88         'not null' => TRUE,
89         'default' => 0,
90         'description' => t('The {role}.rid to which the permissions are assigned.'),
91       ),
92       'perm' => array(
93         'type' => 'text',
94         'not null' => FALSE,
95         'size' => 'big',
96         'description' => t('List of permissions being assigned.'),
97       ),
98       'tid' => array(
99         'type' => 'int',
100         'unsigned' => TRUE,
101         'not null' => TRUE,
102         'default' => 0,
103         'description' => t('Originally intended for taxonomy-based permissions, but never used.'),
104       ),
105     ),
106     'primary key' => array('pid'),
107     'indexes' => array(
108       'rid' => array('rid'),
109     ),
110   );
111 
112   $schema['role'] = array(
1131    'description' => t('Stores user roles.'),
114     'fields' => array(
115       'rid' => array(
116         'type' => 'serial',
117         'unsigned' => TRUE,
118         'not null' => TRUE,
119         'description' => t('Primary Key: Unique role id.'),
120       ),
121       'name' => array(
122         'type' => 'varchar',
123         'length' => 64,
124         'not null' => TRUE,
125         'default' => '',
126         'description' => t('Unique role name.'),
127       ),
128     ),
129     'unique keys' => array(
130       'name' => array('name'),
131     ),
132     'primary key' => array('rid'),
133   );
134 
135   $schema['users'] = array(
1361    'description' => t('Stores user data.'),
137     'fields' => array(
138       'uid' => array(
139         'type' => 'serial',
140         'unsigned' => TRUE,
141         'not null' => TRUE,
142         'description' => t('Primary Key: Unique user ID.'),
143       ),
144       'name' => array(
145         'type' => 'varchar',
146         'length' => 60,
147         'not null' => TRUE,
148         'default' => '',
149         'description' => t('Unique user name.'),
150       ),
151       'pass' => array(
152         'type' => 'varchar',
153         'length' => 128,
154         'not null' => TRUE,
155         'default' => '',
156         'description' => t("User's password (hashed)."),
157       ),
158       'mail' => array(
159         'type' => 'varchar',
160         'length' => 64,
161         'not null' => FALSE,
162         'default' => '',
163         'description' => t("User's email address."),
164       ),
165       'mode' => array(
166         'type' => 'int',
167         'not null' => TRUE,
168         'default' => 0,
169         'size' => 'tiny',
170         'description' => t('Per-user comment display mode (threaded vs. flat), used by the {comment} module.'),
171       ),
172       'sort' => array(
173         'type' => 'int',
174         'not null' => FALSE,
175         'default' => 0,
176         'size' => 'tiny',
177         'description' => t('Per-user comment sort order (newest vs. oldest first), used by the {comment} module.'),
178       ),
179       'threshold' => array(
180         'type' => 'int',
181         'not null' => FALSE,
182         'default' => 0,
183         'size' => 'tiny',
184         'description' => t('Previously used by the {comment} module for per-user preferences; no longer used.'),
185       ),
186       'theme' => array(
187         'type' => 'varchar',
188         'length' => 255,
189         'not null' => TRUE,
190         'default' => '',
191         'description' => t("User's default theme."),
192       ),
193       'signature' => array(
194         'type' => 'varchar',
195         'length' => 255,
196         'not null' => TRUE,
197         'default' => '',
198         'description' => t("User's signature."),
199       ),
200       'created' => array(
201         'type' => 'int',
202         'not null' => TRUE,
203         'default' => 0,
204         'description' => t('Timestamp for when user was created.'),
205       ),
206       'access' => array(
207         'type' => 'int',
208         'not null' => TRUE,
209         'default' => 0,
210         'description' => t('Timestamp for previous time user accessed the site.'),
211       ),
212       'login' => array(
213         'type' => 'int',
214         'not null' => TRUE,
215         'default' => 0,
216         'description' => t("Timestamp for user's last login."),
217       ),
218       'status' => array(
219         'type' => 'int',
220         'not null' => TRUE,
221         'default' => 0,
222         'size' => 'tiny',
223         'description' => t('Whether the user is active(1) or blocked(0).'),
224       ),
225       'timezone' => array(
226         'type' => 'varchar',
227         'length' => 8,
228         'not null' => FALSE,
229         'description' => t("User's timezone."),
230       ),
231       'language' => array(
232         'type' => 'varchar',
233         'length' => 12,
234         'not null' => TRUE,
235         'default' => '',
236         'description' => t("User's default language."),
237       ),
238       'picture' => array(
239         'type' => 'varchar',
240         'length' => 255,
241         'not null' => TRUE,
242         'default' => '',
243         'description' => t("Path to the user's uploaded picture."),
244       ),
245       'init' => array(
246         'type' => 'varchar',
247         'length' => 64,
248         'not null' => FALSE,
249         'default' => '',
250         'description' => t('Email address used for initial account creation.'),
251       ),
252       'data' => array(
253         'type' => 'text',
254         'not null' => FALSE,
255         'size' => 'big',
256         'serialize' => TRUE,
257         '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.'),
258       ),
259     ),
260     'indexes' => array(
261       'access' => array('access'),
262       'created' => array('created'),
263       'mail' => array('mail'),
264     ),
265     'unique keys' => array(
266       'name' => array('name'),
267     ),
268     'primary key' => array('uid'),
269   );
270 
271   $schema['users_roles'] = array(
2721    'description' => t('Maps users to roles.'),
273     'fields' => array(
274       'uid' => array(
275         'type' => 'int',
276         'unsigned' => TRUE,
277         'not null' => TRUE,
278         'default' => 0,
279         'description' => t('Primary Key: {users}.uid for user.'),
280       ),
281       'rid' => array(
282         'type' => 'int',
283         'unsigned' => TRUE,
284         'not null' => TRUE,
285         'default' => 0,
286         'description' => t('Primary Key: {role}.rid for role.'),
287       ),
288     ),
289     'primary key' => array('uid', 'rid'),
290     'indexes' => array(
291       'rid' => array('rid'),
292     ),
293   );
294 
2951  return $schema;
296 }
297 
298 /**
299  * @defgroup user-updates-6.x-to-7.x User updates from 6.x to 7.x
300  * @{
301  */
302 
303 /**
304  * Increase the length of the password field to accommodate better hashes.
305  *
306  * Also re-hashes all current passwords to improve security. This may be a
307  * lengthy process, and is performed batch-wise.
308  */
309 function user_update_7000(&$sandbox) {
310   $ret = array('#finished' => 0);
311   // Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
312   $hash_count_log2 = 11;
313   // Multi-part update.
314   if (!isset($sandbox['user_from'])) {
315     db_change_field($ret, 'users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
316     $sandbox['user_from'] = 0;
317     $sandbox['user_count'] = db_result(db_query("SELECT COUNT(uid) FROM {users}"));
318   }
319   else {
320     require_once variable_get('password_inc', './includes/password.inc');
321     //  Hash again all current hashed passwords.
322     $has_rows = FALSE;
323     // Update this many per page load.
324     $count = 1000;
325     $result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0 ORDER BY uid", $sandbox['user_from'], $count);
326     while ($account = db_fetch_array($result)) {
327        $has_rows = TRUE;
328        $new_hash = user_hash_password($account['pass'], $hash_count_log2);
329        if ($new_hash) {
330          // Indicate an updated password.
331          $new_hash  = 'U'. $new_hash;
332          db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $new_hash, $account['uid']);
333        }
334     }
335     $ret['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
336     $sandbox['user_from'] += $count;
337     if (!$has_rows) {
338       $ret['#finished'] = 1;
339       $ret[] = array('success' => TRUE, 'query' => "UPDATE {users} SET pass = 'U'. user_hash_password(pass) WHERE uid > 0");
340     }
341   }
342   return $ret;
343 }
344 
345 /**
346  * @} End of "defgroup user-updates-6.x-to-7.x"
347  * The next series of updates should start at 8000.
348  */
349