Skip to content
Snippets Groups Projects
Commit e027fd1e authored by Derek Laventure's avatar Derek Laventure
Browse files

Issue #3248592: Importing configs doesn't handle inter-module dependencies properly

parent 2b2ccc92
No related branches found
Tags 5.1.0
No related merge requests found
......@@ -3,6 +3,7 @@
namespace Drupal\config_enforce;
use Drupal\Core\Config\ConfigImporter as CoreConfigImporter;
use Drupal\Core\Config\ConfigException;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageComparer;
use Drupal\config\StorageReplaceDataWrapper;
......@@ -42,7 +43,7 @@ class ConfigImporter {
// @TODO log whether config has changed?
return $this->getConfigImporter($storage_comparer)->import();
return $this->doImport($storage_comparer);
}
protected function getDataFromConfigFiles($filenames) {
......@@ -70,6 +71,49 @@ class ConfigImporter {
return $config_data;
}
// Copied from submitForm() at /core/modules/config/src/Form/ConfigSync.php
protected function doImport($storage_comparer) {
$config_importer = $this->getConfigImporter($storage_comparer);
if ($config_importer->alreadyImporting()) {
$this->log()->warning('Another request may be synchronizing configuration already.');
} else {
try {
// This is the contents of \Drupal\Core\Config\ConfigImporter::import.
// Copied here so we can log progress.
if ($config_importer->hasUnprocessedConfigurationChanges()) {
$sync_steps = $config_importer->initialize();
foreach ($sync_steps as $step) {
$context = [];
do {
$config_importer->doSyncStep($step, $context);
if (isset($context['message'])) {
$this->log()->notice(str_replace('Synchronizing', 'Synchronized', (string)$context['message']));
}
} while ($context['finished'] < 1);
}
// Clear the cache of the active config storage.
\Drupal::service('cache.config')->deleteAll();
}
if ($config_importer->getErrors()) {
throw new ConfigException('Errors occurred during import');
} else {
$this->log()->notice('The configuration was imported successfully.');
}
} catch (ConfigException $e) {
// Return a negative result for UI purposes. We do not differentiate
// between an actual synchronization error and a failed lock, because
// concurrent synchronizations are an edge-case happening only when
// multiple developers or site builders attempt to do it without
// coordinating.
$message = 'The import failed due to the following reasons:' . "\n";
$message .= implode("\n", $config_importer->getErrors());
watchdog_exception('config_import', $e);
throw new \Exception($message);
}
}
}
/**
* Return an instantiated ConfigImporter.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment