protected function overwriteConfig(DrupalStyle $io, PreExistingConfigException $e, $moduleList, $overwriteConfig)
 {
     if ($overwriteConfig) {
         $io->info($this->trans('commands.module.install.messages.config-conflict-overwrite'));
     } else {
         $io->info($this->trans('commands.module.install.messages.config-conflict'));
     }
     $configObjects = $e->getConfigObjects();
     foreach (current($configObjects) as $config) {
         $io->info($config);
         $config = $this->getConfigFactory()->getEditable($config);
         $config->delete();
     }
     if (!$overwriteConfig) {
         return;
     }
     try {
         $moduleInstaller = $this->getModuleInstaller();
         $moduleInstaller->install($moduleList);
         $io->info(sprintf($this->trans('commands.module.install.messages.success'), implode(', ', $moduleList)));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return;
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function checkConfigurationToInstall($type, $name)
 {
     if ($this->isSyncing()) {
         // Configuration is assumed to already be checked by the config importer
         // validation events.
         return;
     }
     $config_install_path = $this->getDefaultConfigDirectory($type, $name);
     if (!is_dir($config_install_path)) {
         return;
     }
     $storage = new FileStorage($config_install_path, StorageInterface::DEFAULT_COLLECTION);
     $enabled_extensions = $this->getEnabledExtensions();
     // Add the extension that will be enabled to the list of enabled extensions.
     $enabled_extensions[] = $name;
     // Gets a profile storage to search for overrides if necessary.
     $profile_storage = $this->getProfileStorage($name);
     // Check the dependencies of configuration provided by the module.
     $invalid_default_config = $this->findDefaultConfigWithUnmetDependencies($storage, $enabled_extensions, $profile_storage);
     if (!empty($invalid_default_config)) {
         throw UnmetDependenciesException::create($name, $invalid_default_config);
     }
     // Install profiles can not have config clashes. Configuration that
     // has the same name as a module's configuration will be used instead.
     if ($name != $this->drupalGetProfile()) {
         // Throw an exception if the module being installed contains configuration
         // that already exists. Additionally, can not continue installing more
         // modules because those may depend on the current module being installed.
         $existing_configuration = $this->findPreExistingConfiguration($storage);
         if (!empty($existing_configuration)) {
             throw PreExistingConfigException::create($name, $existing_configuration);
         }
     }
 }
Example #3
0
 protected function overwriteConfig(PreExistingConfigException $e, $module_list, $modules, $dependencies, $overwrite_config, $output)
 {
     if ($overwrite_config) {
         $output->writeln('[+] <info>' . $this->trans('commands.module.install.messages.config-conflict-overwrite') . '</info>');
     } else {
         $output->writeln('[+] <info>' . $this->trans('commands.module.install.messages.config-conflict') . '</info>');
     }
     $configObjects = $e->getConfigObjects();
     foreach (current($configObjects) as $config) {
         $output->writeln('[-] <info>' . $config . '</info>');
         $config = $this->getConfigFactory()->getEditable($config);
         $config->delete();
     }
     if (!$overwrite_config) {
         return;
     }
     // Try to reinstall modules
     try {
         // Install the modules.
         $this->moduleInstaller->install($module_list);
         system_rebuild_module_data();
         $output->writeln('[+] <info>' . sprintf($this->trans('commands.module.install.messages.success'), implode(', ', array_merge($modules, $dependencies))) . '</info>');
     } catch (\Exception $e) {
         $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
         return;
     }
 }