Commit 642f91d1 authored by Dries's avatar Dries

Merge branch '8.x' of git.drupal.org:project/drupal into 8.x

parents 4c0124b7 72cf5a75
......@@ -531,8 +531,8 @@ function drupal_get_destination() {
* Parses a system URL string into an associative array suitable for url().
*
* This function should only be used for URLs that have been generated by the
* system, resp. url(). It should not be used for URLs that come from external
* sources, or URLs that link to external resources.
* system, such as via url(). It should not be used for URLs that come from
* external sources, or URLs that link to external resources.
*
* The returned array contains a 'path' that may be passed separately to url().
* For example:
......
......@@ -849,6 +849,72 @@ function update_retrieve_dependencies() {
return $return;
}
/**
* Updates config with values set on Drupal 7.x
*
* Provide a generalised method to migrate variables from Drupal 7 to Drupal 8's
* configuration management system.
*
* @param $config_name
* The name of the configuration object to retrieve. The name corresponds to
* an XML configuration file. For @code config(book.admin) @endcode, the
* config object returned will contain the contents of book.admin.xml.
* @param $variable_map
* An array to map new to old configuration naming conventions. Example:
* @code
* array('new_config' => 'old_config')
* @endcode
* This would update the value for new_config to the value old_config has in
* the variable table.
*/
function update_variables_to_config($config_name, $variable_map = array()) {
$config = config($config_name);
$config_data = array_keys($config->get());
if (!empty($config_data)) {
// Build a list of variables to select from the database and build a mapping
// of variable names to config keys.
foreach ($config_data as $config_key) {
if (isset($variable_map[$config_key])) {
$variables[] = $variable_map[$config_key];
$config_keys[$variable_map[$config_key]] = $config_key;
}
else {
$variables[] = $config_key;
$config_keys[$config_key] = $config_key;
}
}
// Get any variables currently defined that match the new setting names in
// the config file.
$query = db_select('variable', 'v')
->fields('v')
->condition('name', $variables, 'IN');
$var_values = $query->execute()->fetchAllKeyed(0);
if (!empty($var_values)) {
// Update the config system settings to use the values previously stored in
// the variable table.
try {
foreach($var_values as $name => $val) {
$config->set($config_keys[$name], unserialize($val));
}
$config->save();
// Delete the old variables. The config system will throw an exception if a
// value cannot be saved, so this code will not run if there is a problem
// running the update.
$del = db_delete('variable')->condition('name', $variables, 'IN');
$del->execute();
}
// @TODO We may want to do different error handling for different
// exception types, but for now we'll just log the exception.
catch (Exception $e) {
watchdog_exception('update', $e);
}
}
}
}
/**
* @defgroup update-api-7.x-to-8.x Update versions of API functions
* @{
......
......@@ -414,7 +414,7 @@ function book_get_books() {
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
* Implements hook_form_BASE_FORM_ID_alter() for node_form().
*
* Adds the book fieldset to the node form.
*
......@@ -1036,7 +1036,7 @@ function _book_parent_depth_limit($book_link) {
}
/**
* Implements hook_form_FORM_ID_alter().
* Implements hook_form_FORM_ID_alter() for node_delete_confirm().
*
* Alters the confirm form for a single node deletion.
*
......
......@@ -56,7 +56,7 @@ function book_export($type, $nid) {
}
/**
* This function is called by book_export() to generate HTML for export.
* Generates HTML for export when invoked by book_export().
*
* The given node is embedded to its absolute depth in a top level section. For
* example, a child node with depth 2 in the hierarchy is contained in
......
......@@ -296,3 +296,40 @@ class ConfOverrideTestCase extends DrupalWebTestCase {
$this->assertEqual($config->get('cache'), $conf['system.performance']['cache']);
}
}
/**
* Tests function providing configuration upgrade from Drupal 7 to 8.
*/
class ConfUpdate7to8TestCase extends DrupalWebTestCase {
protected $testContent = 'Olá, Sao Paulo!';
public static function getInfo() {
return array(
'name' => 'Configuration update from Drupal 7 to 8',
'description' => 'Tests the ability to update Drupal 7 variables to the
configuration management system.',
'group' => 'Configuration',
);
}
function setUp() {
parent::setUp('config_upgrade');
require_once DRUPAL_ROOT . '/core/includes/update.inc';
}
/**
* Test configuration update function.
*/
function testConfigurationUpdate() {
// Ensure that the variable table has the object. The variable table will
// remain in place for Drupal 8 to provide an upgrade path for overridden
// variables.
db_merge('variable')->key(array('name' => 'config_test_foo'))->fields(array('value' => serialize($this->testContent)))->execute();
db_merge('variable')->key(array('name' => 'config_bar'))->fields(array('value' => serialize($this->testContent)))->execute();
update_variables_to_config('config.test', array('config_test_bar' => 'config_bar'));
$config = config('config.test');
$this->assertEqual($config->get('config_test_foo'), $this->testContent);
$this->assertEqual($config->get('config_test_bar'), $this->testContent);
}
}
......@@ -120,7 +120,7 @@ function file_field_instance_settings_form($field, $instance) {
}
/**
* Render API callback: Validates the maximum uplodad size field.
* Render API callback: Validates the maximum upload size field.
*
* Ensures that a size has been entered and that it can be parsed by
* parse_size().
......
<?xml version="1.0"?>
<config>
<config_test_foo>bar</config_test_foo>
<config_test_bar>foo</config_test_bar>
</config>
name = Config upgrade tests
description = A support module for update_variables_to_config testing.
core = 8.x
package = Testing
version = VERSION
hidden = TRUE
<?php
/**
* @file
* A support module for update_variables_to_config() testing.
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment