function update_variables_to_state

Updates 7.x variables to state records.

Provides a generalized method to migrate variables from 7.x to 8.x's Drupal::state() system.

Parameters

array $variable_map: An associative array that maps old variables names to new state record names; e.g.:

array(
  'old_variable' => 'extension.new_name',
);

This would migrate the value contained in variable name 'old_variable' into the state item 'extension.new_name'. Non-existing variables and variables with NULL values are omitted.

8 calls to update_variables_to_state()
comment_update_8004 in drupal/core/modules/comment/comment.install
Convert variables to state.
node_update_8010 in drupal/core/modules/node/node.install
Moves node_access_needs_rebuild from variable to state.
node_update_8011 in drupal/core/modules/node/node.install
Moves node cron last run time from variable to state.
statistics_update_8002 in drupal/core/modules/statistics/statistics.install
Convert variables to state.
system_update_8034 in drupal/core/modules/system/system.install
Move cron last run time and cron key from variable to state.

... See full list

File

drupal/core/includes/update.inc, line 1464
Drupal database update API.

Code

function update_variables_to_state(array $variable_map) {
  foreach ($variable_map as $variable_name => $state_name) {
    if (NULL !== ($value = update_variable_get($variable_name))) {
      Drupal::state()
        ->set($state_name, $value);
    }
  }

  // Delete the migrated variables.
  db_delete('variable')
    ->condition('name', array_keys($variable_map))
    ->execute();
}