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 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.

5 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.
update_update_8001 in drupal/core/modules/update/update.install
Convert update_last_check, last_email_notification variables to state API.

File

drupal/core/includes/update.inc, line 1273
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))) {
      state()
        ->set($state_name, $value);
    }
  }

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