You are here

public static function Vars::renameVariables in Variable API 6

Same name and namespace in other branches
  1. 6.2 vars.module \Vars::renameVariables()
  2. 7.2 vars.classes.inc \Vars::renameVariables()
  3. 7 vars.module \Vars::renameVariables()

Renames persistent variables.

Renames the persistent variables whose name matches the passed argument. The variables are renamed in memory, and in the database table used by Drupal core code.

Parameters

$names: A array whose keys are the names of the variables to rename, and the values are the new names to give to the persistent variables.

See also

Vars::deleteVariables()

1 call to Vars::renameVariables()
VarsExtendedTestCase::testRenamingVars in tests/vars.test

File

./vars.module, line 307
Implement an API to handle persistent variables.

Class

Vars
@file Implement an API to handle persistent variables.

Code

public static function renameVariables(array $names) {
  global $conf;
  $count = 0;
  foreach ($names as $old_name => $new_name) {
    if (isset($conf[$old_name])) {
      $serialized_value = serialize($conf[$old_name]);
      db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'", $serialized_value, $new_name);
      if (!db_affected_rows()) {
        @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $new_name, $serialized_value);
      }
      $conf[$new_name] = $conf[$old_name];
      unset($conf[$old_name]);
      $count++;
    }
  }
  if ($count) {
    $args = array_keys($names);
    db_query("DELETE FROM {variable} WHERE name  IN (" . db_placeholders($args, 'varchar') . ")", $args);
    cache_clear_all('variables', 'cache');
  }
}