You are here

function _invite_update_role_name_to_id in Invite 6.2

Same name and namespace in other branches
  1. 7.2 invite.install \_invite_update_role_name_to_id()

Helper function to update a variable name using role name to role id.

1 call to _invite_update_role_name_to_id()
invite_update_203 in ./invite.install
Update variable names to use role id instead of translated role name.

File

./invite.install, line 181
Installation file for invite module.

Code

function _invite_update_role_name_to_id($variable) {
  $result = db_query("SELECT * FROM {role} ORDER BY name ASC");
  while ($role = db_fetch_object($result)) {

    // Look for both a translated (D6) and untranslated (D5) variables.
    // A translated one is newer and has therefore precendence.
    $translated_role = str_replace(' ', '_', t($role->name));
    $value = variable_get($variable . '_' . $translated_role, NULL);
    if (is_null($value)) {
      $untranslated_role = str_replace(' ', '_', $role->name);
      $value = variable_get($variable . '_' . $untranslated_role, NULL);
    }
    if (!is_null($value)) {
      variable_set($variable . '_' . $role->rid, $value);
      db_query("DELETE FROM {variable} WHERE name IN('%s', '%s')", $variable . '_' . $translated_role, $variable . '_' . $untranslated_role);
    }
  }
}