Commit 50ae478f authored by alexpott's avatar alexpott
Browse files

Issue #1998204 by tim.plunkett: Fixed config_install_default_config() is not...

Issue #1998204 by tim.plunkett: Fixed config_install_default_config() is not safe to use in hook_update_N().
parent 15d30125
......@@ -1462,16 +1462,21 @@ function update_variables_to_config($config_name, array $variable_map) {
* The extension type; e.g., 'module' or 'theme'.
* @param string $config_name
* The configuration object name to retrieve.
* @param string $name
* (optional) The owner of the config. Defaults to NULL, in which case the
* name will be derived from the $config_name.
*
* @return boolean
* True on success, false if config file does not exist.
*/
function update_7_to_8_install_default_config($type, $config_name) {
function update_install_default_config($type, $config_name, $name = NULL) {
// Build the new configuration object.
$config = Drupal::config($config_name);
// Extract the extension namespace/owner from the configuration object name.
$name = strtok($config_name, '.');
if (!$name) {
$name = strtok($config_name, '.');
}
// Load and set default configuration values.
$file = new FileStorage(drupal_get_path($type, $name) . '/config');
......
......@@ -40,5 +40,5 @@ function field_ui_update_8001() {
* @ingroup config_upgrade
*/
function field_ui_update_8002() {
update_7_to_8_install_default_config('module', 'field_ui.settings');
update_install_default_config('module', 'field_ui.settings');
}
......@@ -7,7 +7,6 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Uuid\Uuid;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\Language;
......@@ -1924,7 +1923,7 @@ function system_update_8045() {
'system.date_format.html_yearless_date',
);
foreach ($new_formats as $new_format) {
update_7_to_8_install_default_config('module', $new_format);
update_install_default_config('module', $new_format);
}
}
......@@ -1932,28 +1931,13 @@ function system_update_8045() {
* Install new default views.
*/
function system_update_8046() {
$config_to_import = array(
'views.view.user_admin_people' => 'user',
'views.view.content' => 'node',
);
update_install_default_config('module', 'views.view.user_admin_people', 'user');
update_install_default_config('module', 'views.view.content', 'node');
$front_page = config('system.site')->get('page.front') ?: 'node';
if ($front_page == 'node') {
// This imports the node frontpage view.
$config_to_import['views.view.frontpage'] = 'node';
}
foreach ($config_to_import as $config_name => $module) {
$module_config_path = drupal_get_path('module', $module) . '/config';
$module_filestorage = new FileStorage($module_config_path);
$config_storage = drupal_container()->get('config.storage');
// If this file already exists, something in the upgrade path went
// completely wrong and we want to know.
if ($config_storage->exists($config_name)) {
throw new ConfigException(format_string('Default configuration file @name of @module module unexpectedly exists already before the module was installed.', array(
'@module' => $module,
'@name' => $config_name,
)));
}
$config_storage->write($config_name, $module_filestorage->read($config_name));
update_install_default_config('module', 'views.view.frontpage', 'node');
}
}
......@@ -2127,7 +2111,7 @@ function system_update_8054() {
*/
function system_update_8055() {
// Install the global theme settings from the system module.
update_7_to_8_install_default_config('module', 'system.theme.global');
update_install_default_config('module', 'system.theme.global');
// Add the global settings to a map for variable to configuration conversion.
$theme_settings_to_config_map = array('theme_settings' => 'system.theme.global');
......@@ -2147,7 +2131,7 @@ function system_update_8055() {
$variable = 'theme_' . $theme . '_settings';
$config_name = $theme . '.settings';
$theme_settings_to_config_map[$variable] = $config_name;
update_7_to_8_install_default_config('theme', $config_name);
update_install_default_config('theme', $config_name);
}
// Convert array of theme settings from Drupal 7's variable system to Drupal
......
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