|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Contains base User migration class |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class DFUsers extends ImportBaseUsers { |
|
9
|
|
|
|
|
10
|
|
|
public function __construct($arguments) { |
|
11
|
|
|
parent::__construct($arguments); |
|
12
|
|
|
// Create a MigrateSource object. |
|
13
|
|
|
if (isset($arguments['path'])) { |
|
14
|
|
|
$import_path = $arguments['path']; |
|
15
|
|
|
} |
|
16
|
|
|
else { |
|
17
|
|
|
$import_path = drupal_get_path('module', 'df_tools_user') . '/import/df_tools_user.users.csv'; |
|
18
|
|
|
} |
|
19
|
|
|
$this->source = new MigrateSourceCSV($import_path, $this->csvcolumns(), array('header_rows' => 1)); |
|
20
|
|
|
|
|
21
|
|
|
$picture_source = isset($arguments['picture_source']) ? $arguments['picture_source'] : 'DFUserPictures'; |
|
22
|
|
|
$this->addFieldMapping('picture', 'picture')->sourceMigration($picture_source); |
|
23
|
|
|
$this->addFieldMapping('field_user_interests', 'interests'); |
|
24
|
|
|
$this->addFieldMapping('field_user_bio', 'bio'); |
|
25
|
|
|
$this->addFieldMapping('field_user_bio:format')->defaultValue('userbase'); |
|
26
|
|
|
$this->addFieldMapping('field_user_first', 'first'); |
|
27
|
|
|
$this->addFieldMapping('field_user_last', 'last'); |
|
28
|
|
|
// Last login |
|
29
|
|
|
$this->addFieldMapping('login', 'access')->defaultValue(strtotime("-1 week")); |
|
30
|
|
|
$this->addFieldMapping('login', 'login')->defaultValue(strtotime("-1 week")); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function csvcolumns() { |
|
|
|
|
|
|
34
|
|
|
$columns[0] = array('name', 'Name'); |
|
|
|
|
|
|
35
|
|
|
$columns[1] = array('pass', 'Pass'); |
|
36
|
|
|
$columns[2] = array('mail', 'Mail'); |
|
37
|
|
|
$columns[3] = array('status', 'Status'); |
|
38
|
|
|
$columns[4] = array('roles', 'Roles'); |
|
39
|
|
|
$columns[5] = array('picture', 'Picture'); |
|
40
|
|
|
$columns[6] = array('interests', 'Interests'); |
|
41
|
|
|
$columns[7] = array('bio', 'Bio'); |
|
42
|
|
|
$columns[8] = array('first', 'First'); |
|
43
|
|
|
$columns[9] = array('last', 'Last'); |
|
44
|
|
|
$columns[10] = array('login', 'Last Login'); |
|
45
|
|
|
return $columns; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function prepareRow($row) { |
|
49
|
|
|
$user_roles = explode(", ", $row->roles); |
|
50
|
|
|
$roles = array('2' => '2'); |
|
51
|
|
|
foreach ($user_roles as $role_name) { |
|
52
|
|
|
$rid = db_query('SELECT rid FROM {role} WHERE name = :name', array(':name' => $role_name))->fetchField(); |
|
53
|
|
|
$roles[$rid] = $rid; |
|
54
|
|
|
} |
|
55
|
|
|
$row->roles = $roles; |
|
56
|
|
|
$row->interests = explode(", ", $row->interests); |
|
57
|
|
|
// Convert date string in csv to a datetime |
|
58
|
|
|
if (isset($row->login)) { |
|
59
|
|
|
$row->login = strtotime($row->login); |
|
60
|
|
|
} |
|
61
|
|
|
return TRUE; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
class DFUserPictures extends ImportBaseUserPictures { |
|
67
|
|
|
public function __construct($arguments) { |
|
68
|
|
|
parent::__construct($arguments); |
|
69
|
|
|
if (isset($arguments['path'])) { |
|
70
|
|
|
$import_path = $arguments['path']; |
|
71
|
|
|
} |
|
72
|
|
|
else { |
|
73
|
|
|
$import_path = drupal_get_path('module', 'df_tools_user') . '/import/df_tools_user.users.csv'; |
|
74
|
|
|
} |
|
75
|
|
|
$this->source = new MigrateSourceCSV($import_path, $this->csvcolumns(), array('header_rows' => 1)); |
|
76
|
|
|
|
|
77
|
|
|
// Get the base path, which is where we assume /images is located |
|
78
|
|
|
$base_path = dirname($import_path); |
|
79
|
|
|
$this->addFieldMapping('source_dir')->defaultValue($base_path . '/images'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
function csvcolumns() { |
|
|
|
|
|
|
83
|
|
|
$columns[5] = array('picture', 'Picture'); |
|
|
|
|
|
|
84
|
|
|
return $columns; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.