diff -u b/core/includes/update.inc b/core/includes/update.inc --- b/core/includes/update.inc +++ b/core/includes/update.inc @@ -890,9 +890,7 @@ * This would migrate the value contained in variable name 'old_variable' into * the data key 'new_config.sub_key' of the configuration object $config_name. */ -function update_variables_to_config($config_name, array $variable_map) { - // Fetch existing variables. - $variables = db_query('SELECT name, value FROM {variable} WHERE name IN (:variables)', array(':variables' => array_keys($variable_map)))->fetchAllKeyed(); +function update_variables_to_config($config_name, array $variable_map = array()) { // Build the new configuration object. // This potentially loads an existing configuration object, in case another @@ -912,6 +910,14 @@ // Apply the default values. $config->setData($data); + // Get the default variable map if none provided + if (count($variable_map) == 0){ + $variable_map = drupal_map_assoc(array_keys($config->get())); + } + + // Fetch existing variables. + $variables = db_query('SELECT name, value FROM {variable} WHERE name IN (:variables)', array(':variables' => array_keys($variable_map)))->fetchAllKeyed(); + // Set configuration values according to the provided variable mapping. foreach ($variable_map as $variable_name => $config_key) { // This function migrates variables regardless of their value, including diff -u b/core/modules/config/config.test b/core/modules/config/config.test --- b/core/modules/config/config.test +++ b/core/modules/config/config.test @@ -322,7 +322,7 @@ public static function getInfo() { return array( - 'name' => 'update_variables_to_config()', + 'name' => 'Variable migration', 'description' => 'Tests migration of variables into configuration objects.', 'group' => 'Configuration', ); @@ -358,4 +358,24 @@ $this->assertIdentical($config->get('parent.bar'), $this->testContent); $this->assertIdentical($config->get('parent.baz'), 'Baz'); + // Test to ensure varaibles are removed + $variables = db_query("SELECT name, value FROM {variable} WHERE name IN ('config_upgrade_bar','config_upgrade_foo')")->fetchAllKeyed(); + $this->assertFalse($variables); + + db_insert('variable') + ->fields(array('name', 'value')) + ->values(array('config_upgrade_foo', serialize($this->testContent))) + ->values(array('config_upgrade_bar', serialize($this->testContent))) + ->execute(); + + update_variables_to_config('config_upgrade.test_no_array'); + + $config = config('config_upgrade.test_no_array'); + $this->assertIdentical($config->get('config_upgrade_foo'), $this->testContent); + $this->assertIdentical($config->get('config_upgrade_bar'), $this->testContent); + $this->assertIdentical($config->get('config_upgrade_baz'), 'Baz'); + // Test to ensure varaibles are removed + $variables = db_query("SELECT name, value FROM {variable} WHERE name IN ('config_upgrade_bar','config_upgrade_foo')")->fetchAllKeyed(); + $this->assertFalse($variables); + } } diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1903,13 +1903,7 @@ * @ingroup config_upgrade */ function system_update_8009() { - update_variables_to_config('system.cron', array( - 'cron_max_threshold' => 'cron_max_threshold', - 'cron_safe_threshold' => 'cron_safe_threshold', - 'cron_threshold_warning' => 'cron_threshold_warning', - 'cron_threshold_error' => 'cron_threshold_error', - 'cron_key' => 'cron_key', - )); + update_variables_to_config('system.cron'); } /** @@ -1918,11 +1912,7 @@ * @ingroup config_upgrade */ function system_update_8010() { - update_variables_to_config('system.rss-publishing', array( - 'feed_description' => 'feed_description', - 'feed_default_items' => 'feed_default_items', - 'feed_item_length' => 'feed_item_length', - )); + update_variables_to_config('system.rss-publishing'); } /** only in patch2: unchanged: --- /dev/null +++ b/core/modules/system/tests/modules/config_upgrade/config/config_upgrade.test_no_array.yml @@ -0,0 +1,3 @@ +config_upgrade_foo: Bar +config_upgrade_bar: Foo +config_upgrade_baz: Baz