diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index 715138f..64f7252 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -434,7 +434,7 @@ protected function createExtensionChangelist() { * @return array * An array of extension names. */ - protected function getExtensionChangelist($type, $op = NULL) { + public function getExtensionChangelist($type, $op = NULL) { if ($op) { return $this->extensionChangelist[$type][$op]; } diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php index f17d5bd..4d0af11 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php @@ -8,6 +8,7 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\Config\Config; +use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigImporterEvent; use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase; use Drupal\Core\Config\ConfigNameException; @@ -16,7 +17,6 @@ * Config import subscriber for config import events. */ class ConfigImportSubscriber extends ConfigImportValidateEventSubscriberBase { - /** * Validates the configuration to be imported. * @@ -37,6 +37,79 @@ public function onConfigImporterValidate(ConfigImporterEvent $event) { } } } + $config_importer = $event->getConfigImporter(); + $this->validateModuleInstalls($config_importer); + $this->validateThemeInstalls($config_importer); + $this->validateDependencies($config_importer); + } + + protected function validateModuleInstalls(ConfigImporter $config_importer) { + $modules = system_rebuild_module_data(); + foreach ($config_importer->getExtensionChangelist('module', 'install') as $module) { + if (!isset($modules[$module])) { + $config_importer->logError($this->t('Unable to install module %module since it does not exist.', array('%module' => $module))); + } + } + } + + protected function validateThemeInstalls(ConfigImporter $config_importer) { + $themes = \Drupal::service('theme_handler')->rebuildThemeData(); + foreach ($config_importer->getExtensionChangelist('theme', 'install') as $theme) { + if (!isset($themes[$theme])) { + $config_importer->logError($this->t('Unable to install theme %theme since it does not exist.', array('%theme' => $theme))); + } + } + } + + protected function validateDependencies(ConfigImporter $config_importer) { + $themes = array_keys(\Drupal::service('theme_handler')->rebuildThemeData()); + $available_config = $config_importer->getStorageComparer()->getSourceStorage()->listAll(); + $modules = array_keys(system_rebuild_module_data()); + $core_extension = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension'); + $enabled_modules = array_keys($core_extension['module']); + $enabled_themes = array_keys($core_extension['theme']); + foreach (array('delete', 'create', 'update') as $op) { + foreach ($config_importer->getUnprocessedConfiguration($op) as $name) { + $data = $config_importer->getStorageComparer()->getSourceStorage()->read($name); + if (isset($data['dependencies']) && isset($data['uuid'])) { + $dependencies = $data['dependencies']; + if (isset($dependencies['module'])) { + // Ensure that the module is available and will be installed. + $diffs = array_diff($dependencies['module'], $modules); + if (!empty($diffs)) { + $config_importer->logError($this->t('Configuration %name depends on modules that do not exist.', array('%name' => $name))); + } + else { + $diffs = array_diff($dependencies['module'], $enabled_modules); + if (!empty($diffs)) { + $config_importer->logError($this->t('Configuration %name depends on modules that will not installed after import.', array('%name' => $name))); + } + } + } + if (isset($dependencies['theme'])) { + // Ensure that the theme is available and will be installed. + $diffs = array_diff($dependencies['theme'], $themes); + if (!empty($diffs)) { + $config_importer->logError($this->t('Configuration %name depends on themes that do not exist.', array('%name' => $name))); + } + else { + $diffs = array_diff($dependencies['theme'], $enabled_themes); + if (!empty($diffs)) { + $config_importer->logError($this->t('Configuration %name depends on themes that will not installed after import.', array('%name' => $name))); + } + } + } + if (isset($dependencies['config'])) { + // Ensure that the config exists. + $diffs = array_diff($dependencies['config'], $available_config); + if (!empty($diffs)) { + $config_importer->logError($this->t('Configuration %name depends on configuration that will not exist after import.', array('%name' => $name))); + } + } + } + } + } + } }