You are here

public static function Vars::renameVariables in Variable API 7

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

Renames persistent variables.

Renames the persistent variables whose name matched 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 260
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])) {
      $conf[$new_name] = $conf[$old_name];
      db_merge('variable')
        ->key(array(
        'name' => $new_name,
      ))
        ->fields(array(
        'value' => serialize($conf[$old_name]),
      ))
        ->execute();
      unset($conf[$old_name]);
      $count++;
    }
  }
  if ($count) {
    db_delete('variable')
      ->condition('name', array_keys($names), 'IN')
      ->execute();
    cache_clear_all('variables', 'cache_bootstrap');
  }
}