function profile2_regpath_update_7132 in Profile2 Registration Path 7
Same name and namespace in other branches
- 7.2 profile2_regpath.install \profile2_regpath_update_7132()
Update roles.
File
- ./
profile2_regpath.install, line 182 - Install file for the profile2_regpath module.
Code
function profile2_regpath_update_7132() {
$query = db_select('profile2_regpath', 'pr');
$query
->fields('pr', array(
'roles',
'profile_id',
));
$result = $query
->execute();
$regpaths = $result
->fetchAll();
// Only store role that is enabled.
foreach ($regpaths as $regpath) {
$roles = unserialize($regpath->roles);
$updated_roles = array();
foreach ($roles as $role_id => $enable) {
if ($enable) {
$updated_roles[$role_id] = db_query("SELECT r.name FROM {role} AS r WHERE r.rid = :rid", array(
':rid' => $role_id,
))
->fetchField();
}
}
// Update roles.
db_update('profile2_regpath')
->fields(array(
'roles' => serialize($updated_roles),
))
->condition('profile_id', $regpath->profile_id)
->execute();
}
}