-
Notifications
You must be signed in to change notification settings - Fork 6
/
fixtures.user.inc
41 lines (39 loc) · 1.14 KB
/
fixtures.user.inc
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
<?php
/**
* Create all users
*/
function fixtures_create_users() {
$fixtures = fixtures_get_fixtures('user');
foreach ($fixtures as $fixture) {
foreach ($fixture as $user_name => $user_array) {
$user = fixture_create_user($user_array);
}
}
return "debugging fixtures";
}
/**`
* Create single user from YAML array
*/
function fixture_create_user($user_array) {
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$user = new stdClass();
$user->name = $user_array['name'];
$user->pass = user_hash_password($user_array['pass']);
$user->pass_raw = $user->pass;
$user->mail = $user_array['mail'];
$user->status = 1;
$roles = array(DRUPAL_AUTHENTICATED_RID => TRUE);
foreach (preg_split('/\s*,\s*/', $user_array['roles'], 0, PREG_SPLIT_NO_EMPTY) as $role_name) {
$role = user_role_load_by_name($role_name);
if ($role != null) {
$roles[$role->rid] = TRUE;
}
else {
throw new Exception("User role not found: '$role_name'", 1);
}
}
$user->roles = $roles;
$user->timezone = variable_get('date_default_timezone', '');
user_save($user);
return $user;
}