diff --git a/core/includes/config.inc b/core/includes/config.inc index c89537d..b949199 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -29,27 +29,27 @@ function config_install_default_config($type, $name) { $source_storage = new FileStorage($config_dir); $target_storage = drupal_container()->get('config.storage'); + // Ignore manifest files. + $config_changes = config_sync_get_changes($source_storage, $target_storage, FALSE); + // If this module defines any ConfigEntity types, then create a manifest file // for each of them with a listing of the objects it maintains. foreach (config_get_module_config_entities($name) as $entity_type => $entity_info) { $manifest_config = config('manifest.' . $entity_info['config_prefix']); - $manifest_data = array(); foreach ($source_storage->listAll($entity_info['config_prefix']) as $config_name) { list(, , $id) = explode('.', $config_name); - $manifest_data[$id]['name'] = $config_name; + $manifest_config->set("$id.name", $config_name); } - $manifest_config->setData($manifest_data)->save(); + $manifest_config->save(); } - $config_changes = array( - 'delete' => array(), - 'create' => array(), - 'change' => array(), - ); - $config_changes['create'] = $source_storage->listAll(); if (empty($config_changes['create'])) { return; } + // Do not overwrite or delete pre-existing configuration. + $config_changes['change'] = array(); + $config_changes['delete'] = array(); + $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage); config_sync_changes($remaining_changes, $source_storage, $target_storage); } @@ -112,44 +112,51 @@ function config($name) { * The storage to synchronize configuration from. * @param Drupal\Core\Config\StorageInterface $target_storage * The storage to synchronize configuration to. + * @param bool $require_manifest + * (optional) Whether to determine changes based on manifest files. Defaults + * to TRUE. * * @return array|bool * An assocative array containing the differences between source and target * storage, or FALSE if there are no differences. */ -function config_sync_get_changes(StorageInterface $source_storage, StorageInterface $target_storage) { +function config_sync_get_changes(StorageInterface $source_storage, StorageInterface $target_storage, $require_manifest = TRUE) { + $config_changes = array( + 'create' => array(), + 'change' => array(), + 'delete' => array(), + ); + $all_source_names = $source_storage->listAll(); + $all_target_names = $target_storage->listAll(); + // Config entities maintain 'manifest' files that list the objects they // are currently handling. Each file is a simple indexed array of config // object names. In order to generate a list of objects that have been // created or deleted we need to open these files in both the source and // target storage, generate an array of the objects, and compare them. - $source_config_data = array(); - $target_config_data = array(); - foreach ($source_storage->listAll('manifest') as $name) { - if ($source_manifest_data = $source_storage->read($name)) { - $source_config_data = array_merge($source_config_data, $source_manifest_data); + if ($require_manifest) { + $source_config_data = array(); + $target_config_data = array(); + foreach ($source_storage->listAll('manifest') as $name) { + if ($source_manifest_data = $source_storage->read($name)) { + $source_config_data = array_merge($source_config_data, $source_manifest_data); + } + if ($target_manifest_data = $target_storage->read($name)) { + $target_config_data = array_merge($target_config_data, $target_manifest_data); + } } - - if ($target_manifest_data = $target_storage->read($name)) { - $target_config_data = array_merge($target_config_data, $target_manifest_data); + foreach (array_diff_key($target_config_data, $source_config_data) as $name => $value) { + $config_changes['delete'][] = $value['name']; + } + foreach (array_diff_key($source_config_data, $target_config_data) as $name => $value) { + $config_changes['create'][] = $value['name']; } } - - $config_changes = array( - 'create' => array(), - 'change' => array(), - 'delete' => array(), - ); - - foreach (array_diff_key($target_config_data, $source_config_data) as $name => $value) { - $config_changes['delete'][] = $value['name']; - } - - foreach (array_diff_key($source_config_data, $target_config_data) as $name => $value) { - $config_changes['create'][] = $value['name']; + else { + $config_changes['delete'] = array_diff($all_target_names, $all_source_names); + $config_changes['create'] = array_diff($all_source_names, $all_target_names); } - - foreach (array_intersect($source_storage->listAll(), $target_storage->listAll()) as $name) { + foreach (array_intersect($all_source_names, $all_target_names) as $name) { // Ignore manifest files if (substr($name, 0, 9) != 'manifest.') { $source_config_data = $source_storage->read($name);