Commit d3edf501 authored by Dries's avatar Dries

Issue #1798732 by Dean Reilly, westie, alexpott, sun: convert install_task()...

Issue #1798732 by Dean Reilly, westie, alexpott, sun: convert install_task() variable to use state system.
parent c862b715
......@@ -1182,6 +1182,33 @@ function update_variables_to_config($config_name, array $variable_map) {
db_delete('variable')->condition('name', array_keys($variable_map), 'IN')->execute();
}
/**
* Updates 7.x variables to state records.
*
* Provides a generalized method to migrate variables from 7.x to 8.x's
* state() system.
*
* @param array $variable_map
* An associative array that maps old variables names to new state record
* names; e.g.:
* @code
* array('old_variable' => 'extension.new_name')
* @endcode
* 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.
*/
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), 'IN')->execute();
}
/**
* Helper function to update entities with uuid.
*
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Upgrade\StateSystemUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Tests upgrade of system variables.
*/
class StateSystemUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'State system upgrade test',
'description' => 'Tests upgrade of system variables to the state system.',
'group' => 'Upgrade path',
);
}
public function setUp() {
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.state.system.database.php',
);
parent::setUp();
}
/**
* Tests upgrade of system variables to state system.
*/
public function testSystemVariableUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
$expected_state = array();
$expected_state['system.install_time'] = array(
'value' => 1304208000,
'variable_name' => 'install_time',
);
$expected_state['system.install_task'] = array(
'value' => 'done',
'variable_name' => 'install_task',
);
$expected_state['system.path_alias_whitelist'] = array(
'value' => array(
),
'variable_name' => 'path_alias_whitelist',
);
foreach ($expected_state as $name => $data) {
$this->assertIdentical(state()->get($name), $data['value']);
$deleted = !db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $data['variable_name']))->fetchField();
$this->assertTrue($deleted, format_string('Variable !name has been deleted.', array('!name' => $data['variable_name'])));
}
}
}
......@@ -2132,17 +2132,15 @@ function system_update_8025() {
}
/**
* Convert install_task and install_time variables to state api values.
* Migrates install_task and install_time variables to State API.
*
* @ingroup config_upgrade
*/
function system_update_8026() {
$variables = array('system.install_task', 'system.install_time');
foreach ($variables as $variable) {
if ($value = update_variable_get($variable, FALSE)) {
state()->set($variable, $value);
}
update_variable_del($variable);
}
update_variables_to_state(array(
'install_task' => 'system.install_task',
'install_time' => 'system.install_time',
));
}
/**
......
<?php
/**
* @file
* Database additions for state system upgrade tests.
*
* This dump only contains data and schema components relevant for system
* functionality. The drupal-7.filled.bare.php file is imported before
* this dump, so the two form the database structure expected in tests
* altogether.
*/
// Update system settings to known values.
db_merge('variable')
->key(array('name' => 'install_time'))->fields(array('value' => serialize(1304208000)))
->execute();
// Add non-default system settings.
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