function autoassignrole_update_7100 in Auto Assign Role 7
Same name and namespace in other branches
- 7.2 autoassignrole.install \autoassignrole_update_7100()
Upgrade the custom table used on the D6 version.
File
- ./
autoassignrole.install, line 92 - Installation related functionality for the auto assign role module.
Code
function autoassignrole_update_7100() {
if (db_table_exists('autoassignrole')) {
// The D6 variables with the D7 defaults.
$defaults = array(
'auto_active' => 0,
'auto_admin_active' => 0,
'auto_roles' => serialize(array()),
'node_user_register' => '',
'page_active' => 0,
'user_active' => 0,
'user_description' => t('Select a role'),
'user_fieldset_title' => t('User Roles'),
'user_multiple' => 0,
'user_required' => 0,
'user_roles' => serialize(array()),
'user_selection' => 0,
'user_sort' => 'SORT_ASC',
'user_title' => t("Role"),
);
// Get a list of all current variables.
$results = db_select('autoassignrole', 'a')
->fields('a', array(
'arid',
'value',
))
->execute();
while ($setting = $results
->fetchObject()) {
if (isset($defaults[$setting->arid])) {
if (strcmp($setting->value, $defaults[$setting->arid]) === 0) {
drupal_set_message(t('AutoAssignRole upgrade: @var is using the default value so has been skipped.', array(
'@var' => $setting->arid,
)));
}
else {
// Expand any serialized objects, ignore any error messages.
if (!empty($setting->value) && !is_numeric($setting->value)) {
$unserialized = @unserialize($setting->value);
if (!empty($unserialized) && $setting->value != $unserialized) {
$setting->value = $unserialized;
}
}
// Save the custom value.
variable_set('autoassignrole_' . $setting->arid, $setting->value);
drupal_set_message(t('AutoAssignRole upgrade: @var has been converted.', array(
'@var' => $setting->arid,
)));
}
}
}
drupal_set_message(t('AutoAssignRole upgrade: removed the "autoassignrole" table.'));
db_drop_table('autoassignrole');
}
else {
drupal_set_message(t('AutoAssignRole: no need to upgrade existing D7 sites.'));
}
}