function user_migrate_import_role in Migrate 6
Implementation of hook_migrate_import_role().
File
- modules/
user.migrate.inc, line 208 - Implementation of user destination handling
Code
function user_migrate_import_role($tblinfo, $row) {
$errors = array();
$new_role = array();
// Handle an update operation
if ($row->destid) {
$new_role['rid'] = $row->destid;
}
else {
if (isset($tblinfo->fields['rid'])) {
$ridname = $tblinfo->fields['rid']['srcfield'];
$new_role['rid'] = $row->{$ridname};
$sql = "SELECT name FROM {role} WHERE rid=%d";
$new_role['name'] = db_result(db_query($sql, $new_role['rid']));
}
}
foreach ($tblinfo->fields as $destfield => $values) {
if ($values['srcfield'] && isset($row->{$values}['srcfield'])) {
$newvalue = $row->{$values}['srcfield'];
}
else {
$newvalue = $values['default_value'];
}
$new_role[$destfield] = $newvalue;
}
// Prepare the role for import
$errors = migrate_destination_invoke_all('prepare_role', $new_role, $tblinfo, $row);
$role_name = $new_role['name'];
if ($role_name) {
if (isset($new_role['rid'])) {
db_query("UPDATE {role} SET name='%s' WHERE rid=%d", $role_name, $new_role['rid']);
}
else {
db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name);
}
$sql = "SELECT rid FROM {role} WHERE name='%s'";
$rid = db_result(db_query($sql, $role_name));
$new_role['rid'] = $rid;
// Call completion hooks, for any additional role-related processing
// (such as assigning permissions)
timer_start('role completion hooks');
$errors = migrate_destination_invoke_all('complete_role', $new_role, $tblinfo, $row);
timer_stop('role completion hooks');
$sourcekey = $tblinfo->sourcekey;
migrate_add_mapping($tblinfo->mcsid, $row->{$sourcekey}, $rid);
}
return $errors;
}