diff --git a/core/includes/config.inc b/core/includes/config.inc index c89537d..d240df4 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -177,8 +177,10 @@ function config_sync_get_changes(StorageInterface $source_storage, StorageInterf * The storage to synchronize configuration from. * @param Drupal\Core\Config\StorageInterface $target_storage * The storage to synchronize configuration to. + * @param bool $delete_source = FALSE + * Whether or not to delete the source item. */ -function config_sync_changes(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { +function config_sync_changes(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage, $delete_source = FALSE) { $factory = drupal_container()->get('config.factory'); foreach (array('delete', 'create', 'change') as $op) { foreach ($config_changes[$op] as $name) { @@ -190,6 +192,11 @@ function config_sync_changes(array $config_changes, StorageInterface $source_sto $data = $source_storage->read($name); $config->setData($data ? $data : array()); $config->save(); + // if required, we can now delete the source, as the target has + // been saved + if ($delete_source) { + $source_storage->delete($name); + } } $factory->reset($name); } @@ -199,11 +206,14 @@ function config_sync_changes(array $config_changes, StorageInterface $source_sto /** * Imports configuration into the active configuration. * + * @param bool $delete_source = FALSE + * Whether or not to delete the source item. + * * @return bool|null * TRUE if configuration was imported successfully, FALSE in case of a * synchronization error, or NULL if there are no changes to synchronize. */ -function config_import() { +function config_import($delete_source = FALSE) { // Retrieve a list of differences between staging and the active configuration. $source_storage = drupal_container()->get('config.storage.staging'); $target_storage = drupal_container()->get('config.storage'); @@ -225,7 +235,7 @@ function config_import() { $success = TRUE; try { $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage); - config_sync_changes($remaining_changes, $source_storage, $target_storage); + config_sync_changes($remaining_changes, $source_storage, $target_storage, $delete_source); } catch (ConfigException $e) { watchdog_exception('config_import', $e); diff --git a/core/modules/config/config.admin.inc b/core/modules/config/config.admin.inc index 4a6f953..fff6149 100644 --- a/core/modules/config/config.admin.inc +++ b/core/modules/config/config.admin.inc @@ -99,18 +99,18 @@ function config_admin_import_form_submit($form, &$form_state) { if (!lock()->lockMayBeAvailable(CONFIG_IMPORT_LOCK)) { drupal_set_message(t('Another request may be synchronizing configuration already.')); } - else if (config_import()) { + else if (config_import(TRUE)) { // Once a sync completes, we empty the staging directory. This prevents // changes from being accidentally overwritten by stray files getting // imported later. $source_storage = drupal_container()->get('config.storage.staging'); - foreach ($source_storage->listAll() as $name) { - $source_storage->delete($name); + if (count($source_storage->listAll())) { + drupal_set_message(t('The configuration was imported successfully, but certain files were left in the staging directory, as they could were not handled.')); + } + else { + drupal_set_message(t('The configuration was imported successfully.')); } - drupal_flush_all_caches(); - - drupal_set_message(t('The configuration was imported successfully.')); } else { drupal_set_message(t('The import failed due to an error. Any errors have been logged.'), 'error');