- Patch #1348162 by catch, sun, Berdir: Add update_variable_*().

8.0.x
Dries 2012-08-07 15:11:13 -04:00
parent 12b49aa11f
commit d1ea099f80
6 changed files with 112 additions and 43 deletions

View File

@ -347,9 +347,9 @@ function update_module_add_to_system($modules = array()) {
function update_fix_d8_requirements() {
global $conf;
if (drupal_get_installed_schema_version('system') < 8000 && !variable_get('update_d8_requirements', FALSE)) {
if (drupal_get_installed_schema_version('system') < 8000 && !update_variable_get('update_d8_requirements', FALSE)) {
// @todo: Make critical, first-run changes to the database here.
variable_set('update_d8_requirements', TRUE);
update_variable_set('update_d8_requirements', TRUE);
}
}
@ -959,6 +959,75 @@ function update_retrieve_dependencies() {
return $return;
}
/**
* Gets the value of a variable directly from the database during the 7.x-8.x upgrade path.
*
* Use this during the 7.x-8.x upgrade path instead of variable_get().
*
* @param string $name
* The name of the variable.
* @param mixed $default
* The default value of the variable.
*
* @return mixed
* The value of the variable in the database unserialized, or NULL if not set.
*
* @see update_variable_set()
* @see update_variable_del()
* @ingroup config_upgrade
*/
function update_variable_get($name, $default = NULL) {
$result = db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $name))->fetchField();
if ($result !== FALSE) {
return unserialize($result);
}
return $default;
}
/**
* Sets a persistent variable during the 7.x-8.x upgrade path.
*
* Use this during the 7.x-8.x upgrade path instead of variable_set().
*
* @param string $name
* The name of the variable to set.
* @param mixed $value
* The value to set. This can be any PHP data type; these functions take care
* of serialization as necessary.
*
* @see update_variable_get()
* @see update_variable_del()
* @ingroup config_upgrade
*/
function update_variable_set($name, $value) {
db_merge('variable')
->key(array(
'name' => $name,
))
->fields(array(
'value' => serialize($value),
))
->execute();
}
/**
* Delete a variable from the database during the 7.x-8.x upgrade path.
*
* Use this during the 7.x-8.x upgrade path instead of variable_del().
*
* @param string $name
* The name of the variable to delete.
*
* @see update_variable_get()
* @see update_variable_set()
* @ingroup config_upgrade
*/
function update_variable_del($name) {
db_delete('variable')
->condition('name', $name)
->execute();
}
/**
* Updates config with values set on Drupal 7.x
*

View File

@ -245,7 +245,7 @@ function block_update_dependencies() {
* @ingroup config_upgrade
*/
function block_update_8000() {
variable_del('block_cache');
update_variable_del('block_cache');
}
/**

View File

@ -195,27 +195,27 @@ function locale_update_8000() {
function locale_update_8001() {
// Only change language_types if we had this setting saved. Keep order
// of types because that is significant for value dependency.
$types = variable_get('language_types', NULL);
$types = update_variable_get('language_types', NULL);
if (!empty($types) && isset($types['language'])) {
$new_types = array();
foreach ($types as $key => $type) {
$new_types[$key == 'language' ? 'language_interface' : $key] = $type;
}
variable_set('language_types', $new_types);
update_variable_set('language_types', $new_types);
}
// Rename language_negotiation_language setting if exists.
$setting = variable_get('language_negotiation_language', NULL);
$setting = update_variable_get('language_negotiation_language', NULL);
if ($setting !== NULL) {
variable_set('language_negotiation_language_interface', $setting);
variable_del('language_negotiation_language');
update_variable_set('language_negotiation_language_interface', $setting);
update_variable_del('language_negotiation_language');
}
// Rename locale_language_providers_weight_language setting if exists.
$weight = variable_get('locale_language_providers_weight_language', NULL);
$weight = update_variable_get('locale_language_providers_weight_language', NULL);
if ($weight !== NULL) {
variable_set('locale_language_providers_weight_language_interface', $weight);
variable_del('locale_language_providers_weight_language');
update_variable_set('locale_language_providers_weight_language_interface', $weight);
update_variable_del('locale_language_providers_weight_language');
}
// Update block data in all core block related tables. Contributed modules
@ -281,7 +281,7 @@ function locale_update_8002() {
*/
function locale_update_8003() {
$message = '';
$domains = variable_get('locale_language_negotiation_url_domains', array());
$domains = update_variable_get('locale_language_negotiation_url_domains', array());
// $used_domains keeps track of the domain names in use.
$used_domains = array();
foreach ($domains as $langcode => $domain) {
@ -301,7 +301,7 @@ function locale_update_8003() {
}
}
}
variable_set('locale_language_negotiation_url_domains', $domains);
update_variable_set('locale_language_negotiation_url_domains', $domains);
if (!empty($message)) {
return $message;
@ -314,11 +314,11 @@ function locale_update_8003() {
* @ingroup config_upgrade
*/
function locale_update_8004() {
$types = variable_get('language_types', NULL);
$types = update_variable_get('language_types', NULL);
if (!empty($types)) {
foreach ($types as $type => $configurable) {
// Rename the negotiation and language switch callback keys.
$negotiation = variable_get('language_negotiation_' . $type, NULL);
$negotiation = update_variable_get('language_negotiation_' . $type, NULL);
if (!empty($negotiation)) {
foreach ($negotiation as $method_id => &$method) {
$method['callbacks']['negotiation'] = $method['callbacks']['language'];
@ -328,14 +328,14 @@ function locale_update_8004() {
unset($method['callbacks']['switcher']);
}
}
variable_set('language_negotiation_' . $type, $negotiation);
update_variable_set('language_negotiation_' . $type, $negotiation);
}
// Rename the language negotiation methods weight variable.
$weight = variable_get('locale_language_providers_weight_' . $type , NULL);
$weight = update_variable_get('locale_language_providers_weight_' . $type , NULL);
if ($weight !== NULL) {
variable_set('language_negotiation_methods_weight_' . $type , $weight);
variable_del('locale_language_providers_weight_' . $type);
update_variable_set('language_negotiation_methods_weight_' . $type , $weight);
update_variable_del('locale_language_providers_weight_' . $type);
}
}
}
@ -486,7 +486,7 @@ function locale_update_8007() {
);
// Add all language type weight variables. As the function language_types()
// is not available its functionality is rebuild.
$language_types = variable_get('language_types', array(
$language_types = update_variable_get('language_types', array(
LANGUAGE_TYPE_INTERFACE => TRUE,
LANGUAGE_TYPE_CONTENT => FALSE,
LANGUAGE_TYPE_URL => FALSE,
@ -515,7 +515,7 @@ function locale_update_8007() {
'locale-session' => 'language-session',
);
foreach ($variable_names as $variable_name) {
$value = variable_get($variable_name);
$value = update_variable_get($variable_name);
// Skip processing if the variable is not stored in the db.
if ($value === NULL) {
continue;
@ -544,7 +544,7 @@ function locale_update_8007() {
if (stristr($variable_name, 'language_negotiation_methods_weight_') !== FALSE) {
asort($new_value);
}
variable_set($variable_name, $new_value);
update_variable_set($variable_name, $new_value);
}
}
@ -562,10 +562,10 @@ function locale_update_8008() {
);
foreach ($variable_name_map as $deprecated_variable_name => $new_variable_name) {
// Check if this variable is stored in the db and if so rename it.
$value = variable_get($deprecated_variable_name);
$value = update_variable_get($deprecated_variable_name);
if ($value !== NULL) {
variable_set($new_variable_name, $value);
variable_del($deprecated_variable_name);
update_variable_set($new_variable_name, $value);
update_variable_del($deprecated_variable_name);
}
}
}

View File

@ -529,11 +529,11 @@ function _update_7000_node_get_types() {
function node_update_8001() {
$types = db_query('SELECT type FROM {node_type}')->fetchCol();
foreach ($types as $type) {
$node_type_language = variable_get('language_content_type_' . $type);
$node_type_language = update_variable_get('language_content_type_' . $type);
if (isset($node_type_language)) {
variable_set('node_type_language_' . $type, $node_type_language);
update_variable_set('node_type_language_' . $type, $node_type_language);
}
variable_del('language_content_type_' . $type);
update_variable_del('language_content_type_' . $type);
}
}
@ -557,20 +557,20 @@ function node_update_8002() {
function node_update_8003() {
$types = db_query('SELECT type FROM {node_type}')->fetchCol();
foreach ($types as $type) {
variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED);
$node_type_language = variable_get('node_type_language_' . $type, 0);
update_variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED);
$node_type_language = update_variable_get('node_type_language_' . $type, 0);
if ($node_type_language == 0) {
variable_set('node_type_language_hidden_' . $type, TRUE);
update_variable_set('node_type_language_hidden_' . $type, TRUE);
}
if ($node_type_language == 2) {
// Translation was enabled, so enable it again and
// unhide the language selector. Because if language is
// LANGUAGE_NOT_SPECIFIED and the selector hidden, translation
// cannot be enabled.
variable_set('node_type_language_hidden_' . $type, FALSE);
variable_set('node_type_language_translation_enabled_' . $type, TRUE);
update_variable_set('node_type_language_hidden_' . $type, FALSE);
update_variable_set('node_type_language_translation_enabled_' . $type, TRUE);
}
variable_del('node_type_language_' . $type);
update_variable_del('node_type_language_' . $type);
}
}

View File

@ -110,7 +110,7 @@ class LanguageUpgradePathTest extends UpgradePathTestBase {
);
// Check that locale_language_providers_weight_language is correctly
// renamed.
$current_weights = variable_get('language_negotiation_methods_weight_language_interface', array());
$current_weights = update_variable_get('language_negotiation_methods_weight_language_interface', array());
$this->assertTrue(serialize($expected_weights) == serialize($current_weights), t('Language negotiation method weights upgraded.'));
// Look up migrated plural string.
@ -137,7 +137,7 @@ class LanguageUpgradePathTest extends UpgradePathTestBase {
public function testLanguageUrlUpgrade() {
$language_domain = 'ca.example.com';
db_update('languages')->fields(array('domain' => 'http://' . $language_domain . ':8888'))->condition('language', 'ca')->execute();
variable_set('locale_language_negotiation_url_part', 1);
$this->variable_set('locale_language_negotiation_url_part', 1);
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));

View File

@ -1727,8 +1727,8 @@ function system_update_8000() {
function system_update_8001() {
$themes = array('theme_default', 'maintenance_theme', 'admin_theme');
foreach ($themes as $theme) {
if (variable_get($theme) == 'garland') {
variable_set($theme, 'bartik');
if (update_variable_get($theme) == 'garland') {
update_variable_set($theme, 'bartik');
}
}
}
@ -1755,13 +1755,13 @@ function system_update_8001() {
* @ingroup config_upgrade
*/
function system_update_8002() {
$front_page = variable_get('site_frontpage');
$front_page = update_variable_get('site_frontpage');
if (!isset($front_page)) {
variable_set('site_frontpage', 'node');
update_variable_set('site_frontpage', 'node');
}
$theme = variable_get('theme_default');
$theme = update_variable_get('theme_default');
if (!isset($theme)) {
variable_set('theme_default', 'bartik');
update_variable_set('theme_default', 'bartik');
}
}
@ -1893,7 +1893,7 @@ function system_update_8007() {
* Remove the 'clean_url' configuration variable.
*/
function system_update_8008() {
variable_del('clean_url');
update_variable_del('clean_url');
}
/**