Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
229
Merge Requests
229
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
d1ea099f
Commit
d1ea099f
authored
Aug 07, 2012
by
Dries
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Patch
#1348162
by catch, sun, Berdir: Add update_variable_*().
parent
12b49aa1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
43 deletions
+112
-43
core/includes/update.inc
core/includes/update.inc
+71
-2
core/modules/block/block.install
core/modules/block/block.install
+1
-1
core/modules/locale/locale.install
core/modules/locale/locale.install
+22
-22
core/modules/node/node.install
core/modules/node/node.install
+9
-9
core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php
...b/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php
+2
-2
core/modules/system/system.install
core/modules/system/system.install
+7
-7
No files found.
core/includes/update.inc
View file @
d1ea099f
...
...
@@ -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
*
...
...
core/modules/block/block.install
View file @
d1ea099f
...
...
@@ -245,7 +245,7 @@ function block_update_dependencies() {
* @ingroup config_upgrade
*/
function
block_update_8000
()
{
variable_del
(
'block_cache'
);
update_
variable_del
(
'block_cache'
);
}
/**
...
...
core/modules/locale/locale.install
View file @
d1ea099f
...
...
@@ -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
);
}
}
}
...
...
core/modules/node/node.install
View file @
d1ea099f
...
...
@@ -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
);
}
}
...
...
core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php
View file @
d1ea099f
...
...
@@ -110,7 +110,7 @@ public function testLanguageUpgrade() {
);
// 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 @@ public function testLanguageUpgrade() {
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.'
));
...
...
core/modules/system/system.install
View file @
d1ea099f
...
...
@@ -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'
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment